summaryrefslogtreecommitdiffstats
path: root/fs/ext4/inode.c
diff options
context:
space:
mode:
authorTheodore Ts'o2018-09-01 18:45:04 +0200
committerTheodore Ts'o2018-09-01 18:45:04 +0200
commitbcd8e91f98c156f4b1ebcfacae675f9cfd962441 (patch)
treed6a8e8a1d4596f0c559efa1dc4d404d1260dc6a1 /fs/ext4/inode.c
parentext4: avoid divide by zero fault when deleting corrupted inline directories (diff)
downloadkernel-qcow2-linux-bcd8e91f98c156f4b1ebcfacae675f9cfd962441.tar.gz
kernel-qcow2-linux-bcd8e91f98c156f4b1ebcfacae675f9cfd962441.tar.xz
kernel-qcow2-linux-bcd8e91f98c156f4b1ebcfacae675f9cfd962441.zip
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/inode.c')
-rw-r--r--fs/ext4/inode.c8
1 files changed, 6 insertions, 2 deletions
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,
{
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)) {