Skip to content

Commit 32c2d2b

Browse files
Eric SandeenLinus Torvalds
authored andcommitted
[PATCH] more ext3 16T overflow fixes
Some of the changes in balloc.c are just cosmetic, as Andreas pointed out - if they overflow they'll then underflow and things are fine. 5th hunk actually fixes an overflow problem. Also check for potential overflows in inode & block counts when resizing. Signed-off-by: Eric Sandeen <esandeen@redhat.com> Cc: Mingming Cao <cmm@us.ibm.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent a4e4de3 commit 32c2d2b

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

‎fs/ext3/balloc.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ goal_in_my_reservation(struct ext3_reserve_window *rsv, ext3_grpblk_t grp_goal,
202202
ext3_fsblk_t group_first_block, group_last_block;
203203

204204
group_first_block = ext3_group_first_block_no(sb, group);
205-
group_last_block = group_first_block + EXT3_BLOCKS_PER_GROUP(sb) - 1;
205+
group_last_block = group_first_block + (EXT3_BLOCKS_PER_GROUP(sb) - 1);
206206

207207
if ((rsv->_rsv_start > group_last_block) ||
208208
(rsv->_rsv_end < group_first_block))
@@ -1047,7 +1047,7 @@ static int alloc_new_reservation(struct ext3_reserve_window_node *my_rsv,
10471047
spinlock_t *rsv_lock = &EXT3_SB(sb)->s_rsv_window_lock;
10481048

10491049
group_first_block = ext3_group_first_block_no(sb, group);
1050-
group_end_block = group_first_block + EXT3_BLOCKS_PER_GROUP(sb) - 1;
1050+
group_end_block = group_first_block + (EXT3_BLOCKS_PER_GROUP(sb) - 1);
10511051

10521052
if (grp_goal < 0)
10531053
start_block = group_first_block;
@@ -1239,7 +1239,7 @@ ext3_try_to_allocate_with_rsv(struct super_block *sb, handle_t *handle,
12391239
struct ext3_reserve_window_node * my_rsv,
12401240
unsigned long *count, int *errp)
12411241
{
1242-
ext3_fsblk_t group_first_block;
1242+
ext3_fsblk_t group_first_block, group_last_block;
12431243
ext3_grpblk_t ret = 0;
12441244
int fatal;
12451245
unsigned long num = *count;
@@ -1276,6 +1276,7 @@ ext3_try_to_allocate_with_rsv(struct super_block *sb, handle_t *handle,
12761276
* first block is the block number of the first block in this group
12771277
*/
12781278
group_first_block = ext3_group_first_block_no(sb, group);
1279+
group_last_block = group_first_block + (EXT3_BLOCKS_PER_GROUP(sb) - 1);
12791280

12801281
/*
12811282
* Basically we will allocate a new block from inode's reservation
@@ -1311,9 +1312,8 @@ ext3_try_to_allocate_with_rsv(struct super_block *sb, handle_t *handle,
13111312
try_to_extend_reservation(my_rsv, sb,
13121313
*count-my_rsv->rsv_end + grp_goal - 1);
13131314

1314-
if ((my_rsv->rsv_start >= group_first_block +
1315-
EXT3_BLOCKS_PER_GROUP(sb))
1316-
|| (my_rsv->rsv_end < group_first_block)) {
1315+
if ((my_rsv->rsv_start > group_last_block) ||
1316+
(my_rsv->rsv_end < group_first_block)) {
13171317
rsv_window_dump(&EXT3_SB(sb)->s_rsv_window_root, 1);
13181318
BUG();
13191319
}

‎fs/ext3/resize.c‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,18 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input)
731731
return -EPERM;
732732
}
733733

734+
if (le32_to_cpu(es->s_blocks_count) + input->blocks_count <
735+
le32_to_cpu(es->s_blocks_count)) {
736+
ext3_warning(sb, __FUNCTION__, "blocks_count overflow\n");
737+
return -EINVAL;
738+
}
739+
740+
if (le32_to_cpu(es->s_inodes_count) + EXT3_INODES_PER_GROUP(sb) <
741+
le32_to_cpu(es->s_inodes_count)) {
742+
ext3_warning(sb, __FUNCTION__, "inodes_count overflow\n");
743+
return -EINVAL;
744+
}
745+
734746
if (reserved_gdb || gdb_off == 0) {
735747
if (!EXT3_HAS_COMPAT_FEATURE(sb,
736748
EXT3_FEATURE_COMPAT_RESIZE_INODE)){
@@ -959,6 +971,11 @@ int ext3_group_extend(struct super_block *sb, struct ext3_super_block *es,
959971

960972
add = EXT3_BLOCKS_PER_GROUP(sb) - last;
961973

974+
if (o_blocks_count + add < o_blocks_count) {
975+
ext3_warning(sb, __FUNCTION__, "blocks_count overflow");
976+
return -EINVAL;
977+
}
978+
962979
if (o_blocks_count + add > n_blocks_count)
963980
add = n_blocks_count - o_blocks_count;
964981

0 commit comments

Comments
 (0)