Skip to content

Commit b302ef2

Browse files
committed
ext4: verify group number in verify_group_input() before using it
Check the group number for sanity earilier, before calling routines such as ext4_bg_has_super() or ext4_group_overhead_blocks(). Reported-by: Jonathan Salwan <jonathan.salwan@gmail.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
1 parent a1d8d9a commit b302ef2

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

‎fs/ext4/resize.c‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,20 @@ static int verify_group_input(struct super_block *sb,
7979
ext4_fsblk_t end = start + input->blocks_count;
8080
ext4_group_t group = input->group;
8181
ext4_fsblk_t itend = input->inode_table + sbi->s_itb_per_group;
82-
unsigned overhead = ext4_group_overhead_blocks(sb, group);
83-
ext4_fsblk_t metaend = start + overhead;
82+
unsigned overhead;
83+
ext4_fsblk_t metaend;
8484
struct buffer_head *bh = NULL;
8585
ext4_grpblk_t free_blocks_count, offset;
8686
int err = -EINVAL;
8787

88+
if (group != sbi->s_groups_count) {
89+
ext4_warning(sb, "Cannot add at group %u (only %u groups)",
90+
input->group, sbi->s_groups_count);
91+
return -EINVAL;
92+
}
93+
94+
overhead = ext4_group_overhead_blocks(sb, group);
95+
metaend = start + overhead;
8896
input->free_blocks_count = free_blocks_count =
8997
input->blocks_count - 2 - overhead - sbi->s_itb_per_group;
9098

@@ -96,10 +104,7 @@ static int verify_group_input(struct super_block *sb,
96104
free_blocks_count, input->reserved_blocks);
97105

98106
ext4_get_group_no_and_offset(sb, start, NULL, &offset);
99-
if (group != sbi->s_groups_count)
100-
ext4_warning(sb, "Cannot add at group %u (only %u groups)",
101-
input->group, sbi->s_groups_count);
102-
else if (offset != 0)
107+
if (offset != 0)
103108
ext4_warning(sb, "Last group not full");
104109
else if (input->reserved_blocks > input->blocks_count / 5)
105110
ext4_warning(sb, "Reserved blocks too high (%u)",

0 commit comments

Comments
 (0)