Skip to content

Commit b39430e

Browse files
tytsogregkh
authored andcommitted
ext4: add validity checks for bitmap block numbers
commit 7dac4a1 upstream. An privileged attacker can cause a crash by mounting a crafted ext4 image which triggers a out-of-bounds read in the function ext4_valid_block_bitmap() in fs/ext4/balloc.c. This issue has been assigned CVE-2018-1093. BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=199181 BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=1560782 Reported-by: Wen Xu <wen.xu@gatech.edu> Signed-off-by: Theodore Ts'o <tytso@mit.edu> Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 55cc3bb commit b39430e

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

‎fs/ext4/balloc.c‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,20 +338,25 @@ static ext4_fsblk_t ext4_valid_block_bitmap(struct super_block *sb,
338338
/* check whether block bitmap block number is set */
339339
blk = ext4_block_bitmap(sb, desc);
340340
offset = blk - group_first_block;
341-
if (!ext4_test_bit(EXT4_B2C(sbi, offset), bh->b_data))
341+
if (offset < 0 || EXT4_B2C(sbi, offset) >= sb->s_blocksize ||
342+
!ext4_test_bit(EXT4_B2C(sbi, offset), bh->b_data))
342343
/* bad block bitmap */
343344
return blk;
344345

345346
/* check whether the inode bitmap block number is set */
346347
blk = ext4_inode_bitmap(sb, desc);
347348
offset = blk - group_first_block;
348-
if (!ext4_test_bit(EXT4_B2C(sbi, offset), bh->b_data))
349+
if (offset < 0 || EXT4_B2C(sbi, offset) >= sb->s_blocksize ||
350+
!ext4_test_bit(EXT4_B2C(sbi, offset), bh->b_data))
349351
/* bad block bitmap */
350352
return blk;
351353

352354
/* check whether the inode table block number is set */
353355
blk = ext4_inode_table(sb, desc);
354356
offset = blk - group_first_block;
357+
if (offset < 0 || EXT4_B2C(sbi, offset) >= sb->s_blocksize ||
358+
EXT4_B2C(sbi, offset + sbi->s_itb_per_group) >= sb->s_blocksize)
359+
return blk;
355360
next_zero_bit = ext4_find_next_zero_bit(bh->b_data,
356361
EXT4_B2C(sbi, offset + EXT4_SB(sb)->s_itb_per_group),
357362
EXT4_B2C(sbi, offset));
@@ -417,6 +422,7 @@ struct buffer_head *
417422
ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group)
418423
{
419424
struct ext4_group_desc *desc;
425+
struct ext4_sb_info *sbi = EXT4_SB(sb);
420426
struct buffer_head *bh;
421427
ext4_fsblk_t bitmap_blk;
422428
int err;
@@ -425,6 +431,12 @@ ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group)
425431
if (!desc)
426432
return ERR_PTR(-EFSCORRUPTED);
427433
bitmap_blk = ext4_block_bitmap(sb, desc);
434+
if ((bitmap_blk <= le32_to_cpu(sbi->s_es->s_first_data_block)) ||
435+
(bitmap_blk >= ext4_blocks_count(sbi->s_es))) {
436+
ext4_error(sb, "Invalid block bitmap block %llu in "
437+
"block_group %u", bitmap_blk, block_group);
438+
return ERR_PTR(-EFSCORRUPTED);
439+
}
428440
bh = sb_getblk(sb, bitmap_blk);
429441
if (unlikely(!bh)) {
430442
ext4_error(sb, "Cannot get buffer for block bitmap - "

‎fs/ext4/ialloc.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ static struct buffer_head *
122122
ext4_read_inode_bitmap(struct super_block *sb, ext4_group_t block_group)
123123
{
124124
struct ext4_group_desc *desc;
125+
struct ext4_sb_info *sbi = EXT4_SB(sb);
125126
struct buffer_head *bh = NULL;
126127
ext4_fsblk_t bitmap_blk;
127128
int err;
@@ -131,6 +132,12 @@ ext4_read_inode_bitmap(struct super_block *sb, ext4_group_t block_group)
131132
return ERR_PTR(-EFSCORRUPTED);
132133

133134
bitmap_blk = ext4_inode_bitmap(sb, desc);
135+
if ((bitmap_blk <= le32_to_cpu(sbi->s_es->s_first_data_block)) ||
136+
(bitmap_blk >= ext4_blocks_count(sbi->s_es))) {
137+
ext4_error(sb, "Invalid inode bitmap blk %llu in "
138+
"block_group %u", bitmap_blk, block_group);
139+
return ERR_PTR(-EFSCORRUPTED);
140+
}
134141
bh = sb_getblk(sb, bitmap_blk);
135142
if (unlikely(!bh)) {
136143
ext4_error(sb, "Cannot read inode bitmap - "

0 commit comments

Comments
 (0)