resize2fs: fix 32bit overflow during minimal size calculation for 64bit fs.
PATCH 1/1 resize2fs: fix 32bit overflow during minimal size calculation for 64bit fs.
calculate_minimum_resize_size() multiplying two 32bit numbers, however the result must be 64bit, but it will be truncated to 32bit, and because of this data_blocks will be zero, and it will never leave loop:
blocks_per_group=32768 (u32)
extra_groups=131072 (u32)
data_blocks=4294967296 # overflow
And here is messages from log with resize2fs -f 255:
fs has 4007207 inodes, 1957 groups required.
fs requires 4374122900 data blocks.
With 1957 group(s), we have 63820826 blocks available.
Added 131540 extra group(s), blks_needed 4374122900, data_blocks·62023030, last_start 4356599580 Added 131595 extra group(s), blks_needed 4374122900, data_blocks·73483100, last_start 5781212288 Added 131246 extra group(s), blks_needed 4374122900, data_blocks·79184732, last_start 5781244926 Added 131072 extra group(s), blks_needed 4374122900, data_blocks·79184732, last_start 5781277564 Added 131072 extra group(s), blks_needed 4374122900, data_blocks·79184732, last_start 5781310202
...
--- resize/resize2fs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
resize/resize2fs.c +2 -1
@@ -2479,7 +2479,8 @@ blk64_t calculate_minimum_resize_size(ext2_filsys fs, int flags) extra_grps =ext2fs_div64_ceil (remainder,EXT2_BLOCKS_PER_GROUP (fs->super)); - data_blocks += extra_grps *EXT2_BLOCKS_PER_GROUP (fs->super); + data_blocks += (unsigned long long )extra_grps * +EXT2_BLOCKS_PER_GROUP (fs->super);/* ok we have to account for the last group */ overhead =calc_group_overhead (fs, groups-1 , old_desc_blocks);
Signature · 6 lines
2.0.1 -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 3 lines · Azat Khuzhin
calculate_minimum_resize_size()multiplying two 32bit numbers, however the result must be 64bit, but it will be truncated to 32bit, and because of thisdata_blockswill be zero, and it will never leave loop...
There is a much more general patch which solves a number of other instances where this bug exists which I've already committed into my tree:
Cheers,
- Ted
Quoted 10 lines · Theodore Ts'o
Quoted 3 lines · Azat Khuzhin
calculate_minimum_resize_size()multiplying two 32bit numbers, however the result must be 64bit, but it will be truncated to 32bit, and because of thisdata_blockswill be zero, and it will never leave loop...There is a much more general patch which solves a number of other instances where this bug exists which I've already committed into my tree:
Yeah, I didn't thought about fixing *all* places of this bug. Thanks,
Azat.