aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Doebbelin <robert@quobyte.com>2016-03-07 09:50:56 +0100
committerMoyster <oysterized@gmail.com>2017-06-17 15:50:39 +0200
commit7e2cd0177d4e64717c323fa5df3f9a7d0eb59c68 (patch)
treee5486e1af25be0a33f5febb75a185f4d8510056a
parentdb70ea4aa161056ffb367913a6bce3ff03871ff3 (diff)
fuse: do not use iocb after it may have been freed
commit 7cabc61e01a0a8b663bd2b4c982aa53048218734 upstream. There's a race in fuse_direct_IO(), whereby is_sync_kiocb() is called on an iocb that could have been freed if async io has already completed. The fix in this case is simple and obvious: cache the result before starting io. It was discovered by KASan: Kernel: ================================================================== Kernel: BUG: KASan: use after free in fuse_direct_IO+0xb1a/0xcc0 at addr ffff88036c414390 Signed-off-by: Robert Doebbelin <robert@quobyte.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com> Fixes: bcba24ccdc82 ("fuse: enable asynchronous processing direct IO") Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Willy Tarreau <w@1wt.eu>
-rw-r--r--fs/fuse/file.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 7149a96f3..ca1cf74cf 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -2726,6 +2726,7 @@ fuse_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov,
loff_t i_size;
size_t count = iov_length(iov, nr_segs);
struct fuse_io_priv *io;
+ bool is_sync = is_sync_kiocb(iocb);
pos = offset;
inode = file->f_mapping->host;
@@ -2761,7 +2762,7 @@ fuse_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov,
* to wait on real async I/O requests, so we must submit this request
* synchronously.
*/
- if (!is_sync_kiocb(iocb) && (offset + count > i_size) && rw == WRITE)
+ if (!is_sync && (offset + count > i_size) && rw == WRITE)
io->async = false;
if (rw == WRITE)
@@ -2773,7 +2774,7 @@ fuse_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov,
fuse_aio_complete(io, ret < 0 ? ret : 0, -1);
/* we have a non-extending, async request, so return */
- if (!is_sync_kiocb(iocb))
+ if (!is_sync)
return -EIOCBQUEUED;
ret = wait_on_sync_kiocb(iocb);