[PATCH v4 0/2] ext4: reject impossible group free cluster counts
From: Zhao Gongyi
Date: Mon Nov 23 2026 - 22:39:40 EST
ext4 initializes its free-space counters from the group descriptors. A
corrupt descriptor can advertise more free clusters than its group can
hold. Journal block replay can also replace the superblock and group
descriptors that were examined when mounting.
This series adds an optional JBD2 recovery callback and uses it in ext4
to validate the recovered geometry and group descriptors. It checks the
metadata before fast commit replay and checks the descriptors again
after fast commit replay. Both halves of the group free-cluster count
are read under the group lock.
Changes since v3
- Reject loss of HAS_JOURNAL before fast commit replay or journal
reset.
- Recheck the extra inode size settings and the checksum seed,
including EA_INODE and CSUM_SEED without METADATA_CSUM.
- Validate feature and field changes that affect mount setup.
Recheck encryption constraints and initialize the VFS encoding
when replay applies online feature enablement.
- Preserve JBD2's failed-commit diagnostic when recovery uses a
validation callback. Document the callback context and lifetime.
Changes since v2
- Skip restoring and writing out superblock error information when
journal load fails.
- Drain deferred EA inode evictions before checking descriptors after
fast commit replay. If replay fails, drain the work before restoring
the read-only flag. Leave fast commit state cleanup to the mount
failure path.
- Reject changes to the casefold feature and encoding settings during
journal recovery.
- The JBD2 patch is unchanged.
Changes since v1
- Keep the descriptor checks needed to load the internal journal and
defer full validation on recovery mounts until block replay completes.
- Revalidate the recovered geometry and reload the descriptor table
when replay changes its layout.
- Put the JBD2 interface in its own patch and read the free-cluster
count under the group lock.
Testing
Built v4 with arm64 GCC 15.2 and W=1 at both patch boundaries
for fs/jbd2/ and fs/ext4/, with CONFIG_UNICODE enabled.
Also built the complete series with CONFIG_UNICODE disabled
and CONFIG_FS_ENCRYPTION enabled.
A host-side control-flow test covered the failed-commit diagnostic
for callback and legacy callers, callback errors, and fast commit
replay ordering.
Ran v4 in an instrumented amd64 QEMU/KVM guest on 7.4.0-rc2-syz
(7475ea8b5), with both patches applied to that test tree.
- Recovery accepted valid descriptors after block replay. The callback
rejected out-of-range free-cluster counts with an empty journal and
when corruption persisted in a separate descriptor block after block
replay.
- Recovery of an online resize grew the filesystem from 32 to 128
groups, reloaded the descriptor table from one block to two, and
completed a read-write mount.
- Read-write recovery with fast commit enabled reached the second
callback and passed descriptor validation. Read-only recovery
reached the first callback and mounted without errors or warnings.
- Recovery mounted an existing casefold filesystem. On the empty
journal path, failed descriptor validation left the superblock
unchanged.
Earlier v3 tests covered deferred EA inode eviction on successful
read-only fast commit recovery and on fast commit replay failure.
Application of fast commit tags and the read-only path through the
second callback remain unverified on v4. Replay of online feature
enablement and rejection of invalid replayed superblock settings,
including casefold settings, still need runtime coverage.
Link: https://lore.kernel.org/linux-ext4/20261102042428.65204-1-zhaogongyi@xxxxxxxxxxxxx/
Link: https://lore.kernel.org/linux-ext4/20261119122601.85293-1-zhaogongyi@xxxxxxxxxxxxx/
Link: https://lore.kernel.org/linux-ext4/sashiko-outbox-223131@xxxxxxxxxx/
Link: https://lore.kernel.org/linux-ext4/20261120025459.70290-1-zhaogongyi@xxxxxxxxxxxxx/
Link: https://sashiko.dev/#/patchset/20261120025459.70290-1-zhaogongyi@xxxxxxxxxxxxx?part=2
Zhao Gongyi (2):
jbd2: add a metadata validation hook to journal recovery
ext4: reject impossible group free cluster counts
fs/ext4/balloc.c | 10 +-
fs/ext4/ext4.h | 2 +
fs/ext4/super.c | 452 +++++++++++++++++++++++++++++++++----------
fs/jbd2/journal.c | 33 +++-
fs/jbd2/recovery.c | 42 ++--
include/linux/jbd2.h | 7 +-
6 files changed, 425 insertions(+), 121 deletions(-)
base-commit: 4aa05e642bade8cf8405936b03cabf848fe6c456