diff mbox series

fuse: Fix use-after-free in fuse_dev_do_write()

Message ID 153786915356.22029.14929917223689579717.stgit@localhost.localdomain (mailing list archive)
State New, archived
Headers show
Series fuse: Fix use-after-free in fuse_dev_do_write() | expand

Commit Message

Kirill Tkhai Sept. 25, 2018, 9:52 a.m. UTC
After we found req in request_find() and released the lock,
everything may happen with the req in parallel.

Keep it alive till we finish touch its memory.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 fs/fuse/dev.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Miklos Szeredi Oct. 1, 2018, 9:26 a.m. UTC | #1
On Tue, Sep 25, 2018 at 11:52 AM, Kirill Tkhai <ktkhai@virtuozzo.com> wrote:
> After we found req in request_find() and released the lock,
> everything may happen with the req in parallel.
>
> Keep it alive till we finish touch its memory.
>
> Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>

Applied.

Thanks,
Miklos
diff mbox series

Patch

diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 675caed3e655..c2af8042f176 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -1877,16 +1877,20 @@  static ssize_t fuse_dev_do_write(struct fuse_dev *fud,
 
 	/* Is it an interrupt reply? */
 	if (req->intr_unique == oh.unique) {
+		__fuse_get_request(req);
 		spin_unlock(&fpq->lock);
 
 		err = -EINVAL;
-		if (nbytes != sizeof(struct fuse_out_header))
+		if (nbytes != sizeof(struct fuse_out_header)) {
+			fuse_put_request(fc, req);
 			goto err_finish;
+		}
 
 		if (oh.error == -ENOSYS)
 			fc->no_interrupt = 1;
 		else if (oh.error == -EAGAIN)
 			queue_interrupt(&fc->iq, req);
+		fuse_put_request(fc, req);
 
 		fuse_copy_finish(cs);
 		return nbytes;