From: Andreas Dilger Date: Fri, 7 Feb 2020 01:09:44 +0000 (-0700) Subject: e2fsck: fix overflow if more than 4B inodes X-Git-Tag: v1.45.6~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=102993ec1c841ef9392652db5a7a546f470a1004;p=thirdparty%2Fe2fsprogs.git e2fsck: fix overflow if more than 4B inodes Even though we don't have support for filesystems with over 4B inodes in the current e2fsprogs, this may happen in the future. There are latent overflow bugs when calculating the number of inodes in the filesystem that can trivially be fixed now, rather than waiting for them to be hit at some point in the future. The block number calcs are already correct in this code. Signed-off-by: Andreas Dilger Lustre-bug-id: https://jira.whamcloud.com/browse/LU-13197 Signed-off-by: Theodore Ts'o --- diff --git a/e2fsck/pass5.c b/e2fsck/pass5.c index 3a5c88dad..c1d45a5f1 100644 --- a/e2fsck/pass5.c +++ b/e2fsck/pass5.c @@ -842,7 +842,7 @@ static void check_inode_end(e2fsck_t ctx) clear_problem_context(&pctx); - end = EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count; + end = (__u64)EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count; pctx.errcode = ext2fs_fudge_inode_bitmap_end(fs->inode_map, end, &save_inodes_count); if (pctx.errcode) { diff --git a/lib/ext2fs/bitmaps.c b/lib/ext2fs/bitmaps.c index e25db2c66..834a3962a 100644 --- a/lib/ext2fs/bitmaps.c +++ b/lib/ext2fs/bitmaps.c @@ -62,7 +62,8 @@ errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs, start = 1; end = fs->super->s_inodes_count; - real_end = (EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count); + real_end = (__u64)EXT2_INODES_PER_GROUP(fs->super) * + fs->group_desc_count; /* Are we permitted to use new-style bitmaps? */ if (fs->flags & EXT2_FLAG_64BITS) diff --git a/lib/ext2fs/imager.c b/lib/ext2fs/imager.c index ed0989adb..b3ede9a86 100644 --- a/lib/ext2fs/imager.c +++ b/lib/ext2fs/imager.c @@ -347,7 +347,8 @@ errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags) } bmap = fs->inode_map; itr = 1; - cnt = EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count; + cnt = (__u64)EXT2_INODES_PER_GROUP(fs->super) * + fs->group_desc_count; size = (EXT2_INODES_PER_GROUP(fs->super) / 8); } else { if (!fs->block_map) { @@ -422,7 +423,8 @@ errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags) } bmap = fs->inode_map; itr = 1; - cnt = EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count; + cnt = (__u64)EXT2_INODES_PER_GROUP(fs->super) * + fs->group_desc_count; size = (EXT2_INODES_PER_GROUP(fs->super) / 8); } else { if (!fs->block_map) { diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c index 68ddddd3b..f906ca8f1 100644 --- a/misc/fuse2fs.c +++ b/misc/fuse2fs.c @@ -2357,7 +2357,7 @@ static int op_statfs(const char *path EXT2FS_ATTR((unused)), overhead = 0; else overhead = fs->desc_blocks + - fs->group_desc_count * + (blk64_t)fs->group_desc_count * (fs->inode_blocks_per_group + 2); reserved = ext2fs_r_blocks_count(fs->super); if (!reserved)