From: sashiko-bot@kernel.org
To: "Zhao Gongyi" <zhaogongyi@bytedance.com>, linux-ext4@vger.kernel.org
Cc: tytso@mit.edu
Subject: Re: [PATCH v3 2/2] ext4: reject impossible group free cluster counts
Date: Fri, 20 Nov 2026 03:23:12 +0000 [thread overview]
Message-ID: <sashiko-outbox-224402@kernel.org> (raw)
In-Reply-To: <20261120025459.70290-3-zhaogongyi@bytedance.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] ext4: missing superblock checks in
ext4_validate_replayed_metadata()
--
commit 74564af214213946c8db9db48f043911b396d215
Author: Zhao Gongyi <zhaogongyi@bytedance.com>
ext4: reject impossible group free cluster counts
This commit rejects group descriptor free cluster counts that exceed a
group's capacity and validates replayed superblock and group descriptor
metadata during journal recovery.
Link: https://lore.kernel.org/linux-ext4/20261102042428.65204-1-zhaogongyi@bytedance.com/
Link: https://lore.kernel.org/linux-ext4/sashiko-outbox-223131@kernel.org/
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 359f9d4ed4479..45d6f39bc3f18 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
[ ... ]
> @@ -4939,88 +4970,204 @@ 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;
> + /* Deferred EA inode eviction can change group free counts. */
> + flush_delayed_work(&sbi->s_ea_inode_work);
> + goto check_descriptors;
> + }
> +
> + 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)) ||
> + (ro_compat & (EXT4_FEATURE_RO_COMPAT_BIGALLOC |
> + EXT4_FEATURE_RO_COMPAT_METADATA_CSUM |
> + EXT4_FEATURE_RO_COMPAT_GDT_CSUM |
> + EXT4_FEATURE_RO_COMPAT_READONLY))) {
> + ext4_msg(sb, KERN_ERR, "invalid filesystem geometry after journal replay");
> + return -EFSCORRUPTED;
> + }
> +
> + /* An unreplayed superblock can contain mount-time hash flags. */
> + if (memcmp(es, old, sizeof(*es)) &&
> + (!ext4_verify_csum_type(sb, es) ||
> + !ext4_superblock_csum_verify(sb, es))) {
> + ext4_msg(sb, KERN_ERR, "invalid superblock checksum after journal replay");
> + return -EFSBADCRC;
> + }
> +
> + if (ext4_has_feature_metadata_csum(sb) &&
> + sbi->s_csum_seed != (ext4_has_feature_csum_seed(sb) ?
> + le32_to_cpu(es->s_checksum_seed) :
> + ext4_chksum(~0, es->s_uuid, sizeof(es->s_uuid)))) {
> + ext4_msg(sb, KERN_ERR, "metadata checksum seed changed during journal replay");
> + return -EFSCORRUPTED;
> + }
> +
> + /* The VFS encoding was initialized before replay. */
> + if ((incompat & EXT4_FEATURE_INCOMPAT_CASEFOLD) ||
> + (ext4_has_feature_casefold(sb) &&
> + (es->s_encoding != old->s_encoding ||
> + es->s_encoding_flags != old->s_encoding_flags))) {
> + ext4_msg(sb, KERN_ERR, "casefold settings changed during journal replay");
> + return -EFSCORRUPTED;
> + }
> +
> + if (!ext4_feature_set_ok(sb, replay->readonly))
> + return -EINVAL;
> +
> + err = ext4_check_geometry(sb, es, &groups_count);
> + if (err)
> + return err;
[Severity: Medium]
Can a replayed superblock bypass pre-replay checks on fields and features
that ext4_validate_replayed_metadata() does not re-verify?
If journal replay clears EXT4_FEATURE_COMPAT_HAS_JOURNAL in es,
ext4_validate_replayed_metadata() succeeds and JBD2 resets the journal,
after which ext4_load_journal() -> ext4_clear_journal_err() calls
ext4_error() (committing the corrupt superblock and panicking when
ERRORS_PANIC is enabled).
Similarly, es->s_min_extra_isize and es->s_want_extra_isize are only
checked against sbi->s_inode_size in ext4_inode_info_init() before replay,
so a replayed s_min_extra_isize larger than s_inode_size -
EXT4_GOOD_OLD_INODE_SIZE will later cause ext4_expand_extra_isize_ea() to
shift in-inode xattrs past the end of the raw inode.
In addition, sbi->s_csum_seed is only checked when
ext4_has_feature_metadata_csum(sb) is set, even though
ext4_init_metadata_csum() also initializes it for EA_INODE and CSUM_SEED,
and changes to features or fields validated before replay (such as
ENCRYPT, INLINE_DATA, HUGE_FILE, s_encryption_level, and s_creator_os) are
not rejected here.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261120025459.70290-1-zhaogongyi@bytedance.com?part=2
prev parent reply other threads:[~2026-11-20 3:23 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 2:54 [PATCH v3 2/2] ext4: reject impossible group free cluster counts Zhao Gongyi
2026-11-20 3:23 ` 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-224402@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.