]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
ext4: avoid arithemetic overflow that can trigger a BUG
authorTheodore Ts'o <tytso@mit.edu>
Sat, 1 Sep 2018 16:45:04 +0000 (12:45 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 1 Sep 2018 16:45:04 +0000 (12:45 -0400)
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
fs/ext4/ext4.h
fs/ext4/inode.c

index 249bcee4d7b238252269a921ed7df3c1cede7876..ac05bd86643a74ad6ae11e2d9ed78ef198cbe5ae 100644 (file)
@@ -686,6 +686,9 @@ enum {
 /* Max physical block we can address w/o extents */
 #define EXT4_MAX_BLOCK_FILE_PHYS       0xFFFFFFFF
 
+/* Max logical block we can support */
+#define EXT4_MAX_LOGICAL_BLOCK         0xFFFFFFFF
+
 /*
  * Structure of an inode on the disk
  */
index 8f6ad766797403dac536d0743557898caae8256b..694f3136420625fb5e3b31623035e6b6112fa75a 100644 (file)
@@ -3412,12 +3412,16 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
 {
        struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
        unsigned int blkbits = inode->i_blkbits;
-       unsigned long first_block = offset >> blkbits;
-       unsigned long last_block = (offset + length - 1) >> blkbits;
+       unsigned long first_block, last_block;
        struct ext4_map_blocks map;
        bool delalloc = false;
        int ret;
 
+       if ((offset >> blkbits) > EXT4_MAX_LOGICAL_BLOCK)
+               return -EINVAL;
+       first_block = offset >> blkbits;
+       last_block = min_t(loff_t, (offset + length - 1) >> blkbits,
+                          EXT4_MAX_LOGICAL_BLOCK);
 
        if (flags & IOMAP_REPORT) {
                if (ext4_has_inline_data(inode)) {