Skip to content

Commit 322a6af

Browse files
committed
ext2: Verify bitmap and itable block numbers before using them
Verify bitmap block numbers and inode table blocks are sane before using them for checking bits in the block bitmap. CC: [email protected] Signed-off-by: Jan Kara <[email protected]>
1 parent 56e69e5 commit 322a6af

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

fs/ext2/balloc.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,26 +77,33 @@ static int ext2_valid_block_bitmap(struct super_block *sb,
7777
ext2_grpblk_t next_zero_bit;
7878
ext2_fsblk_t bitmap_blk;
7979
ext2_fsblk_t group_first_block;
80+
ext2_grpblk_t max_bit;
8081

8182
group_first_block = ext2_group_first_block_no(sb, block_group);
83+
max_bit = ext2_group_last_block_no(sb, block_group) - group_first_block;
8284

8385
/* check whether block bitmap block number is set */
8486
bitmap_blk = le32_to_cpu(desc->bg_block_bitmap);
8587
offset = bitmap_blk - group_first_block;
86-
if (!ext2_test_bit(offset, bh->b_data))
88+
if (offset < 0 || offset > max_bit ||
89+
!ext2_test_bit(offset, bh->b_data))
8790
/* bad block bitmap */
8891
goto err_out;
8992

9093
/* check whether the inode bitmap block number is set */
9194
bitmap_blk = le32_to_cpu(desc->bg_inode_bitmap);
9295
offset = bitmap_blk - group_first_block;
93-
if (!ext2_test_bit(offset, bh->b_data))
96+
if (offset < 0 || offset > max_bit ||
97+
!ext2_test_bit(offset, bh->b_data))
9498
/* bad block bitmap */
9599
goto err_out;
96100

97101
/* check whether the inode table block number is set */
98102
bitmap_blk = le32_to_cpu(desc->bg_inode_table);
99103
offset = bitmap_blk - group_first_block;
104+
if (offset < 0 || offset > max_bit ||
105+
offset + EXT2_SB(sb)->s_itb_per_group - 1 > max_bit)
106+
goto err_out;
100107
next_zero_bit = ext2_find_next_zero_bit(bh->b_data,
101108
offset + EXT2_SB(sb)->s_itb_per_group,
102109
offset);

0 commit comments

Comments
 (0)