Skip to content

Commit 658a523

Browse files
LiBaokun96tytso
authored andcommitted
ext4: unify the type of flexbg_size to unsigned int
The maximum value of flexbg_size is 2^31, but the maximum value of int is (2^31 - 1), so overflow may occur when the type of flexbg_size is declared as int. For example, when uninit_mask is initialized in ext4_alloc_group_tables(), if flexbg_size == 2^31, the initialized uninit_mask is incorrect, and this may causes set_flexbg_block_bitmap() to trigger a BUG_ON(). Therefore, the flexbg_size type is declared as unsigned int to avoid overflow and memory waste. Signed-off-by: Baokun Li <[email protected]> Reviewed-by: Jan Kara <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 6c02757 commit 658a523

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

fs/ext4/resize.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ struct ext4_new_flex_group_data {
228228
*
229229
* Returns NULL on failure otherwise address of the allocated structure.
230230
*/
231-
static struct ext4_new_flex_group_data *alloc_flex_gd(unsigned long flexbg_size)
231+
static struct ext4_new_flex_group_data *alloc_flex_gd(unsigned int flexbg_size)
232232
{
233233
struct ext4_new_flex_group_data *flex_gd;
234234

@@ -283,7 +283,7 @@ static void free_flex_gd(struct ext4_new_flex_group_data *flex_gd)
283283
*/
284284
static int ext4_alloc_group_tables(struct super_block *sb,
285285
struct ext4_new_flex_group_data *flex_gd,
286-
int flexbg_size)
286+
unsigned int flexbg_size)
287287
{
288288
struct ext4_new_group_data *group_data = flex_gd->groups;
289289
ext4_fsblk_t start_blk;
@@ -384,12 +384,12 @@ static int ext4_alloc_group_tables(struct super_block *sb,
384384
group = group_data[0].group;
385385

386386
printk(KERN_DEBUG "EXT4-fs: adding a flex group with "
387-
"%d groups, flexbg size is %d:\n", flex_gd->count,
387+
"%u groups, flexbg size is %u:\n", flex_gd->count,
388388
flexbg_size);
389389

390390
for (i = 0; i < flex_gd->count; i++) {
391391
ext4_debug(
392-
"adding %s group %u: %u blocks (%d free, %d mdata blocks)\n",
392+
"adding %s group %u: %u blocks (%u free, %u mdata blocks)\n",
393393
ext4_bg_has_super(sb, group + i) ? "normal" :
394394
"no-super", group + i,
395395
group_data[i].blocks_count,
@@ -1606,7 +1606,7 @@ static int ext4_flex_group_add(struct super_block *sb,
16061606
static int ext4_setup_next_flex_gd(struct super_block *sb,
16071607
struct ext4_new_flex_group_data *flex_gd,
16081608
ext4_fsblk_t n_blocks_count,
1609-
unsigned long flexbg_size)
1609+
unsigned int flexbg_size)
16101610
{
16111611
struct ext4_sb_info *sbi = EXT4_SB(sb);
16121612
struct ext4_super_block *es = sbi->s_es;
@@ -1990,8 +1990,9 @@ int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count)
19901990
ext4_fsblk_t o_blocks_count;
19911991
ext4_fsblk_t n_blocks_count_retry = 0;
19921992
unsigned long last_update_time = 0;
1993-
int err = 0, flexbg_size = 1 << sbi->s_log_groups_per_flex;
1993+
int err = 0;
19941994
int meta_bg;
1995+
unsigned int flexbg_size = ext4_flex_bg_size(sbi);
19951996

19961997
/* See if the device is actually as big as what was requested */
19971998
bh = ext4_sb_bread(sb, n_blocks_count - 1, 0);

0 commit comments

Comments
 (0)