jbd2: Fix two annoyances in jbd2
Subsystems (2)
cover jbd2: Fix two annoyances in jbd2
Hello,
filesystem fuzzing of ocfs2 has revealed some issues in jbd2 where suitably corrupted fs can trigger issues in jbd2 - most notably a complaint about sb->s_sequence being 0 (which is actually correct after recent changes) and also attempt to replay the journal after it has been wiped. Fix them.
Honza
PATCH 1/2 jbd2: Remove wrong sb->s_sequence check
Journal emptiness is not determined by sb->s_sequence == 0 but rather by sb->s_start == 0 (which is set a few lines above). Furthermore 0 is a valid transaction ID so the check can spuriously trigger. Remove the invalid WARN_ON.
--- fs/jbd2/journal.c | 1 - 1 file changed, 1 deletion(-)
fs/jbd2/journal.c +0 -1
@@ -1879,7 +1879,6 @@ int jbd2_journal_update_sb_log_tail(journal_t *journal, tid_t tail_tid,/* Log is no longer empty */ write_lock (&journal->j_state_lock); -WARN_ON (!sb->s_sequence); journal->j_flags &= ~JBD2_FLUSHED ;write_unlock (&journal->j_state_lock);
Signature · 1 line
2.43.0
Re: [PATCH 1/2] jbd2: Remove wrong sb->s_sequence check
Quoted 7 lines · Jan Kara
Journal emptiness is not determined by
sb->s_sequence== 0 but rather bysb->s_start== 0 (which is set a few lines above). Furthermore 0 is a valid transaction ID so the check can spuriously trigger. Remove the invalidWARN_ON.Signed-off-by Jan Kara <[email protected]>
This is indeed subtle, it looks good to me.
Quoted 16 lines
--- fs/jbd2/journal.c | 1 - 1 file changed, 1 deletion(-)fs/jbd2/journal.c +0
-1@@ -1879,7 +1879,6 @@ int jbd2_journal_update_sb_log_tail(journal_t *journal, tid_t tail_tid,/* Log is no longer empty */ write_lock (&journal->j_state_lock); -WARN_ON (!sb->s_sequence); journal->j_flags &= ~JBD2_FLUSHED ;write_unlock (&journal->j_state_lock);
PATCH 2/2 jbd2: Do not try to recover wiped journal
In reply to Jan KaraIf a journal is wiped, we will set journal->j_tail to 0. However if 'write' argument is not set (as it happens for read-only device or for ocfs2), the on-disk superblock is not updated accordingly and thus jbd2_journal_recover() cat try to recover the wiped journal. Fix the check in jbd2_journal_recover() to use journal->j_tail for checking empty journal instead.
--- fs/jbd2/recovery.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
fs/jbd2/recovery.c +6 -5
@@ -287,19 +287,20 @@ static int fc_do_one_pass(journal_t *journal,int jbd2_journal_recover (journal_t *journal) {int err, err2; -journal_superblock_t * sb; -struct recovery_info info;memset (&info,0 ,sizeof (info)); - sb = journal->j_superblock;/* * The journal superblock's s_start field (the current log head) * is always zero if, and only if, the journal was cleanly -* unmounted. +* unmounted. We use its in-memory version j_tail here because +* jbd2_journal_wipe() could have updated it without updating journal +* superblock. */ -if (!sb->s_start) { +if (!journal->j_tail) { +journal_superblock_t *sb = journal->j_superblock; +jbd2_debug (1 ,"No recovery required, last transaction %d, head block %u\n" ,be32_to_cpu (sb->s_sequence),be32_to_cpu (sb->s_head)); journal->j_transaction_sequence =be32_to_cpu (sb->s_sequence) +1 ;
Signature · 1 line
2.43.0
Re: [PATCH 2/2] jbd2: Do not try to recover wiped journal
Quoted 8 lines · Jan Kara
If a journal is wiped, we will set
journal->j_tailto 0. However if 'write' argument is not set (as it happens for read-only device or for ocfs2), the on-disk superblock is not updated accordingly and thusjbd2_journal_recover()cat try to recover the wiped journal. Fix the check injbd2_journal_recover()to usejournal->j_tailfor checking empty journal instead.Signed-off-by Jan Kara <[email protected]>
Ha, right, it looks good to me.
Quoted 34 lines
--- fs/jbd2/recovery.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)fs/jbd2/recovery.c +6
-5@@ -287,19 +287,20 @@ static int fc_do_one_pass(journal_t *journal,int jbd2_journal_recover (journal_t *journal) {int err, err2; -journal_superblock_t * sb; -struct recovery_info info;memset (&info,0 ,sizeof (info)); - sb = journal->j_superblock;/* * The journal superblock's s_start field (the current log head) * is always zero if, and only if, the journal was cleanly -* unmounted. +* unmounted. We use its in-memory version j_tail here because +* jbd2_journal_wipe() could have updated it without updating journal +* superblock. */ -if (!sb->s_start) { +if (!journal->j_tail) { +journal_superblock_t *sb = journal->j_superblock; +jbd2_debug (1 ,"No recovery required, last transaction %d, head block %u\n" ,be32_to_cpu (sb->s_sequence),be32_to_cpu (sb->s_head)); journal->j_transaction_sequence =be32_to_cpu (sb->s_sequence) +1 ;
Quoted 8 lines · Jan Kara
filesystem fuzzing of ocfs2 has revealed some issues in jbd2 where suitably corrupted fs can trigger issues in jbd2 - most notably a complaint about
sb->s_sequencebeing 0 (which is actually correct after recent changes) and also attempt to replay the journal after it has been wiped. Fix them.Honza
[...]
Applied, thanks!
[1/2] jbd2: Remove wrong sb->s_sequence check
commit: e6eff39dd0fe4190c6146069cc16d160e71d1148
[2/2] jbd2: Do not try to recover wiped journal
commit: a662f3c03b754e1f97a2781fa242e95bdb139798Best regards,
Signature · 1 line
Theodore Ts'o <[email protected]>