Commit 9277aac3 authored by Robert Doebbelin's avatar Robert Doebbelin Committed by Ben Hutchings

fuse: do not use iocb after it may have been freed

commit 7cabc61e 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: default avatarRobert Doebbelin <robert@quobyte.com>
Signed-off-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
Fixes: bcba24cc ("fuse: enable asynchronous processing direct IO")
[bwh: Backported to 3.16: adjust context]
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent db88024c
...@@ -2876,6 +2876,7 @@ fuse_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter, ...@@ -2876,6 +2876,7 @@ fuse_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter,
loff_t i_size; loff_t i_size;
size_t count = iov_iter_count(iter); size_t count = iov_iter_count(iter);
struct fuse_io_priv *io; struct fuse_io_priv *io;
bool is_sync = is_sync_kiocb(iocb);
pos = offset; pos = offset;
inode = file->f_mapping->host; inode = file->f_mapping->host;
...@@ -2915,7 +2916,7 @@ fuse_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter, ...@@ -2915,7 +2916,7 @@ fuse_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter,
* to wait on real async I/O requests, so we must submit this request * to wait on real async I/O requests, so we must submit this request
* synchronously. * synchronously.
*/ */
if (!is_sync_kiocb(iocb) && (offset + count > i_size) && rw == WRITE) if (!is_sync && (offset + count > i_size) && rw == WRITE)
io->async = false; io->async = false;
if (rw == WRITE) if (rw == WRITE)
...@@ -2927,7 +2928,7 @@ fuse_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter, ...@@ -2927,7 +2928,7 @@ fuse_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter,
fuse_aio_complete(io, ret < 0 ? ret : 0, -1); fuse_aio_complete(io, ret < 0 ? ret : 0, -1);
/* we have a non-extending, async request, so return */ /* we have a non-extending, async request, so return */
if (!is_sync_kiocb(iocb)) if (!is_sync)
return -EIOCBQUEUED; return -EIOCBQUEUED;
ret = wait_on_sync_kiocb(iocb); ret = wait_on_sync_kiocb(iocb);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment