Commit 3834b12a authored by Harsh Prateek Bora's avatar Harsh Prateek Bora Committed by Eric Van Hensbergen

fs/9p: setrlimit fix for 9p write

Current 9p client file write code does not check for RLIMIT_FSIZE resource.
This bug was found by running LTP test case for setrlimit. This bug is fixed
by calling generic_write_checks before sending the write request to the
server.
Without this patch: the write function is allowed to write above the
RLIMIT_FSIZE set by user.
With this patch: the write function checks for RLIMIT_SIZE and writes upto
the size limit.
Signed-off-by: default avatarHarsh Prateek Bora <harsh@linux.vnet.ibm.com>
Signed-off-by: default avatarEric Van Hensbergen <ericvh@gmail.com>
parent 57ee047b
...@@ -219,7 +219,9 @@ static ssize_t ...@@ -219,7 +219,9 @@ static ssize_t
v9fs_file_write(struct file *filp, const char __user * data, v9fs_file_write(struct file *filp, const char __user * data,
size_t count, loff_t * offset) size_t count, loff_t * offset)
{ {
int n, rsize, total = 0; ssize_t retval;
size_t total = 0;
int n, rsize;
struct p9_fid *fid; struct p9_fid *fid;
struct p9_client *clnt; struct p9_client *clnt;
struct inode *inode = filp->f_path.dentry->d_inode; struct inode *inode = filp->f_path.dentry->d_inode;
...@@ -234,6 +236,17 @@ v9fs_file_write(struct file *filp, const char __user * data, ...@@ -234,6 +236,17 @@ v9fs_file_write(struct file *filp, const char __user * data,
rsize = fid->iounit ? fid->iounit : clnt->msize - P9_IOHDRSZ; rsize = fid->iounit ? fid->iounit : clnt->msize - P9_IOHDRSZ;
retval = generic_write_checks(filp, &origin, &count, 0);
if (retval)
goto out;
retval = -EINVAL;
if ((ssize_t) count < 0)
goto out;
retval = 0;
if (!count)
goto out;
do { do {
if (count < rsize) if (count < rsize)
rsize = count; rsize = count;
...@@ -258,9 +271,11 @@ v9fs_file_write(struct file *filp, const char __user * data, ...@@ -258,9 +271,11 @@ v9fs_file_write(struct file *filp, const char __user * data,
} }
if (n < 0) if (n < 0)
return n; retval = n;
else
return total; retval = total;
out:
return retval;
} }
static int v9fs_file_fsync(struct file *filp, int datasync) static int v9fs_file_fsync(struct file *filp, int datasync)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment