From: Theodore Ts'o Date: Sun, 23 Jul 2017 04:26:44 +0000 (-0400) Subject: libext2fs: add stricter checks on the inode size in ext2fs_open2() X-Git-Tag: v1.43.5~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bf445b4e68a053d0b5eaf8da0f61a4c9d13fb5a8;p=thirdparty%2Fe2fsprogs.git libext2fs: add stricter checks on the inode size in ext2fs_open2() An inode size larger than the block size can cause userspace programs to crash. This problem was found using American Fuzzy Lop. Reported-by: Adam Buchbinder Signed-off-by: Theodore Ts'o --- diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c index 0362b2839..da03bc147 100644 --- a/lib/ext2fs/openfs.c +++ b/lib/ext2fs/openfs.c @@ -121,6 +121,7 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, blk64_t group_block, blk; char *dest, *cp; int group_zero_adjust = 0; + int inode_size; #ifdef WORDS_BIGENDIAN unsigned int groups_per_block; struct ext2_group_desc *gdp; @@ -297,7 +298,10 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, goto cleanup; } fs->fragsize = fs->blocksize = EXT2_BLOCK_SIZE(fs->super); - if (EXT2_INODE_SIZE(fs->super) < EXT2_GOOD_OLD_INODE_SIZE) { + inode_size = EXT2_INODE_SIZE(fs->super); + if ((inode_size < EXT2_GOOD_OLD_INODE_SIZE) || + (inode_size > fs->blocksize) || + (inode_size & (inode_size - 1))) { retval = EXT2_ET_CORRUPT_SUPERBLOCK; goto cleanup; }