Skip to content

Commit 5784d9f

Browse files
jc2870akpm00
authored andcommitted
ocfs2: fix null-ptr-deref when journal load failed.
During the mounting process, if journal_reset() fails because of too short journal, then lead to jbd2_journal_load() fails with NULL j_sb_buffer. Subsequently, ocfs2_journal_shutdown() calls jbd2_journal_flush()->jbd2_cleanup_journal_tail()-> __jbd2_update_log_tail()->jbd2_journal_update_sb_log_tail() ->lock_buffer(journal->j_sb_buffer), resulting in a null-pointer dereference error. To resolve this issue, we should check the JBD2_LOADED flag to ensure the journal was properly loaded. Additionally, use journal instead of osb->journal directly to simplify the code. Link: https://syzkaller.appspot.com/bug?extid=05b9b39d8bdfe1a0861f Link: https://lkml.kernel.org/r/[email protected] Fixes: f6f50e2 ("jbd2: Fail to load a journal if it is too short") Signed-off-by: Julian Sun <[email protected]> Reported-by: [email protected] Suggested-by: Joseph Qi <[email protected]> Reviewed-by: Joseph Qi <[email protected]> Cc: Mark Fasheh <[email protected]> Cc: Joel Becker <[email protected]> Cc: Junxiao Bi <[email protected]> Cc: Changwei Ge <[email protected]> Cc: Gang He <[email protected]> Cc: Jun Piao <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 052a45c commit 5784d9f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

fs/ocfs2/journal.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ void ocfs2_journal_shutdown(struct ocfs2_super *osb)
10551055
if (!igrab(inode))
10561056
BUG();
10571057

1058-
num_running_trans = atomic_read(&(osb->journal->j_num_trans));
1058+
num_running_trans = atomic_read(&(journal->j_num_trans));
10591059
trace_ocfs2_journal_shutdown(num_running_trans);
10601060

10611061
/* Do a commit_cache here. It will flush our journal, *and*
@@ -1074,9 +1074,10 @@ void ocfs2_journal_shutdown(struct ocfs2_super *osb)
10741074
osb->commit_task = NULL;
10751075
}
10761076

1077-
BUG_ON(atomic_read(&(osb->journal->j_num_trans)) != 0);
1077+
BUG_ON(atomic_read(&(journal->j_num_trans)) != 0);
10781078

1079-
if (ocfs2_mount_local(osb)) {
1079+
if (ocfs2_mount_local(osb) &&
1080+
(journal->j_journal->j_flags & JBD2_LOADED)) {
10801081
jbd2_journal_lock_updates(journal->j_journal);
10811082
status = jbd2_journal_flush(journal->j_journal, 0);
10821083
jbd2_journal_unlock_updates(journal->j_journal);

0 commit comments

Comments
 (0)