diff options
author | Theodore Ts'o <tytso@mit.edu> | 2018-09-01 12:45:04 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2018-09-01 12:45:04 -0400 |
commit | bcd8e91f98c156f4b1ebcfacae675f9cfd962441 (patch) | |
tree | d6a8e8a1d4596f0c559efa1dc4d404d1260dc6a1 /fs/ext4 | |
parent | 4d982e25d0bdc83d8c64e66fdeca0b89240b3b85 (diff) |
ext4: avoid arithemetic overflow that can trigger a BUG
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
Diffstat (limited to 'fs/ext4')
-rw-r--r-- | fs/ext4/ext4.h | 3 | ||||
-rw-r--r-- | fs/ext4/inode.c | 8 |
2 files changed, 9 insertions, 2 deletions
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 249bcee4d7b2..ac05bd86643a 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h | |||
@@ -686,6 +686,9 @@ enum { | |||
686 | /* Max physical block we can address w/o extents */ | 686 | /* Max physical block we can address w/o extents */ |
687 | #define EXT4_MAX_BLOCK_FILE_PHYS 0xFFFFFFFF | 687 | #define EXT4_MAX_BLOCK_FILE_PHYS 0xFFFFFFFF |
688 | 688 | ||
689 | /* Max logical block we can support */ | ||
690 | #define EXT4_MAX_LOGICAL_BLOCK 0xFFFFFFFF | ||
691 | |||
689 | /* | 692 | /* |
690 | * Structure of an inode on the disk | 693 | * Structure of an inode on the disk |
691 | */ | 694 | */ |
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 8f6ad7667974..694f31364206 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
@@ -3412,12 +3412,16 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length, | |||
3412 | { | 3412 | { |
3413 | struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); | 3413 | struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); |
3414 | unsigned int blkbits = inode->i_blkbits; | 3414 | unsigned int blkbits = inode->i_blkbits; |
3415 | unsigned long first_block = offset >> blkbits; | 3415 | unsigned long first_block, last_block; |
3416 | unsigned long last_block = (offset + length - 1) >> blkbits; | ||
3417 | struct ext4_map_blocks map; | 3416 | struct ext4_map_blocks map; |
3418 | bool delalloc = false; | 3417 | bool delalloc = false; |
3419 | int ret; | 3418 | int ret; |
3420 | 3419 | ||
3420 | if ((offset >> blkbits) > EXT4_MAX_LOGICAL_BLOCK) | ||
3421 | return -EINVAL; | ||
3422 | first_block = offset >> blkbits; | ||
3423 | last_block = min_t(loff_t, (offset + length - 1) >> blkbits, | ||
3424 | EXT4_MAX_LOGICAL_BLOCK); | ||
3421 | 3425 | ||
3422 | if (flags & IOMAP_REPORT) { | 3426 | if (flags & IOMAP_REPORT) { |
3423 | if (ext4_has_inline_data(inode)) { | 3427 | if (ext4_has_inline_data(inode)) { |