From: Jan Kara Date: Mon, 22 Aug 2022 11:48:32 +0000 (+0200) Subject: ext4: fix check for block being out of directory size X-Git-Tag: v6.0.3~714 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9a62667d1640890a96e31dc71d4011f4f28f912f;p=thirdparty%2Fkernel%2Fstable.git ext4: fix check for block being out of directory size commit 61a1d87a324ad5e3ed27c6699dfc93218fcf3201 upstream. The check in __ext4_read_dirblock() for block being outside of directory size was wrong because it compared block number against directory size in bytes. Fix it. Fixes: 65f8ea4cd57d ("ext4: check if directory block is within i_size") CVE: CVE-2022-1184 CC: stable@vger.kernel.org Signed-off-by: Jan Kara Reviewed-by: Lukas Czerner Link: https://lore.kernel.org/r/20220822114832.1482-1-jack@suse.cz Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 3a31b662f6619..bc2e0612ec32a 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -126,7 +126,7 @@ static struct buffer_head *__ext4_read_dirblock(struct inode *inode, struct ext4_dir_entry *dirent; int is_dx_block = 0; - if (block >= inode->i_size) { + if (block >= inode->i_size >> inode->i_blkbits) { ext4_error_inode(inode, func, line, block, "Attempting to read directory block (%u) that is past i_size (%llu)", block, inode->i_size);