diff mbox series

fuse: fix use-after-free in fuse_direct_IO()

Message ID 20181109135146.23470-1-lczerner@redhat.com (mailing list archive)
State New, archived
Headers show
Series fuse: fix use-after-free in fuse_direct_IO() | expand

Commit Message

Lukas Czerner Nov. 9, 2018, 1:51 p.m. UTC
In async IO blocking case the additional reference to the io is taken for
it to survive fuse_aio_complete(). In non blocking case this additional
reference is not needed, however we still reference io to figure out
whether to wait for completion or not. This is wrong and will lead to
use-after-free. Fix it by storing blocking information in separate
variable.

This was spotted by KASAN when running generic/208 fstest.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Fixes: 744742d692e3 ("fuse: Add reference counting for fuse_io_priv")
Reported-by: Zorro Lang <zlang@redhat.com>
---
 fs/fuse/file.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Miklos Szeredi Nov. 9, 2018, 2:57 p.m. UTC | #1
On Fri, Nov 9, 2018 at 2:51 PM, Lukas Czerner <lczerner@redhat.com> wrote:
> In async IO blocking case the additional reference to the io is taken for
> it to survive fuse_aio_complete(). In non blocking case this additional
> reference is not needed, however we still reference io to figure out
> whether to wait for completion or not. This is wrong and will lead to
> use-after-free. Fix it by storing blocking information in separate
> variable.
>
> This was spotted by KASAN when running generic/208 fstest.

Thanks, applied.

Miklos
diff mbox series

Patch

diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index cc2121b37bf5..b52f9baaa3e7 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -2924,10 +2924,12 @@  fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
 	}
 
 	if (io->async) {
+		bool blocking = io->blocking;
+
 		fuse_aio_complete(io, ret < 0 ? ret : 0, -1);
 
 		/* we have a non-extending, async request, so return */
-		if (!io->blocking)
+		if (!blocking)
 			return -EIOCBQUEUED;
 
 		wait_for_completion(&wait);