ocfs2: fix null-ptr-deref when journal load failed.
PATCH v3 1/1 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. Additionly, refine code to make it cleaner.
--- fs/ocfs2/journal.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/ocfs2/journal.c +3 -2
@@ -1074,9 +1074,10 @@ void ocfs2_journal_shutdown(struct ocfs2_super *osb) osb->commit_task =NULL ; } -BUG_ON (atomic_read (&(osb->journal->j_num_trans)) !=0 ); +BUG_ON (atomic_read (&(journal->j_num_trans)) !=0 ); -if (ocfs2_mount_local (osb)) { +if (ocfs2_mount_local (osb) && + (journal->j_journal->j_flags &JBD2_LOADED )) {jbd2_journal_lock_updates (journal->j_journal); status =jbd2_journal_flush (journal->j_journal,0 );jbd2_journal_unlock_updates (journal->j_journal);
Signature · 1 line
2.39.2
Joseph Qi
maintainerQuoted 9 lines · Julian Sun
During the mounting process, if
journal_reset()fails because of too short journal, then lead tojbd2_journal_load()fails with NULLj_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.
Quoted 3 lines
To resolve this issue, we should check the
JBD2_LOADEDflag to ensure the journal was properly loaded. Additionly, refine code to make it cleaner.
s/Additionly/Additionally
Additionally, use journal instead of osb->journal directly to simplify the code.
Quoted 14 lines
Reported-by [email protected]Suggested-by Joseph Qi <[email protected]>Signed-off-by Julian Sun <[email protected]>--- fs/ocfs2/journal.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)fs/ocfs2/journal.c +0
-0
fs/ocfs2/journal.c void ocfs2_journal_shutdown(struct ocfs2_super *osb) · line 1078
Quoted 6 lines
fs/ocfs2/journal.c +1
-1@@ -1074,9 +1074,10 @@ void ocfs2_journal_shutdown(struct ocfs2_super *osb) osb->commit_task =NULL ; } -BUG_ON (atomic_read (&(osb->journal->j_num_trans)) !=0 ); +BUG_ON (atomic_read (&(journal->j_num_trans)) !=0 );
Please do the same change for the above one:
num_running_trans = atomic_read(&(journal->j_num_trans));
fs/ocfs2/journal.c void ocfs2_journal_shutdown(struct ocfs2_super *osb) · line 1080
Quoted 3 lines
fs/ocfs2/journal.c +2
-1-if (ocfs2_mount_local (osb)) { +if (ocfs2_mount_local (osb) && + (journal->j_journal->j_flags &JBD2_LOADED )) {
Align it to the right place, please.
Thanks,
Joseph
Quoted 3 lines
fs/ocfs2/journal.c +0
-0jbd2_journal_lock_updates (journal->j_journal); status =jbd2_journal_flush (journal->j_journal,0 );jbd2_journal_unlock_updates (journal->j_journal);
Quoted 16 lines · Joseph Qi
Quoted 9 lines · Julian Sun
During the mounting process, if
journal_reset()fails because of too short journal, then lead tojbd2_journal_load()fails with NULLj_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.Quoted 3 lines
To resolve this issue, we should check the
JBD2_LOADEDflag to ensure the journal was properly loaded. Additionly, refine code to make it cleaner.
Quoted 5 lines
s/Additionly/Additionally
Additionally, use journal instead of
osb->journaldirectly to simplify
the code.
Yeah, sorry for the typo..
Quoted 24 lines
Quoted 18 lines
Reported-by [email protected]Suggested-by Joseph Qi <[email protected]>Signed-off-by Julian Sun <[email protected]>---
fs/ocfs2/journal.c | 5 +++--1 file changed, 3 insertions(+), 2 deletions(-)fs/ocfs2/journal.c +0
-0@@ -1074,9 +1074,10 @@ void ocfs2_journal_shutdown(struct ocfs2_super *osb) osb->commit_task = NULL; }Quoted 4 lines
- BUG_ON(atomic_read(&(osb->journal->j_num_trans)) != 0); + BUG_ON(atomic_read(&(journal->j_num_trans)) != 0);Please do the same change for the above one:
Quoted 1 line
num_running_trans= atomic_read(&(journal->j_num_trans));
Ok.
Quoted 5 lines
Quoted 4 lines
- if (
ocfs2_mount_local(osb)) {
+ if (ocfs2_mount_local(osb)&&
+ (journal->j_journal->j_flags&JBD2_LOADED)) {Align it to the right place, please.
Sure.
Quoted 7 lines
Thanks,
JosephQuoted 3 lines
jbd2_journal_lock_updates(journal->j_journal); status =
jbd2_journal_flush(journal->j_journal, 0);jbd2_journal_unlock_updates(journal->j_journal);
Thanks,
Signature · 1 line
Julian Sun <[email protected]>