Commit b54e3acc authored by Jan Kara's avatar Jan Kara Committed by Greg Kroah-Hartman

ext4: fix possible use-after-free with AIO

commit 091e26df upstream.

Running AIO is pinning inode in memory using file reference. Once AIO
is completed using aio_complete(), file reference is put and inode can
be freed from memory. So we have to be sure that calling aio_complete()
is the last thing we do with the inode.
Reviewed-by: default avatarCarlos Maiolino <cmaiolino@redhat.com>
Acked-by: default avatarJeff Moyer <jmoyer@redhat.com>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
Signed-off-by: default avatar"Theodore Ts'o" <tytso@mit.edu>
[bwh: Backported to 3.2: adjust context]
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
Cc: Rui Xiang <rui.xiang@huawei.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 8a4188e2
...@@ -2800,9 +2800,9 @@ static void ext4_end_io_dio(struct kiocb *iocb, loff_t offset, ...@@ -2800,9 +2800,9 @@ static void ext4_end_io_dio(struct kiocb *iocb, loff_t offset,
if (!(io_end->flag & EXT4_IO_END_UNWRITTEN)) { if (!(io_end->flag & EXT4_IO_END_UNWRITTEN)) {
ext4_free_io_end(io_end); ext4_free_io_end(io_end);
out: out:
inode_dio_done(inode);
if (is_async) if (is_async)
aio_complete(iocb, ret, 0); aio_complete(iocb, ret, 0);
inode_dio_done(inode);
return; return;
} }
......
...@@ -107,14 +107,13 @@ int ext4_end_io_nolock(ext4_io_end_t *io) ...@@ -107,14 +107,13 @@ int ext4_end_io_nolock(ext4_io_end_t *io)
inode->i_ino, offset, size, ret); inode->i_ino, offset, size, ret);
} }
if (io->iocb)
aio_complete(io->iocb, io->result, 0);
if (io->flag & EXT4_IO_END_DIRECT)
inode_dio_done(inode);
/* Wake up anyone waiting on unwritten extent conversion */ /* Wake up anyone waiting on unwritten extent conversion */
if (atomic_dec_and_test(&EXT4_I(inode)->i_aiodio_unwritten)) if (atomic_dec_and_test(&EXT4_I(inode)->i_aiodio_unwritten))
wake_up_all(ext4_ioend_wq(io->inode)); wake_up_all(ext4_ioend_wq(io->inode));
if (io->flag & EXT4_IO_END_DIRECT)
inode_dio_done(inode);
if (io->iocb)
aio_complete(io->iocb, io->result, 0);
return ret; return ret;
} }
......
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