[PATCH v3] ext4: validate extent root during fast commit replay
From: Jérémy Jean
Date: Mon Nov 09 2026 - 17:12:44 EST
Fast commit replay skips extent tree validation in ext4_iget(). The
replay code then reads and updates the extent root stored in i_data
without validating its header.
The root has space for four extents. A corrupt header with eh_entries
set to 4 and eh_max set to 5 lets replay insert a fifth extent past
the end of i_data, which overwrites other fields in struct
ext4_inode_info.
Check the root in ext4_find_extent() during fast commit replay. Skip
extent replay helpers for non-extent inodes and clear the replay state
before loading the root inode.
Fixes: 8016e29f4362 ("ext4: fast commit recovery path")
Cc: stable@xxxxxxxxxx
Signed-off-by: Jérémy Jean <Jeremy.Jean@xxxxxxxxxxxxxxxxx>
---
Changes in v3:
- Skip extent replay helpers for non-extent inodes.
- Clear EXT4_FC_REPLAY before loading the root inode.
Changes in v2:
- Validate replay roots regardless of EXT4_INODE_EXTENTS.
- Rebase on fa4ad798f6f6.
v2: https://lore.kernel.org/all/20261108201906.1417129-2-Jeremy.Jean@xxxxxxxxxxxxxxxxx/
v1: https://lore.kernel.org/all/20260821100559.3612643-2-Jeremy.Jean@xxxxxxxxxxxxxxxxx/
fs/ext4/extents.c | 8 +++++++-
fs/ext4/fast_commit.c | 4 ++--
fs/ext4/super.c | 3 +--
3 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index ad0d80e33f609..aec75a680bcc7 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -905,6 +905,12 @@ ext4_find_extent(struct inode *inode, ext4_lblk_t block,
ret = -EFSCORRUPTED;
goto err;
}
+ /* ext4_iget() skips extent validation during fast commit replay. */
+ if (unlikely(EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY)) {
+ ret = ext4_ext_check(inode, eh, depth, 0);
+ if (ret)
+ goto err;
+ }
if (path) {
ext4_ext_drop_refs(path);
@@ -6391,7 +6397,7 @@ int ext4_ext_clear_bb(struct inode *inode)
int j, ret = 0;
struct ext4_map_blocks map;
- if (ext4_test_inode_flag(inode, EXT4_INODE_INLINE_DATA))
+ if (!ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
return 0;
/* Determin the size of the file first */
diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c
index 0cac890cf3702..b883ce015c303 100644
--- a/fs/ext4/fast_commit.c
+++ b/fs/ext4/fast_commit.c
@@ -2002,7 +2002,7 @@ static int ext4_fc_replay_inode(struct super_block *sb,
* crashing. This should be fixed but until then, we calculate
* the number of blocks the inode.
*/
- if (!ext4_test_inode_flag(inode, EXT4_INODE_INLINE_DATA))
+ if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
ext4_ext_replay_set_iblocks(inode);
inode->i_generation = le32_to_cpu(ext4_raw_inode(&iloc)->i_generation);
@@ -2334,7 +2334,7 @@ static void ext4_fc_set_bitmaps_and_counters(struct super_block *sb)
}
cur = 0;
end = EXT_MAX_BLOCKS;
- if (ext4_test_inode_flag(inode, EXT4_INODE_INLINE_DATA)) {
+ if (!ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) {
iput(inode);
continue;
}
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 9cae52471dee9..8dac2c1cea78a 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -5660,6 +5660,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
* The jbd2_journal_load will have done any necessary log recovery,
* so we can safely mount the rest of the filesystem now.
*/
+ ext4_fc_replay_cleanup(sb);
root = ext4_iget(sb, EXT4_ROOT_INO, EXT4_IGET_SPECIAL);
if (IS_ERR(root)) {
@@ -5699,8 +5700,6 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
goto failed_mount4a;
}
}
- ext4_fc_replay_cleanup(sb);
-
ext4_ext_init(sb);
/*
--
2.47.3