[PATCH v2 0/2] ext4: reject impossible group free cluster counts

From: Zhao Gongyi

Date: Thu Nov 19 2026 - 07:26:51 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 consumes it and checks the
descriptors again after fast commit replay. The ext4 check reads both
halves of the free-cluster count while holding the group lock.

Changes since v1

- Defer full descriptor validation on recovery mounts until journal
block replay completes. Keep the initial checks needed to load the
internal journal.
- Revalidate the superblock geometry and reload the descriptor table
when replay changes its layout. Validate the free-cluster counts
against the recovered geometry.
- Put the JBD2 interface in its own patch. Sample the group free-cluster
count under the existing group lock.

Testing

The earlier combined patch was tested in an amd64 QEMU/KVM guest
running a 7.4.0-rc2-based kernel. The runs covered these cases.

- ext4 rejected the corrupted bigalloc image before free-space
accounting. Valid read-only mounts succeeded and read-only mounts
with an out-of-range count failed.
- Ordinary journal recovery succeeded and mounted read-write when the
recovered group descriptors were valid.
- The recovery callback rejected an out-of-range count with an empty
journal and during recovery with a nonempty journal when corruption
remained in a separate group descriptor block.

The recovery tests used additional diagnostic logging to identify the
callback. The QEMU runs preceded the split and group-lock change.
Fast commit replay and recovery from an online resize that crosses a
group descriptor block boundary still need runtime coverage.

Built fs/ext4/ and fs/jbd2/ on the ext4 dev base with arm64 GCC 15.2
and W=1 after applying each patch in the series.

Link: https://lore.kernel.org/linux-ext4/20261102042428.65204-1-zhaogongyi@xxxxxxxxxxxxx/

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 | 294 +++++++++++++++++++++++++++++++++----------
fs/jbd2/journal.c | 22 +++-
fs/jbd2/recovery.c | 38 ++++--
include/linux/jbd2.h | 7 +-
6 files changed, 287 insertions(+), 86 deletions(-)

base-commit: 4aa05e642bade8cf8405936b03cabf848fe6c456