fs: Fix possible use-after-free with AIO
authorJan Kara <jack@suse.cz>
Tue, 29 Jan 2013 23:28:01 +0000 (00:28 +0100)
committerAl Viro <viro@zeniv.linux.org.uk>
Sat, 23 Feb 2013 04:31:36 +0000 (23:31 -0500)
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.

CC: Christoph Hellwig <hch@infradead.org>
CC: Jens Axboe <axboe@kernel.dk>
CC: Jeff Moyer <jmoyer@redhat.com>
CC: stable@vger.kernel.org
Acked-by: Jeff Moyer <jmoyer@redhat.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/direct-io.c

index cf5b44b..f853263 100644 (file)
@@ -261,9 +261,9 @@ static ssize_t dio_complete(struct dio *dio, loff_t offset, ssize_t ret, bool is
                dio->end_io(dio->iocb, offset, transferred,
                            dio->private, ret, is_async);
        } else {
+               inode_dio_done(dio->inode);
                if (is_async)
                        aio_complete(dio->iocb, ret, 0);
-               inode_dio_done(dio->inode);
        }
 
        return ret;