[Devel] [PATCH RHEL7 COMMIT] ms/fuse: Don't access pipe->buffers without pipe_lock()

Konstantin Khorenko khorenko at virtuozzo.com
Mon Aug 13 15:55:39 MSK 2018


The commit is pushed to "branch-rh7-3.10.0-862.9.1.vz7.70.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-862.9.1.vz7.70.2
------>
commit 97719ea269f1ea63b2faac3dde1eaebfd743c3ce
Author: Andrey Ryabinin <aryabinin at virtuozzo.com>
Date:   Mon Aug 13 15:55:39 2018 +0300

    ms/fuse: Don't access pipe->buffers without pipe_lock()
    
    fuse_dev_splice_write() reads pipe->buffers to determine the size of
    'bufs' array before taking the pipe_lock(). This is not safe as
    another thread might change the 'pipe->buffers' between the allocation
    and taking the pipe_lock(). So we end up with too small 'bufs' array.
    
    Move the bufs allocations inside pipe_lock()/pipe_unlock() to fix this.
    
    Fixes: dd3bb14f44a6 ("fuse: support splice() writing to fuse device")
    Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
    
    Cc: <stable at vger.kernel.org> # v2.6.35
    Signed-off-by: Miklos Szeredi <mszeredi at redhat.com>
    Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
---
 fs/fuse/dev.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 0071a6a9ff11..e32908a0d103 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -2063,11 +2063,14 @@ static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe,
 	if (!fud)
 		return -EPERM;
 
+	pipe_lock(pipe);
+
 	bufs = kvmalloc(pipe->buffers * sizeof(struct pipe_buffer), GFP_KERNEL);
-	if (!bufs)
+	if (!bufs) {
+		pipe_unlock(pipe);
 		return -ENOMEM;
+	}
 
-	pipe_lock(pipe);
 	nbuf = 0;
 	rem = 0;
 	for (idx = 0; idx < pipe->nrbufs && rem < len; idx++)


More information about the Devel mailing list