Blob Blame History Raw
From: Vasily Averin <vvs@virtuozzo.com>
Date: Mon, 19 Aug 2019 09:53:50 +0300
Subject: fuse: BUG_ON correction in fuse_dev_splice_write()
Git-commit: 0e9fb6f17ad5b386b75451328975a07d7d953c6d
Patch-mainline: v5.8-rc1
References: bsc#1187356

commit 963545357202 ("fuse: reduce allocation size for splice_write")
changed size of bufs array, so BUG_ON which checks the index of the array
shold also be fixed.

[SzM: turn BUG_ON into WARN_ON]

Fixes: 963545357202 ("fuse: reduce allocation size for splice_write")
Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Acked-by: Luis Henriques <lhenriques@suse.com>
---
 fs/fuse/dev.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -2032,6 +2032,7 @@ static ssize_t fuse_dev_splice_write(str
 				     struct file *out, loff_t *ppos,
 				     size_t len, unsigned int flags)
 {
+	unsigned int count;
 	unsigned nbuf;
 	unsigned idx;
 	struct pipe_buffer *bufs;
@@ -2046,6 +2047,7 @@ static ssize_t fuse_dev_splice_write(str
 
 	pipe_lock(pipe);
 
+	count = pipe->nrbufs;
 	bufs = kvmalloc_array(pipe->nrbufs, sizeof(struct pipe_buffer),
 			      GFP_KERNEL);
 	if (!bufs) {
@@ -2067,8 +2069,8 @@ static ssize_t fuse_dev_splice_write(str
 		struct pipe_buffer *ibuf;
 		struct pipe_buffer *obuf;
 
-		BUG_ON(nbuf >= pipe->buffers);
-		BUG_ON(!pipe->nrbufs);
+		if (WARN_ON(nbuf >= count || !pipe->nrbufs))
+			goto out_free;
 		ibuf = &pipe->bufs[pipe->curbuf];
 		obuf = &bufs[nbuf];