Skip to content

Commit fb29e3b

Browse files
Lukas Czernercodewalkerster
authored andcommitted
ext4: fix potential use after free in __ext4_journal_stop
There is a use-after-free possibility in __ext4_journal_stop() in the case that we free the handle in the first jbd2_journal_stop() because we're referencing handle->h_err afterwards. This was introduced in 9705acd and it is wrong. Fix it by storing the handle->h_err value beforehand and avoid referencing potentially freed handle. Fixes: 9705acd Signed-off-by: Lukas Czerner <[email protected]> Reviewed-by: Andreas Dilger <[email protected]> Cc: [email protected] Conflicts: fs/ext4/ext4_jbd2.c Change-Id: I9fd9aca218637fe77f5ef41d47867b6281524b68
1 parent 8533a85 commit fb29e3b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

fs/ext4/ext4_jbd2.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,14 @@ int __ext4_journal_stop(const char *where, unsigned int line, handle_t *handle)
8787
ext4_put_nojournal(handle);
8888
return 0;
8989
}
90-
sb = handle->h_transaction->t_journal->j_private;
90+
9191
err = handle->h_err;
92+
if (!handle->h_transaction) {
93+
rc = jbd2_journal_stop(handle);
94+
return err ? err : rc;
95+
}
96+
97+
sb = handle->h_transaction->t_journal->j_private;
9298
rc = jbd2_journal_stop(handle);
9399

94100
if (!err)

0 commit comments

Comments
 (0)