* [PATCH] ext4: Fix use after free after error in jbd2_journal_dirty_metadata()
@ 2013-08-12 13:39 Jan Kara
2013-08-12 13:56 ` Theodore Ts'o
0 siblings, 1 reply; 2+ messages in thread
From: Jan Kara @ 2013-08-12 13:39 UTC (permalink / raw)
To: Ted Tso; +Cc: Sage Weil, linux-ext4, Jan Kara
When jbd2_journal_dirty_metadata() returns error,
__ext4_handle_dirty_metadata() stops the handle. However callers of this
function do not count with that fact and still happily used now freed
handle. This use after free can result in various issues but very likely
we oops soon.
The motivation of adding __ext4_journal_stop() into
__ext4_handle_dirty_metadata() in commit 9ea7a0df seems to be only to
improve error reporting. So replace __ext4_journal_stop() with
ext4_journal_abort_handle() which was there before that commit and add
WARN_ON_ONCE() to dump stack to provide useful information.
Reported-by: Sage Weil <sage@inktank.com>
Signed-off-by: Jan Kara <jack@suse.cz>
---
fs/ext4/ext4_jbd2.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/fs/ext4/ext4_jbd2.c b/fs/ext4/ext4_jbd2.c
index 72a3600..735e946 100644
--- a/fs/ext4/ext4_jbd2.c
+++ b/fs/ext4/ext4_jbd2.c
@@ -255,10 +255,11 @@ int __ext4_handle_dirty_metadata(const char *where, unsigned int line,
set_buffer_prio(bh);
if (ext4_handle_valid(handle)) {
err = jbd2_journal_dirty_metadata(handle, bh);
- if (err) {
- /* Errors can only happen if there is a bug */
- handle->h_err = err;
- __ext4_journal_stop(where, line, handle);
+ /* Errors can only happen if there is a bug */
+ if (WARN_ON_ONCE(err)) {
+ ext4_journal_abort_handle(where, line, __func__, bh,
+ handle, err);
+
}
} else {
if (inode)
--
1.8.1.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ext4: Fix use after free after error in jbd2_journal_dirty_metadata()
2013-08-12 13:39 [PATCH] ext4: Fix use after free after error in jbd2_journal_dirty_metadata() Jan Kara
@ 2013-08-12 13:56 ` Theodore Ts'o
0 siblings, 0 replies; 2+ messages in thread
From: Theodore Ts'o @ 2013-08-12 13:56 UTC (permalink / raw)
To: Jan Kara; +Cc: Sage Weil, linux-ext4
On Mon, Aug 12, 2013 at 03:39:04PM +0200, Jan Kara wrote:
> When jbd2_journal_dirty_metadata() returns error,
> __ext4_handle_dirty_metadata() stops the handle. However callers of this
> function do not count with that fact and still happily used now freed
> handle. This use after free can result in various issues but very likely
> we oops soon.
>
> The motivation of adding __ext4_journal_stop() into
> __ext4_handle_dirty_metadata() in commit 9ea7a0df seems to be only to
> improve error reporting. So replace __ext4_journal_stop() with
> ext4_journal_abort_handle() which was there before that commit and add
> WARN_ON_ONCE() to dump stack to provide useful information.
>
> Reported-by: Sage Weil <sage@inktank.com>
> Signed-off-by: Jan Kara <jack@suse.cz>
Applied, thanks.
- Ted
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-08-12 13:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-12 13:39 [PATCH] ext4: Fix use after free after error in jbd2_journal_dirty_metadata() Jan Kara
2013-08-12 13:56 ` Theodore Ts'o
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).