splice: Apply generic position and size checks to each write 36/76536/2
authorBen Hutchings <ben@decadent.org.uk>
Thu, 29 Jan 2015 02:50:33 +0000 (02:50 +0000)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Wed, 3 Aug 2016 02:34:40 +0000 (19:34 -0700)
commit 894c6350eaad7e613ae267504014a456e00a3e2a from the 3.2-stable branch.

We need to check the position and size of file writes against various
limits, using generic_write_check().  This was not being done for
the splice write path.  It was fixed upstream by commit 8d0207652cbe
("->splice_write() via ->write_iter()") but we can't apply that.

CVE-2014-7822

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
[Ben fixed it in 3.2 stable, i ported it to 3.10 stable]
Signed-off-by: Zhang Zhen <zhenzhang.zhang@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Change-Id: I10f6cd44e0223d515d905ee5f3043b5d22c31057
Signed-off-by: Junghoon Kim <jhoon20.kim@samsung.com>
fs/ocfs2/file.c
fs/splice.c

index 46387e4..e0b1c88 100644 (file)
@@ -2453,12 +2453,14 @@ static ssize_t ocfs2_file_splice_write(struct pipe_inode_info *pipe,
        struct address_space *mapping = out->f_mapping;
        struct inode *inode = mapping->host;
        struct splice_desc sd = {
-               .total_len = len,
                .flags = flags,
-               .pos = *ppos,
                .u.file = out,
        };
-
+       ret = generic_write_checks(out, ppos, &len, 0);
+       if(ret)
+               return ret;
+       sd.total_len = len;
+       sd.pos = *ppos;
 
        trace_ocfs2_file_splice_write(inode, out, out->f_path.dentry,
                        (unsigned long long)OCFS2_I(inode)->ip_blkno,
index 4b5a5fa..f183f13 100644 (file)
@@ -1012,13 +1012,17 @@ generic_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
        struct address_space *mapping = out->f_mapping;
        struct inode *inode = mapping->host;
        struct splice_desc sd = {
-               .total_len = len,
                .flags = flags,
-               .pos = *ppos,
                .u.file = out,
        };
        ssize_t ret;
 
+       ret = generic_write_checks(out, ppos, &len, S_ISBLK(inode->i_mode));
+       if (ret)
+               return ret;
+       sd.total_len = len;
+       sd.pos = *ppos;
+
        pipe_lock(pipe);
 
        splice_from_pipe_begin(&sd);