Skip to content

Commit 91aa11f

Browse files
jankaratytso
authored andcommitted
jbd2: Fix use after free after error in jbd2_journal_dirty_metadata()
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 <[email protected]> Signed-off-by: Jan Kara <[email protected]> Signed-off-by: "Theodore Ts'o" <[email protected]> Cc: [email protected] # 3.2+
1 parent cde2d7a commit 91aa11f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

fs/ext4/ext4_jbd2.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,10 @@ int __ext4_handle_dirty_metadata(const char *where, unsigned int line,
255255
set_buffer_prio(bh);
256256
if (ext4_handle_valid(handle)) {
257257
err = jbd2_journal_dirty_metadata(handle, bh);
258-
if (err) {
259-
/* Errors can only happen if there is a bug */
260-
handle->h_err = err;
261-
__ext4_journal_stop(where, line, handle);
258+
/* Errors can only happen if there is a bug */
259+
if (WARN_ON_ONCE(err)) {
260+
ext4_journal_abort_handle(where, line, __func__, bh,
261+
handle, err);
262262
}
263263
} else {
264264
if (inode)

0 commit comments

Comments
 (0)