[PATCH v3 0/2] ext4: reject impossible group free cluster counts
From: Zhao Gongyi
Date: Thu Nov 19 2026 - 21:55:34 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 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 fs/jbd2/ and fs/ext4/ with arm64 GCC 15.2 and W=1 at both
patch boundaries with CONFIG_UNICODE enabled.
Runtime tests of v3 covered these cases.
- Mount rejected out-of-range free-cluster counts. The recovery
callback rejected corrupt descriptors with an empty journal and
when corruption persisted in a separate descriptor block after block
replay. Recovery succeeded with valid descriptors after block replay.
- When post-replay validation failed, ext4 skipped the superblock
writeback used to restore error information.
- Read-only recovery completed fast commit replay and reached the
second callback. Deferred EA inode eviction completed without an
EROFS error or warning.
- When fast commit replay failed with pending EA inode evictions,
recovery drained the work before clearing the replay state.
- Recovery of an existing casefold filesystem loaded its encoding.
Earlier testing verified recovery of a previously resized image at
the expected size. In a separate test, the recovered superblock
reported four groups, up from two before replay. Recovery reached
descriptor validation and rejected the block bitmap location for
group 2. It remains to be established whether JBD2 replayed a valid
group 2 descriptor into the block that ext4 read.
Successful recovery of an online resize across a group descriptor
block boundary remains unverified. Rejection of casefold settings
changed by journal block replay also remains untested.
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/
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 | 332 +++++++++++++++++++++++++++++++++----------
fs/jbd2/journal.c | 22 ++-
fs/jbd2/recovery.c | 38 +++--
include/linux/jbd2.h | 7 +-
6 files changed, 316 insertions(+), 95 deletions(-)
base-commit: 4aa05e642bade8cf8405936b03cabf848fe6c456