Commit 967ac8af4475ce45474800709b12137aa7634c77

Authored by Haogang Chen
Committed by Theodore Ts'o
1 parent 9d99012ff2

ext4: fix potential integer overflow in alloc_flex_gd()

In alloc_flex_gd(), when flexbg_size is large, kmalloc size would
overflow and flex_gd->groups would point to a buffer smaller than
expected, causing OOB accesses when it is used.

Note that in ext4_resize_fs(), flexbg_size is calculated using
sbi->s_log_groups_per_flex, which is read from the disk and only bounded
to [1, 31]. The patch returns NULL for too large flexbg_size.

Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Haogang Chen <haogangchen@gmail.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Cc: stable@kernel.org

Showing 1 changed file with 2 additions and 0 deletions Side-by-side Diff

... ... @@ -161,6 +161,8 @@
161 161 if (flex_gd == NULL)
162 162 goto out3;
163 163  
  164 + if (flexbg_size >= UINT_MAX / sizeof(struct ext4_new_flex_group_data))
  165 + goto out2;
164 166 flex_gd->count = flexbg_size;
165 167  
166 168 flex_gd->groups = kmalloc(sizeof(struct ext4_new_group_data) *