ext4: validate inode block references during fast commit replay
Subsystems (2)
PATCH 1/1 ext4: validate inode block references during fast commit replay
__ext4_iget() currently skips ext4_ext_check_inode() and ext4_ind_check_inode() when EXT4_FC_REPLAY is set in s_mount_state. As a result, an extent-mapped inode loaded from disk during fast commit replay never has its in-inode extent header or root extent entries validated before replay paths such as ext4_fc_replay_inode() and ext4_fc_replay_add_range() walk or modify i_data[].
A crafted filesystem image with a fast commit journal and an inode whose eh_max / eh_entries exceed the four-extent capacity of i_data[] triggers slab-out-of-bounds reads in ext4_cache_extents() and slab-out-of-bounds writes in ext4_ext_insert_extent() into adjacent fields of struct ext4_inode_info and beyond the ext4_inode_cache slab allocation.
ext4_ext_check_inode() and ext4_ind_check_inode() only validate the in-inode extent header and check block numbers against static superblock bounds via ext4_inode_block_valid(), not block allocation bitmaps. So, drop the EXT4_FC_REPLAY exemption in __ext4_iget() so inodes read during fast commit replay are validated.
--- fs/ext4/inode.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
fs/ext4/inode.c +3 -4
@@ -5582,10 +5582,9 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, goto bad_inode; }else if (!ext4_has_inline_data (inode)) {/* validate the block references in the inode */ -if (!(EXT4_SB (sb)->s_mount_state &EXT4_FC_REPLAY ) && - (S_ISREG (inode->i_mode) ||S_ISDIR (inode->i_mode) || - (S_ISLNK (inode->i_mode) && - !ext4_inode_is_fast_symlink (inode)))) { +if (S_ISREG (inode->i_mode) ||S_ISDIR (inode->i_mode) || + (S_ISLNK (inode->i_mode) && + !ext4_inode_is_fast_symlink (inode))) {if (ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS )) ret =ext4_ext_check_inode (inode);else
Signature · 1 line
2.56.0
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 19 lines
__ext4_iget()currently skipsext4_ext_check_inode()andext4_ind_check_inode()whenEXT4_FC_REPLAYis set ins_mount_state. As a result, an extent-mapped inode loaded from disk during fast commit replay never has its in-inode extent header or root extent entries validated before replay paths such asext4_fc_replay_inode()andext4_fc_replay_add_range()walk or modify i_data[].A crafted filesystem image with a fast commit journal and an inode whose
eh_max/eh_entriesexceed the four-extent capacity of i_data[] triggers slab-out-of-bounds reads inext4_cache_extents()and slab-out-of-bounds writes inext4_ext_insert_extent()into adjacent fields of structext4_inode_infoand beyond theext4_inode_cacheslab allocation.
ext4_ext_check_inode()andext4_ind_check_inode()only validate the in-inode extent header and check block numbers against static superblock bounds viaext4_inode_block_valid(), not block allocation bitmaps. So, drop theEXT4_FC_REPLAYexemption in__ext4_iget()so inodes read during fast commit replay are validated.
Quoted 4 lines
Reported-by Simon Brakhane <[email protected]>Fixes 8016e29f4362 ("ext4: fast commit recovery path")Signed-off-by Hamza Mahfooz <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 13 lines · Hamza Mahfooz
__ext4_iget()currently skipsext4_ext_check_inode()andext4_ind_check_inode()whenEXT4_FC_REPLAYis set ins_mount_state. As a result, an extent-mapped inode loaded from disk during fast commit replay never has its in-inode extent header or root extent entries validated before replay paths such asext4_fc_replay_inode()andext4_fc_replay_add_range()walk or modify i_data[].A crafted filesystem image with a fast commit journal and an inode whose
eh_max/eh_entriesexceed the four-extent capacity of i_data[] triggers slab-out-of-bounds reads inext4_cache_extents()and slab-out-of-bounds writes inext4_ext_insert_extent()into adjacent fields of structext4_inode_infoand beyond theext4_inode_cacheslab allocation.
Quoted 6 lines
ext4_ext_check_inode()andext4_ind_check_inode()only validate the in-inode extent header and check block numbers against static superblock bounds viaext4_inode_block_valid(), not block allocation bitmaps. So, drop theEXT4_FC_REPLAYexemption in__ext4_iget()so inodes read during fast commit replay are validated.
Ping?
Quoted 28 lines
Reported-by Simon Brakhane <[email protected]>Fixes 8016e29f4362 ("ext4: fast commit recovery path")Signed-off-by Hamza Mahfooz <[email protected]>--- fs/ext4/inode.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)fs/ext4/inode.c +3
-4@@ -5582,10 +5582,9 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, goto bad_inode; }else if (!ext4_has_inline_data (inode)) {/* validate the block references in the inode */ -if (!(EXT4_SB (sb)->s_mount_state &EXT4_FC_REPLAY ) && - (S_ISREG (inode->i_mode) ||S_ISDIR (inode->i_mode) || - (S_ISLNK (inode->i_mode) && - !ext4_inode_is_fast_symlink (inode)))) { +if (S_ISREG (inode->i_mode) ||S_ISDIR (inode->i_mode) || + (S_ISLNK (inode->i_mode) && + !ext4_inode_is_fast_symlink (inode))) {if (ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS )) ret =ext4_ext_check_inode (inode);else Signature · 1 line
2.56.0
Quoted 8 lines · Hamza Mahfooz
__ext4_iget()currently skipsext4_ext_check_inode()andext4_ind_check_inode()whenEXT4_FC_REPLAYis set ins_mount_state. As a result, an extent-mapped inode loaded from disk during fast commit replay never has its in-inode extent header or root extent entries validated before replay paths such asext4_fc_replay_inode()andext4_fc_replay_add_range()walk or modify i_data[].[...]
Applied, thanks!
[1/1] ext4: validate inode block references during fast commit replay
commit: 7b2eb8a438f6a29aeaf4322657248f21596e04e9
Best regards,
Signature · 1 line
Theodore Ts'o <[email protected]>