From: sashiko-bot@kernel.org
To: "Zhao Gongyi" <zhaogongyi@bytedance.com>, linux-ext4@vger.kernel.org
Cc: tytso@mit.edu
Subject: Re: [PATCH v2 2/2] ext4: reject impossible group free cluster counts
Date: Thu, 19 Nov 2026 13:02:59 +0000 [thread overview]
Message-ID: <sashiko-outbox-223131@kernel.org> (raw)
In-Reply-To: <20261119122601.85293-3-zhaogongyi@bytedance.com>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] ext4: corrupt replayed superblock committed on error in
ext4_load_journal()
- [Medium] ext4: early ext4_fc_replay_cleanup() in ext4_load_journal()
before work flush
- [Medium] ext4: missing s_ea_inode_work flush in
ext4_validate_replayed_metadata()
- [Medium] ext4: uninitialized sb->s_encoding when replay enables
casefold feature
--
commit 8d754fdcbde13550773a9fc6bd6d91302151721b
Author: Zhao Gongyi <zhaogongyi@bytedance.com>
ext4: reject impossible group free cluster counts
This commit rejects group descriptor free-cluster counts that exceed the
group's cluster capacity and validates recovered superblock geometry and
group descriptors during journal and fast commit replay.
Link: https://lore.kernel.org/linux-ext4/20261102042428.65204-1-zhaogongyi@bytedance.com/
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 359f9d4ed4479..68c33a9542897 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
[ ... ]
> @@ -4939,88 +4970,193 @@ static int ext4_check_geometry(struct super_block *sb,
[ ... ]
> +static int ext4_validate_replayed_metadata(journal_t *journal, void *data,
> + bool after_fast_commit)
> +{
> + struct ext4_replay_callback_data *replay = data;
> + struct super_block *sb = journal->j_private;
> + struct ext4_sb_info *sbi = EXT4_SB(sb);
> + struct ext4_super_block *es = sbi->s_es;
> + struct ext4_super_block *old = &replay->super;
> + ext4_fsblk_t sb_block = sbi->s_sbh->b_blocknr;
> + ext4_group_t groups_count;
> + unsigned int inode_size, first_ino;
> + u32 incompat, ro_compat;
> + int err;
> +
> + /* Fast commits only change descriptor contents, such as counts. */
> + if (after_fast_commit) {
> + if (!(sbi->s_mount_state & EXT4_FC_REPLAY))
> + return 0;
> + goto check_descriptors;
> + }
[Severity: Medium]
Should ext4_validate_replayed_metadata() flush sbi->s_ea_inode_work before
jumping to check_descriptors when after_fast_commit is true?
When fast commit replay unlinks an inode that drops the last reference to an
EA inode, ext4_put_ea_inode() schedules sbi->s_ea_inode_work with a 1-jiffy
delay. Without flushing that delayed work here, the bg_free_blocks_count
updates from freeing the EA inode's blocks run after descriptor validation has
already completed, and on a read-only mount requiring recovery the work runs
after ext4_load_journal() restores SB_RDONLY, hitting
WARN_ON_ONCE(sb_rdonly(sb)) and failing with -EROFS in
ext4_journal_check_start().
> + incompat = le32_to_cpu(es->s_feature_incompat ^ old->s_feature_incompat);
> + ro_compat = le32_to_cpu(es->s_feature_ro_compat ^ old->s_feature_ro_compat);
> + if (es->s_rev_level == cpu_to_le32(EXT4_GOOD_OLD_REV)) {
> + inode_size = EXT4_GOOD_OLD_INODE_SIZE;
> + first_ino = EXT4_GOOD_OLD_FIRST_INO;
> + } else {
> + inode_size = le16_to_cpu(es->s_inode_size);
> + first_ino = le32_to_cpu(es->s_first_ino);
> + }
> +
> + /* Online resize can grow the filesystem without changing group units. */
> + if (es->s_magic != old->s_magic ||
> + es->s_log_block_size != old->s_log_block_size ||
> + es->s_log_cluster_size != old->s_log_cluster_size ||
> + es->s_blocks_per_group != old->s_blocks_per_group ||
> + es->s_clusters_per_group != old->s_clusters_per_group ||
> + es->s_inodes_per_group != old->s_inodes_per_group ||
> + es->s_first_data_block != old->s_first_data_block ||
> + inode_size != sbi->s_inode_size || first_ino != sbi->s_first_ino ||
> + es->s_desc_size != old->s_desc_size ||
> + es->s_log_groups_per_flex != old->s_log_groups_per_flex ||
> + ext4_blocks_count(es) < ext4_blocks_count(old) ||
> + (incompat & (EXT4_FEATURE_INCOMPAT_64BIT |
> + EXT4_FEATURE_INCOMPAT_FLEX_BG)) ||
[Severity: Medium]
Can journal replay enable EXT4_FEATURE_INCOMPAT_CASEFOLD while leaving
sb->s_encoding NULL?
ext4_encoding_init() runs in __ext4_fill_super() before journal replay and
returns early if EXT4_FEATURE_INCOMPAT_CASEFOLD is not set in the unrecovered
superblock. If journal replay sets EXT4_FEATURE_INCOMPAT_CASEFOLD in
es->s_feature_incompat, ext4_validate_replayed_metadata() neither rejects the
change nor initializes sb->s_encoding, so looking up or hashing any directory
with EXT4_CASEFOLD_FL causes a NULL pointer dereference of sb->s_encoding in
utf8_casefold() -> utf8nlookup().
[ ... ]
> @@ -6261,9 +6426,11 @@ static int ext4_load_journal(struct super_block *sb,
> */
> if (enable_write)
> sb->s_flags &= ~SB_RDONLY;
> - err = jbd2_journal_load(journal);
> + err = jbd2_journal_load_with_callback(journal, callback, replay);
> if (enable_write)
> sb->s_flags |= SB_RDONLY;
> + kfree(replay);
> +
> if (save && memcmp(((char *) es) + EXT4_S_ERR_START,
> save, EXT4_S_ERR_LEN)) {
> memcpy(((char *) es) + EXT4_S_ERR_START,
> @@ -6285,6 +6452,7 @@ static int ext4_load_journal(struct super_block *sb,
> }
[Severity: Medium]
If jbd2_journal_load_with_callback() fails because
ext4_validate_replayed_metadata() rejected a corrupt replayed superblock in
es, does the error restoration block right below still write that corrupt
superblock to disk?
When the replayed superblock in sbi->s_sbh differs from the pre-replay save
buffer in EXT4_S_ERR_START..EXT4_S_ERR_END (or EXT4_ERROR_FS is set in
sbi->s_mount_state), changed is set to true even when err is non-zero, and
ext4_commit_super(sb) stamps a newly computed valid checksum onto the rejected
replayed superblock and commits it to disk.
> if (err) {
> + ext4_fc_replay_cleanup(sb);
> ext4_msg(sb, KERN_ERR, "error loading journal");
> goto err_out;
> }
[Severity: Medium]
Does calling ext4_fc_replay_cleanup(sb) here clear EXT4_FC_REPLAY before
failed_mount3a in __ext4_fill_super() flushes sbi->s_ea_inode_work?
In __ext4_fill_super(), failed_mount3a calls
flush_delayed_work(&sbi->s_ea_inode_work) right before
ext4_fc_replay_cleanup(sb) so that any EA inode evictions queued during fast
commit replay run while EXT4_FC_REPLAY is still set. Clearing EXT4_FC_REPLAY
early in ext4_load_journal() causes those flushed evictions to run in normal
non-replay mode while sbi->s_group_info is still NULL (before ext4_mb_init()),
so ext4_free_inode() sees ext4_get_group_info() == NULL and triggers
ext4_std_error(sb, -EFSCORRUPTED).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119122601.85293-1-zhaogongyi@bytedance.com?part=2
prev parent reply other threads:[~2026-11-19 13:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 12:25 [PATCH v2 0/2] ext4: reject impossible group free cluster counts Zhao Gongyi
2026-11-19 12:26 ` [PATCH v2 1/2] jbd2: add a metadata validation hook to journal recovery Zhao Gongyi
2026-11-19 12:34 ` sashiko-bot
2026-11-19 12:26 ` [PATCH v2 2/2] ext4: reject impossible group free cluster counts Zhao Gongyi
2026-11-19 13:02 ` sashiko-bot [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-223131@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tytso@mit.edu \
--cc=zhaogongyi@bytedance.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox