ext2: Verify bitmap and itable block numbers before using them
commit 322a6aff03937aa1ece33b4e46c298eafaf9ac41 upstream. Verify bitmap block numbers and inode table blocks are sane before using them for checking bits in the block bitmap. CC: stable@vger.kernel.org Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
8ce994880f
commit
b63bddf2e8
1 changed files with 9 additions and 2 deletions
|
@ -79,26 +79,33 @@ static int ext2_valid_block_bitmap(struct super_block *sb,
|
||||||
ext2_grpblk_t next_zero_bit;
|
ext2_grpblk_t next_zero_bit;
|
||||||
ext2_fsblk_t bitmap_blk;
|
ext2_fsblk_t bitmap_blk;
|
||||||
ext2_fsblk_t group_first_block;
|
ext2_fsblk_t group_first_block;
|
||||||
|
ext2_grpblk_t max_bit;
|
||||||
|
|
||||||
group_first_block = ext2_group_first_block_no(sb, block_group);
|
group_first_block = ext2_group_first_block_no(sb, block_group);
|
||||||
|
max_bit = ext2_group_last_block_no(sb, block_group) - group_first_block;
|
||||||
|
|
||||||
/* check whether block bitmap block number is set */
|
/* check whether block bitmap block number is set */
|
||||||
bitmap_blk = le32_to_cpu(desc->bg_block_bitmap);
|
bitmap_blk = le32_to_cpu(desc->bg_block_bitmap);
|
||||||
offset = bitmap_blk - group_first_block;
|
offset = bitmap_blk - group_first_block;
|
||||||
if (!ext2_test_bit(offset, bh->b_data))
|
if (offset < 0 || offset > max_bit ||
|
||||||
|
!ext2_test_bit(offset, bh->b_data))
|
||||||
/* bad block bitmap */
|
/* bad block bitmap */
|
||||||
goto err_out;
|
goto err_out;
|
||||||
|
|
||||||
/* check whether the inode bitmap block number is set */
|
/* check whether the inode bitmap block number is set */
|
||||||
bitmap_blk = le32_to_cpu(desc->bg_inode_bitmap);
|
bitmap_blk = le32_to_cpu(desc->bg_inode_bitmap);
|
||||||
offset = bitmap_blk - group_first_block;
|
offset = bitmap_blk - group_first_block;
|
||||||
if (!ext2_test_bit(offset, bh->b_data))
|
if (offset < 0 || offset > max_bit ||
|
||||||
|
!ext2_test_bit(offset, bh->b_data))
|
||||||
/* bad block bitmap */
|
/* bad block bitmap */
|
||||||
goto err_out;
|
goto err_out;
|
||||||
|
|
||||||
/* check whether the inode table block number is set */
|
/* check whether the inode table block number is set */
|
||||||
bitmap_blk = le32_to_cpu(desc->bg_inode_table);
|
bitmap_blk = le32_to_cpu(desc->bg_inode_table);
|
||||||
offset = bitmap_blk - group_first_block;
|
offset = bitmap_blk - group_first_block;
|
||||||
|
if (offset < 0 || offset > max_bit ||
|
||||||
|
offset + EXT2_SB(sb)->s_itb_per_group - 1 > max_bit)
|
||||||
|
goto err_out;
|
||||||
next_zero_bit = ext2_find_next_zero_bit(bh->b_data,
|
next_zero_bit = ext2_find_next_zero_bit(bh->b_data,
|
||||||
offset + EXT2_SB(sb)->s_itb_per_group,
|
offset + EXT2_SB(sb)->s_itb_per_group,
|
||||||
offset);
|
offset);
|
||||||
|
|
Loading…
Reference in a new issue