Skip to content

Commit bac3190

Browse files
mnikictytso
authored andcommitted
jbd2: gracefully abort on checkpointing state corruptions
This patch targets two internal state machine invariants in checkpoint.c residing inside functions that natively return integer error codes. - In jbd2_cleanup_journal_tail(): A blocknr of 0 indicates a severely corrupted journal superblock. Replaced the J_ASSERT with a WARN_ON_ONCE and a graceful journal abort, returning -EFSCORRUPTED. - In jbd2_log_do_checkpoint(): Replaced the J_ASSERT_BH checking for an unexpected buffer_jwrite state. If the warning triggers, we explicitly drop the just-taken get_bh() reference and call __flush_batch() to safely clean up any previously queued buffers in the j_chkpt_bhs array, preventing a memory leak before returning -EFSCORRUPTED. Signed-off-by: Milos Nikic <nikic.milos@gmail.com> Reviewed-by: Andreas Dilger <adilger@dilger.ca> Reviewed-by: Zhang Yi <yi.zhang@huawei.com> Reviewed-by: Baokun Li <libaokun@linux.alibaba.com> Reviewed-by: Jan Kara <jack@suse.cz> Link: https://patch.msgid.link/20260311041548.159424-1-nikic.milos@gmail.com Signed-off-by: Theodore Ts'o <tytso@mit.edu> Cc: stable@kernel.org
1 parent 5422fe7 commit bac3190

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

fs/jbd2/checkpoint.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,15 @@ int jbd2_log_do_checkpoint(journal_t *journal)
267267
*/
268268
BUFFER_TRACE(bh, "queue");
269269
get_bh(bh);
270-
J_ASSERT_BH(bh, !buffer_jwrite(bh));
270+
if (WARN_ON_ONCE(buffer_jwrite(bh))) {
271+
put_bh(bh); /* drop the ref we just took */
272+
spin_unlock(&journal->j_list_lock);
273+
/* Clean up any previously batched buffers */
274+
if (batch_count)
275+
__flush_batch(journal, &batch_count);
276+
jbd2_journal_abort(journal, -EFSCORRUPTED);
277+
return -EFSCORRUPTED;
278+
}
271279
journal->j_chkpt_bhs[batch_count++] = bh;
272280
transaction->t_chp_stats.cs_written++;
273281
transaction->t_checkpoint_list = jh->b_cpnext;
@@ -325,7 +333,10 @@ int jbd2_cleanup_journal_tail(journal_t *journal)
325333

326334
if (!jbd2_journal_get_log_tail(journal, &first_tid, &blocknr))
327335
return 1;
328-
J_ASSERT(blocknr != 0);
336+
if (WARN_ON_ONCE(blocknr == 0)) {
337+
jbd2_journal_abort(journal, -EFSCORRUPTED);
338+
return -EFSCORRUPTED;
339+
}
329340

330341
/*
331342
* We need to make sure that any blocks that were recently written out

0 commit comments

Comments
 (0)