]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
jbd2: fix integer underflow in jbd2_journal_initialize_fast_commit()
authorJunrui Luo <moonafterrain@outlook.com>
Wed, 13 May 2026 09:28:40 +0000 (17:28 +0800)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 3 Jun 2026 14:24:01 +0000 (10:24 -0400)
jbd2_journal_initialize_fast_commit() validates journal capacity by
checking (journal->j_last - num_fc_blks < JBD2_MIN_JOURNAL_BLOCKS).
Both j_last and num_fc_blks are unsigned, so when num_fc_blks exceeds
j_last the subtraction wraps to a large value, bypassing the bounds
check.

The resulting underflow corrupts j_last, j_fc_first, and j_free,
leading to journal abort.

Fix by checking num_fc_blks against j_last before the subtraction,
returning -EFSCORRUPTED.

Fixes: 6866d7b3f2bb ("ext4 / jbd2: add fast commit initialization")
Reported-by: Yuhao Jiang <danisjiang@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Junrui Luo <moonafterrain@outlook.com>
Fixes: e029c5f27987 ("ext4: make num of fast commit blocks configurable")
Reviewed-by: Baokun Li <libaokun@linux.alibaba.com>
Fixes: e029c5f279872 ("ext4: make num of fast commit blocks configurable")
Reviewed-by: Zhang Yi <yi.zhang@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Link: https://patch.msgid.link/SYBPR01MB7881663C927DE9D7BBF4D1DFAF062@SYBPR01MB7881.ausprd01.prod.outlook.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/jbd2/journal.c

index 4f397fcdb13c51494added4bdd6026546b7ed5d5..e3b2e38e1a1b79649f96154e8b2a373e4bca0d3d 100644 (file)
@@ -2263,6 +2263,8 @@ jbd2_journal_initialize_fast_commit(journal_t *journal)
        unsigned long long num_fc_blks;
 
        num_fc_blks = jbd2_journal_get_num_fc_blks(sb);
+       if (num_fc_blks > journal->j_last)
+               return -EFSCORRUPTED;
        if (journal->j_last - num_fc_blks < JBD2_MIN_JOURNAL_BLOCKS)
                return -ENOSPC;