Skip to content

Commit

Permalink
jbd2: Fix use after free after error in jbd2_journal_dirty_metadata()
Browse files Browse the repository at this point in the history
commit 91aa11f upstream.

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 9ea7a0d 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>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Jan Kara authored and Greg Kroah-Hartman committed Aug 20, 2013
1 parent dadf2af commit 9cfae3e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions fs/ext4/ext4_jbd2.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ int __ext4_handle_dirty_metadata(const char *where, unsigned int line,

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)
Expand Down

0 comments on commit 9cfae3e

Please sign in to comment.