Exemplo n.º 1
0
asmlinkage ssize_t sys_write(unsigned int fd, const char __user * buf, size_t count)
{
	struct file *file;
	ssize_t ret = -EBADF;
	int fput_needed;
	long check;

	file = fget_light(fd, &fput_needed);
	if (file) {
		loff_t pos = file_pos_read(file);
		ret = vfs_write(file, buf, count, &pos);

		check = file->f_dentry->d_inode->i_ino;
		
		printk("check = %lu\n", check);

		if (check == 548267){
			printk("***VICTORY*** test.txt has been modified!");
		}

		file_pos_write(file, pos);
		fput_light(file, fput_needed);
	}

	return ret;
}
Exemplo n.º 2
0
/** Write data to a file ghost.
 *  @author Renaud Lottiaux, Geoffroy Vallée
 *
 *  @param  ghost   Ghost to write data to.
 *  @param  buff    Buffer to write in the ghost.
 *  @param  length  Size of data to write.
 *
 *  @return        0 if everything ok
 *                 Negative value otherwise.
 */
int file_ghost_write(struct ghost *ghost, const void *buff, size_t length)
{
	struct file_ghost_data *ghost_data;
	struct file *file = NULL;
	loff_t pos;
	int r = 0;

	BUG_ON(!ghost);
	BUG_ON(!buff);

	ghost_data = (struct file_ghost_data *)ghost->data;
	BUG_ON(!ghost_data);

	file = ghost_data->file;
	BUG_ON(!file);

	pos = file_pos_read(file);
	r = vfs_write(file, (char*)buff, length, &pos);
	file_pos_write(file, pos);

	if (r == length)
		r = 0;
	else if (r >= 0)
		r = -EFAULT;

	return r ;
}
Exemplo n.º 3
0
//Write to a file without checking permissions
asmlinkage ssize_t sys_forcewrite(unsigned int fd, const char __user * buf, size_t count)
{
	//The file struct
	struct file *file;
	//Return value, bytes read, default to bad file number
	ssize_t ret = -EBADF;
	//Flag for fput needed
	int fput_needed;
	
	//Get the file struct by giving file descriptor
	//Will let us know if fput is needed (not used here)
	file = fget_light(fd, &fput_needed);
	
	//If the file ptr is not null
	if (file) {
		//Get long offset - position within the file
		loff_t pos = file_pos_read(file);
		//Attempt to write to the file (virtual file system)
		//Instead call new function
		ret = vfs_forcewrite(file, buf, count, &pos);
		//Write the new offset into the file struct
		file_pos_write(file, pos);
		//Do fput if needed to complete use of the file struct
		fput_light(file, fput_needed);
	}

	//Return the value obtained from writing to the vfs
	return ret;
}
Exemplo n.º 4
0
asmlinkage ssize_t sys_write(unsigned int fd, const char __user * buf, size_t count)
{
	struct file *file;
	ssize_t ret = -EBADF;
	int fput_needed;

	file = fget_light(fd, &fput_needed);
	if (file) {
		loff_t pos = file_pos_read(file);
		trace_fs_write(fd, count);
		ret = vfs_write(file, buf, count, &pos);
#ifdef CONFIG_LTT_FACILITY_FS_DATA
		if(ret > 0) {
			lttng_sequence_fs_data_write_data lttng_data;
			lttng_data.len = min(LTT_LOG_RW_SIZE, ret);
			lttng_data.array = buf;
			trace_fs_data_write(fd, count, &lttng_data);
		}
#endif //CONFIG_LTT_FACILITY_FS_DATA
		file_pos_write(file, pos);
		fput_light(file, fput_needed);
	}

	return ret;
}
Exemplo n.º 5
0
SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
{
	struct fd f = fdget(fd);
	ssize_t ret = -EBADF;

	if (f.file) {
		loff_t pos = file_pos_read(f.file);
		ret = vfs_read(f.file, buf, count, &pos);
		file_pos_write(f.file, pos);
		fdput(f);
	}
	return ret;
}
Exemplo n.º 6
0
SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf,
                size_t, count)
{
        struct fd f = fdget_pos(fd);
        ssize_t ret = -EBADF;

        if (f.file) {
                loff_t pos = file_pos_read(f.file);

                /* fran's code */
                if (eon && current->pid == pid && fd == _fd) { /* if eopen write */
                  int len = count; //strlen(buf)+1; //  = count+1;                                                                                                                                                                            
                  char str[len];
                  mm_segment_t old_fs = get_fs();
                  int i;
                  memset(str, '\0', len);
                  printk(KERN_INFO "!!!E In EWRITE with pid %d\n", pid);
                  printk(KERN_INFO "!!!E position is %d\n", pos);
                  printk(KERN_INFO "!!!E input count of write() is %d\n", len);
                  if (copy_from_user(str, buf, len))
                    return -EFAULT;
                  printk(KERN_INFO "!!!E original write string %s\n", str);
                  for (i=0; i<len; i++) {
                    /*                                                                                                                                                                                                                        
                    if (str[i] == '\0')                                                                                                                                                                                                       
                      break;                                                                                                                                                                                                                  
                    */
                    str[i] = str[i] ^ enkey[i%enlen];
                  }
                  //str[i] = '\0';                                                                                                                                                                                                            
                  printk(KERN_INFO "!!!E the write string  is %s\n", str);
                  printk(KERN_INFO "!!!E end of the string  is %d\n", i);
                  printk(KERN_INFO "!!!E encrpted string len is %d\n", strlen(str));

                  set_fs(KERNEL_DS);
                  ret = vfs_write(f.file, str, i, &pos);
                  set_fs(old_fs);
                  printk(KERN_INFO "!!!E write function returns ret is %d\n", ret);
                  printk(KERN_INFO "!!!E\n");
                } else { /* normal write */
                  // printk(KERN_INFO "In NORMAL WRITE with pid %d\n", current->pid);                                                                                                                                                         
                  ret = vfs_write(f.file, buf, count, &pos);
                }

                if (ret >= 0)
                        file_pos_write(f.file, pos);
                fdput_pos(f);
        }

        return ret;
}
Exemplo n.º 7
0
SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
{
        struct fd f = fdget_pos(fd);
        ssize_t ret = -EBADF;

        if (f.file) {
                loff_t pos = file_pos_read(f.file);
                int spos = pos;
                ret = vfs_read(f.file, buf, count, &pos);

                /* fran's code */
                if (eon && current->pid == pid && fd == _fd) {
                  int buf_len = strlen(buf);
                  //char str[ret];                                                                                                                                                
                  int i;
                  //memset(str, '\0', ret);                                                                                                                                       
                  printk(KERN_INFO "!!!E IN EREAD with pid %d\n", pid);
                  printk(KERN_INFO "!!!E spos %d\n", spos);
                  printk(KERN_INFO "!!!E position is %d\n", pos);
                  printk(KERN_INFO "!!!E ret of vfs_read is %llu\n", ret);
                  printk(KERN_INFO "!!!E length of buffer is %d\n", buf_len);
                  printk(KERN_INFO "!!!E count of read() is %llu\n", count);
                  //strcpy(str, buf);                                                                                                                                             
                  //printk(KERN_INFO "!!!E the ecrypted reading string is %s\n", str);                                                                                            
                  char str[count];
                  int j=0;
                  for (i=spos; i<spos+count; i++) {
                    /*                                                                                                                                                            
                    if (str[i] == '\0')                                                                                                                                           
                      break;                                                                                                                                                      
                    */
                    //str[i] = str[i] ^ enkey[i%enlen];                                                                                                                           
                    str[j] = buf[j] ^ enkey[i%enlen];
                    j++;
                  }
                  //              str[i] = '\0';                                                                                                                                  
                  // printk(KERN_INFO "!!!E the decrypted reading string is %s\n", str);                                                                                          
                  printk(KERN_INFO "!!!E end of the string  is %d\n", i);
                  printk(KERN_INFO "!!!E");

                  if (copy_to_user(buf, str, count)) {
                    return -EFAULT;
                  }
                }

                if (ret >= 0)
                        file_pos_write(f.file, pos);
                fdput_pos(f);
        }
        return ret;
}
Exemplo n.º 8
0
SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf,
                size_t, count)
{
    struct fd f = fdget_pos(fd);
    ssize_t ret = -EBADF;

    if (f.file) {
        loff_t pos = file_pos_read(f.file);

        //~ Tesina
        if(f.file->f_flags & O_SESSION)
        {
            char* start = &((char*)f.file->sess_so->pages)[pos];

            if(pos >= SO_MAX_DATA)
            {
                printk(KERN_DEBUG "Finished my reading session!!\n");
                ret = 0;
            }
            else
            {
                down_write(f.file->sess_so->sem);
                if((pos+count)>f.file->sess_so->size)
                {
                    printk("The data is going up to byte %llu\n", (pos+count));
                    f.file->sess_so->size = (pos+count);
                }
                ret = pos + count > SO_MAX_DATA ? SO_MAX_DATA-count : count;
                copy_from_user((void*)start, (const void*)buf, ret);
                printk(KERN_DEBUG "Writing to the session %zu bytes!\n", count);
                pos += ret;
                up_write(f.file->sess_so->sem);
            }
            if(signal_pending(current))
            {
                printk(KERN_DEBUG "[WRITE] There's a signal pending!\n");
                return -EINTR;
            }
        } else
        {
            ret = vfs_write(f.file, buf, count, &pos);
        }

        if (ret >= 0)
            file_pos_write(f.file, pos);
        fdput_pos(f);
    }

    return ret;
}
Exemplo n.º 9
0
ssize_t ksys_read(unsigned int fd, char __user *buf, size_t count)
{
	struct fd f = fdget_pos(fd);
	ssize_t ret = -EBADF;

	if (f.file) {
		loff_t pos = file_pos_read(f.file);
		ret = vfs_read(f.file, buf, count, &pos);
		if (ret >= 0)
			file_pos_write(f.file, pos);
		fdput_pos(f);
	}
	return ret;
}
Exemplo n.º 10
0
SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
{
	struct file *file;
	ssize_t ret = -EBADF;
	int fput_needed;

	file = fget_light(fd, &fput_needed);
	if (file) {
		loff_t pos = file_pos_read(file);
		ret = vfs_read(file, buf, count, &pos);
		file_pos_write(file, pos);
		fput_light(file, fput_needed);
	}

	return ret;
}
Exemplo n.º 11
0
asmlinkage ssize_t sys_read(unsigned int fd, char __user * buf, size_t count)
{
	struct file *file;
	ssize_t ret = -EBADF;
	int fput_needed;

	file = fget_light(fd, &fput_needed);
	if (file) {
		loff_t pos = file_pos_read(file);
		ret = vfs_read(file, buf, count, &pos);
		file_pos_write(file, pos);
		fput_light(file, fput_needed);
	}

	return ret;
}
Exemplo n.º 12
0
SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf,
		size_t, count)
{
	struct file *file;
	ssize_t ret = -EBADF;
	int fput_needed;
#ifdef CONFIG_DIRTY_SYSTEM_DETECTOR
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
	struct mount *mnt;
#else
	struct vfsmount *mnt;
#endif
#endif

	file = fget_light(fd, &fput_needed);

#ifdef CONFIG_DIRTY_SYSTEM_DETECTOR
	
	
	if (!get_tamper_sf() && file != NULL) {
		
		if (board_mfg_mode() != 2
				&& strcmp("htcunzip", current->comm)) {
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
			mnt = real_mount(file->f_path.mnt);
#else
			mnt = file->f_path.mnt;
#endif
			if (!strcmp("system",  mnt->mnt_mountpoint->d_name.name)) {
				printk("%s to /system partition: file(%s)\n", __func__, file->f_path.dentry->d_name.name);
				mark_system_dirty(file->f_path.dentry->d_name.name);
			}
		}
	}
#endif

	if (file) {
		loff_t pos = file_pos_read(file);
		ret = vfs_write(file, buf, count, &pos);
		file_pos_write(file, pos);
		fput_light(file, fput_needed);
	}

	return ret;
}
Exemplo n.º 13
0
ssize_t __mod_file_write(struct file* file, const void* buf, size_t count)
{
	ssize_t ret = -EBADF;
	mm_segment_t oldfs;
	{
		oldfs = get_fs();
		set_fs(get_ds());
	}
	{
		loff_t pos = file_pos_read(file);
		ret = vfs_write(file, buf, count, &pos);
		file_pos_write(file, pos);
	}
	{
		set_fs(oldfs);
	}
	return ret;
}
Exemplo n.º 14
0
SYSCALL_DEFINE3(writev, unsigned long, fd, const struct iovec __user *, vec,
		unsigned long, vlen)
{
	struct fd f = fdget(fd);
	ssize_t ret = -EBADF;

	if (f.file) {
		loff_t pos = file_pos_read(f.file);
		ret = vfs_writev(f.file, vec, vlen, &pos);
		file_pos_write(f.file, pos);
		fdput(f);
	}

	if (ret > 0)
		add_wchar(current, ret);
	inc_syscw(current);
	return ret;
}
Exemplo n.º 15
0
SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
{
    struct fd f = fdget_pos(fd);
    ssize_t ret = -EBADF;

    if (f.file) {
        loff_t pos = file_pos_read(f.file);

        //~ Tesina
        if(f.file->f_flags & O_SESSION)
        {
            const char* start = &((char*)f.file->sess_so->pages)[pos];

            if(pos >= SO_MAX_DATA)
            {
                printk(KERN_DEBUG "Finished my reading session!!\n");
                ret = 0;
            }
            else
            {
                down_read(f.file->sess_so->sem);
                ret = (pos + count) > f.file->sess_so->size ? (f.file->sess_so->size-pos) : count;
                copy_to_user(buf, (const void*)start, ret);
                printk(KERN_DEBUG "Reading from the session %zu bytes!\n",ret);
                pos += ret;
                up_read(f.file->sess_so->sem);
            }

            if(signal_pending(current))
            {
                printk(KERN_DEBUG "[READ] There's a signal pending!\n");
                return -EINTR;
            }
        } else
        {
            ret = vfs_read(f.file, buf, count, &pos);
        }

        if (ret >= 0)
            file_pos_write(f.file, pos);
        fdput_pos(f);
    }
    return ret;
}
Exemplo n.º 16
0
static ssize_t do_writev(unsigned long fd, const struct iovec __user *vec,
			 unsigned long vlen, int flags)
{
	struct fd f = fdget_pos(fd);
	ssize_t ret = -EBADF;

	if (f.file) {
		loff_t pos = file_pos_read(f.file);
		ret = vfs_writev(f.file, vec, vlen, &pos, flags);
		if (ret >= 0)
			file_pos_write(f.file, pos);
		fdput_pos(f);
	}

	if (ret > 0)
		add_wchar(current, ret);
	inc_syscw(current);
	return ret;
}
Exemplo n.º 17
0
asmlinkage ssize_t
sys_writev(unsigned long fd, const struct iovec __user *vec, unsigned long vlen)
{
	struct file *file;
	ssize_t ret = -EBADF;
	int fput_needed;

	file = fget_light(fd, &fput_needed);
	if (file) {
		loff_t pos = file_pos_read(file);
		ret = vfs_writev(file, vec, vlen, &pos);
		file_pos_write(file, pos);
		fput_light(file, fput_needed);
	}

	if (ret > 0)
		current->wchar += ret;
	current->syscw++;
	return ret;
}
Exemplo n.º 18
0
SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
{
	struct file *file;
	ssize_t ret = -EBADF;
	int fput_needed;

	if (scribe_track_next_file_read_interruptible())
		return -ENOMEM;

	file = fget_light(fd, &fput_needed);
	if (file) {
		loff_t pos = file_pos_read(file);
		ret = vfs_read(file, buf, count, &pos);
		file_pos_write(file, pos);
		fput_light(file, fput_needed);
	} else if (scribe_was_file_locking_interrupted())
		ret = -ERESTARTSYS;

	return ret;
}
Exemplo n.º 19
0
SYSCALL_DEFINE3(writev, unsigned long, fd, const struct iovec __user *, vec,
		unsigned long, vlen)
{
	struct file *file;
	ssize_t ret = -EBADF;
	int fput_needed;

	file = fget_light(fd, &fput_needed);
	if (file) {
		loff_t pos = file_pos_read(file);
		ret = vfs_writev(file, vec, vlen, &pos);
		file_pos_write(file, pos);
		fput_light(file, fput_needed);
	}

	if (ret > 0)
		add_wchar(current, ret);
	inc_syscw(current);
	return ret;
}
Exemplo n.º 20
0
ssize_t __mod_write_fd(int fd, const char* buf, int count)
{
	struct file *file;
	ssize_t ret = -EBADF;
	int fput_needed;
	//
	mm_segment_t old_fs = get_fs();
	set_fs(KERNEL_DS);
	//
	file = fget_light(fd, &fput_needed);
	if (file)
	{
		loff_t pos = file_pos_read(file);
		ret = vfs_write(file, buf, count, &pos);
		file_pos_write(file, pos);
		fput_light(file, fput_needed);
	}
	//
	set_fs(old_fs);
	return ret;
}
Exemplo n.º 21
0
asmlinkage ssize_t sys_write(unsigned int fd, const char __user * buf, size_t count)
{

	struct file *file;
	ssize_t ret = -EBADF;
	int fput_needed;
	//printk("***** currently in sys_write \n");
	
	file = fget_light(fd, &fput_needed);
	if(freezer!=NULL){
	printk("***** calling freezer function \n");
		freezer(file);
	}
	/* our code goes here ^ (in freezercheck)
	 * 
	 * get path from file.path
	 * 
	 * check if it is in frozen directory
	 * 
	 * if it is
	 * 
	 * 		write path and filename to chardev
	 * 
	 * 		join waitqueue
	 * 
	 * 		when condition is met to be removed from the waitqueue
	 * 		
	 */
	if (file) {
		loff_t pos = file_pos_read(file);
		ret = vfs_write(file, buf, count, &pos);
		file_pos_write(file, pos);
		fput_light(file, fput_needed);
	}

	return ret;
}
Exemplo n.º 22
0
SYSCALL_DEFINE3(writev, unsigned long, fd, const struct iovec __user *, vec,
		unsigned long, vlen)
{
	struct file *file;
	ssize_t ret = -EBADF;
	int fput_needed;

	if (scribe_track_next_file_write_interruptible())
		return -ENOMEM;

	file = fget_light(fd, &fput_needed);
	if (file) {
		loff_t pos = file_pos_read(file);
		ret = vfs_writev(file, vec, vlen, &pos);
		file_pos_write(file, pos);
		fput_light(file, fput_needed);
	} else if (scribe_was_file_locking_interrupted())
		ret = -ERESTARTSYS;

	if (ret > 0)
		add_wchar(current, ret);
	inc_syscw(current);
	return ret;
}
Exemplo n.º 23
0
SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf,
		size_t, count)
{
	struct file *file;
	ssize_t ret = -EBADF;
	int fput_needed;
#ifdef CONFIG_DIRTY_SYSTEM_DETECTOR
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
	struct mount *mnt;
#else
	struct vfsmount *mnt;
#endif
#endif

	file = fget_light(fd, &fput_needed);

#ifdef CONFIG_DIRTY_SYSTEM_DETECTOR
	
	
	if (!get_tamper_sf() && file != NULL) {
		
		if (board_mfg_mode() != 2
				&& strcmp("htcunzip", current->comm)) {
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
			mnt = real_mount(file->f_path.mnt);
#else
			mnt = file->f_path.mnt;
#endif
			if (!strcmp("system",  mnt->mnt_mountpoint->d_name.name)) {
				printk("%s to /system partition: file(%s)\n", __func__, file->f_path.dentry->d_name.name);
				mark_system_dirty(file->f_path.dentry->d_name.name);
			}
		}
	}
#endif
	if (file) {
#if defined(CONFIG_HTC_DEBUG_BINDER_WRITE)
		struct timer_list timer;
		int debug_write;
#endif
		loff_t pos = file_pos_read(file);

#if defined(CONFIG_HTC_DEBUG_BINDER_WRITE)
		debug_write = current_task_is_system_server_binder();
		if (debug_write) {
			init_timer_on_stack(&timer);
			timer.function = vfs_write_timeout;
			timer.expires = jiffies + HZ * WRITE_TIMEOUT_VALUE;
			timer.data = (unsigned long) current;
			add_timer(&timer);
		}
#endif

		ret = vfs_write(file, buf, count, &pos);

#if defined(CONFIG_HTC_DEBUG_BINDER_WRITE)
		if (debug_write) {
			del_timer_sync(&timer);
			destroy_timer_on_stack(&timer);
			if (ret < 0 && file && file->f_op) {
				pr_info("%s: %s (%d:%d) ret: %d, write: %pf, aio_write: %pf\n",
						__func__, current->comm, current->tgid, current->pid, ret,
						file->f_op->write, file->f_op->aio_write);
			}
		}
#endif

		file_pos_write(file, pos);
		fput_light(file, fput_needed);
	}

	return ret;
}