Skip to content

Commit 779af00

Browse files
tytsogregkh
authored andcommitted
ext4: avoid arithemetic overflow that can trigger a BUG
commit bcd8e91 upstream. A maliciously crafted file system can cause an overflow when the results of a 64-bit calculation is stored into a 32-bit length parameter. https://bugzilla.kernel.org/show_bug.cgi?id=200623 Signed-off-by: Theodore Ts'o <tytso@mit.edu> Reported-by: Wen Xu <wen.xu@gatech.edu> Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 3f9eafe commit 779af00

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

fs/ext4/ext4.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,9 @@ struct fsxattr {
714714
/* Max physical block we can address w/o extents */
715715
#define EXT4_MAX_BLOCK_FILE_PHYS 0xFFFFFFFF
716716

717+
/* Max logical block we can support */
718+
#define EXT4_MAX_LOGICAL_BLOCK 0xFFFFFFFF
719+
717720
/*
718721
* Structure of an inode on the disk
719722
*/

fs/ext4/inode.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3407,11 +3407,16 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
34073407
{
34083408
struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
34093409
unsigned int blkbits = inode->i_blkbits;
3410-
unsigned long first_block = offset >> blkbits;
3411-
unsigned long last_block = (offset + length - 1) >> blkbits;
3410+
unsigned long first_block, last_block;
34123411
struct ext4_map_blocks map;
34133412
int ret;
34143413

3414+
if ((offset >> blkbits) > EXT4_MAX_LOGICAL_BLOCK)
3415+
return -EINVAL;
3416+
first_block = offset >> blkbits;
3417+
last_block = min_t(loff_t, (offset + length - 1) >> blkbits,
3418+
EXT4_MAX_LOGICAL_BLOCK);
3419+
34153420
if (WARN_ON_ONCE(ext4_has_inline_data(inode)))
34163421
return -ERANGE;
34173422

0 commit comments

Comments
 (0)