Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ext3: Avoid underflow of in ext3_trim_fs()

Currently if len argument in ext3_trim_fs() is smaller than one block,
the 'end' variable underflow. Avoid that by returning EINVAL if len is
smaller than file system block.

Also remove useless unlikely().

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Jan Kara <jack@suse.cz>

authored by

Lukas Czerner and committed by
Jan Kara
ae49eeec 7af11686

+3 -2
+3 -2
fs/ext3/balloc.c
··· 2101 2101 end = start + (range->len >> sb->s_blocksize_bits) - 1; 2102 2102 minlen = range->minlen >> sb->s_blocksize_bits; 2103 2103 2104 - if (unlikely(minlen > EXT3_BLOCKS_PER_GROUP(sb)) || 2105 - unlikely(start >= max_blks)) 2104 + if (minlen > EXT3_BLOCKS_PER_GROUP(sb) || 2105 + start >= max_blks || 2106 + range->len < sb->s_blocksize) 2106 2107 return -EINVAL; 2107 2108 if (end >= max_blks) 2108 2109 end = max_blks - 1;