From: Jan Kara <jack@suse.cz>
To: linux-fsdevel@vger.kernel.org
Cc: tytso@mit.edu, bpm@sgi.com, jlbec@evilplan.org,
Jan Kara <jack@suse.cz>,
linux-ext4@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH 1/4] ext4: Fix possible use-after-free with AIO
Date: Wed, 23 Jan 2013 13:56:17 +0100 [thread overview]
Message-ID: <1358945780-23661-2-git-send-email-jack@suse.cz> (raw)
In-Reply-To: <1358945780-23661-1-git-send-email-jack@suse.cz>
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: linux-ext4@vger.kernel.org
CC: "Theodore Ts'o" <tytso@mit.edu>
CC: stable@vger.kernel.org
Signed-off-by: Jan Kara <jack@suse.cz>
---
fs/ext4/inode.c | 2 +-
fs/ext4/page-io.c | 9 ++++-----
2 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index cbfe13b..ba06638 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -2977,9 +2977,9 @@ static void ext4_end_io_dio(struct kiocb *iocb, loff_t offset,
if (!(io_end->flag & EXT4_IO_END_UNWRITTEN)) {
ext4_free_io_end(io_end);
out:
+ inode_dio_done(inode);
if (is_async)
aio_complete(iocb, ret, 0);
- inode_dio_done(inode);
return;
}
diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c
index 0016fbc..b42d04f 100644
--- a/fs/ext4/page-io.c
+++ b/fs/ext4/page-io.c
@@ -103,14 +103,13 @@ static int ext4_end_io(ext4_io_end_t *io)
"(inode %lu, offset %llu, size %zd, error %d)",
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 */
if (atomic_dec_and_test(&EXT4_I(inode)->i_unwritten))
wake_up_all(ext4_ioend_wq(inode));
+ if (io->flag & EXT4_IO_END_DIRECT)
+ inode_dio_done(inode);
+ if (io->iocb)
+ aio_complete(io->iocb, io->result, 0);
return ret;
}
--
1.7.1
next prev parent reply other threads:[~2013-01-23 12:56 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-23 12:56 [PATCH 0/4] Fix possible use after free with AIO Jan Kara
2013-01-23 12:56 ` Jan Kara [this message]
2013-01-23 13:18 ` [PATCH 1/4] ext4: Fix possible use-after-free " Carlos Maiolino
2013-01-23 12:56 ` [PATCH 2/4] xfs: " Jan Kara
2013-01-23 22:00 ` Ben Myers
2013-01-23 12:56 ` [PATCH 3/4] ocfs2: " Jan Kara
2013-01-23 12:56 ` [PATCH 4/4] fs: " Jan Kara
2013-01-23 15:02 ` Jeff Moyer
2013-01-23 19:18 ` Jan Kara
2013-01-23 16:03 ` [PATCH 0/4] Fix possible use after free " Jeff Moyer
-- strict thread matches above, loose matches on Subject: below --
2013-01-29 23:27 [PATCH 0/4 v2] " Jan Kara
2013-01-29 23:27 ` [PATCH 1/4] ext4: Fix possible use-after-free " Jan Kara
2013-01-30 3:51 ` Theodore Ts'o
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1358945780-23661-2-git-send-email-jack@suse.cz \
--to=jack@suse.cz \
--cc=bpm@sgi.com \
--cc=jlbec@evilplan.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).