From c5b7b6babe658a2037af6c9d2b7a3c23208f98f1 Mon Sep 17 00:00:00 2001 From: Valerie Aurora Henson Date: Mon, 7 Sep 2009 21:23:03 -0400 Subject: [PATCH] Fix overflow in calculation of total file system blocks Blocks per group and group desc count are both 32-bit; multiplied they produce a 32-bit quantity which overflowed. Signed-off-by: Valerie Aurora Henson Signed-off-by: Eric Sandeen Signed-off-by: "Theodore Ts'o" --- e2fsck/pass5.c | 2 +- lib/ext2fs/bitmaps.c | 4 ++-- lib/ext2fs/rw_bitmaps.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/e2fsck/pass5.c b/e2fsck/pass5.c index a2a00b1..c27989a 100644 --- a/e2fsck/pass5.c +++ b/e2fsck/pass5.c @@ -662,7 +662,7 @@ static void check_block_end(e2fsck_t ctx) clear_problem_context(&pctx); end = ext2fs_get_block_bitmap_start2(fs->block_map) + - (EXT2_BLOCKS_PER_GROUP(fs->super) * fs->group_desc_count) - 1; + ((blk64_t)EXT2_BLOCKS_PER_GROUP(fs->super) * fs->group_desc_count) - 1; pctx.errcode = ext2fs_fudge_block_bitmap_end2(fs->block_map, end, &save_blocks_count); if (pctx.errcode) { diff --git a/lib/ext2fs/bitmaps.c b/lib/ext2fs/bitmaps.c index 8dc8465..91a8c96 100644 --- a/lib/ext2fs/bitmaps.c +++ b/lib/ext2fs/bitmaps.c @@ -92,8 +92,8 @@ errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs, start = fs->super->s_first_data_block; end = ext2fs_blocks_count(fs->super)-1; - real_end = (EXT2_BLOCKS_PER_GROUP(fs->super) - * fs->group_desc_count)-1 + start; + real_end = ((__u64) EXT2_BLOCKS_PER_GROUP(fs->super) + * (__u64) fs->group_desc_count)-1 + start; if (fs->flags & EXT2_FLAG_64BITS) return (ext2fs_alloc_generic_bmap(fs, diff --git a/lib/ext2fs/rw_bitmaps.c b/lib/ext2fs/rw_bitmaps.c index 08d3a5e..a100618 100644 --- a/lib/ext2fs/rw_bitmaps.c +++ b/lib/ext2fs/rw_bitmaps.c @@ -212,7 +212,7 @@ static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block) } blk = (fs->image_header->offset_blockmap / fs->blocksize); - blk_cnt = EXT2_BLOCKS_PER_GROUP(fs->super) * + blk_cnt = (blk64_t)EXT2_BLOCKS_PER_GROUP(fs->super) * fs->group_desc_count; while (block_nbytes > 0) { retval = io_channel_read_blk64(fs->image_io, blk++, -- 1.8.3.1