dx_countlimit's count field was read from disk and used directly to compute the checksummed range (count_offset + count * sizeof(dx_entry)) without ever being checked against limit -- only limit itself was bounds-checked against the block size. A corrupted or maliciously crafted filesystem image that sets count to a large value (e.g. 65535) makes ext4_chksum() read far past the end of the directory block buffer, hitting adjacent slab objects. Reported-by: xiaowu.417@qq.com Signed-off-by: Artem Blagodarenko Assisted-by: Claude:claude-opus-5-5 --- fs/ext4/namei.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index b2753daad49f..1d3b71cd51d6 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -395,6 +395,11 @@ static int ext4_dx_csum_verify(struct inode *inode, warn_no_space_for_csum(inode); return 0; } + if (count > limit) { + EXT4_ERROR_INODE(inode, "dir seems corrupt (%i > %i)? " + "Run e2fsck -D.", count, limit); + return 0; + } t = (struct dx_tail *)(((struct dx_entry *)c) + limit); if (t->dt_checksum != ext4_dx_csum(inode, dirent, count_offset, @@ -424,6 +429,11 @@ static void ext4_dx_csum_set(struct inode *inode, struct ext4_dir_entry *dirent) warn_no_space_for_csum(inode); return; } + if (count > limit) { + EXT4_ERROR_INODE(inode, "dir seems corrupt (%i > %i)? " + "Run e2fsck -D.", count, limit); + return; + } t = (struct dx_tail *)(((struct dx_entry *)c) + limit); t->dt_checksum = ext4_dx_csum(inode, dirent, count_offset, count, t); -- 2.52.0