From patchwork Tue Oct 9 12:12:42 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: ext4: Avoid underflow of in ext4_trim_fs() Date: Tue, 09 Oct 2012 02:12:42 -0000 From: Lukas Czerner X-Patchwork-Id: 190290 Message-Id: <1349784762-28069-1-git-send-email-lczerner@redhat.com> To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, Lukas Czerner Currently if len argument in ext4_trim_fs() is smaller than one block, the 'end' variable underflow. Avoid that by exiting right away if len is smaller than one file system block. Signed-off-by: Lukas Czerner Reviewed-by: Carlos Maiolino --- fs/ext4/mballoc.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index f8b27bf..06c8526 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -4989,13 +4989,18 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range) int ret = 0; start = range->start >> sb->s_blocksize_bits; - end = start + (range->len >> sb->s_blocksize_bits) - 1; minlen = EXT4_NUM_B2C(EXT4_SB(sb), range->minlen >> sb->s_blocksize_bits); if (unlikely(minlen > EXT4_CLUSTERS_PER_GROUP(sb)) || unlikely(start >= max_blks)) return -EINVAL; + + end = range->len >> sb->s_blocksize_bits; + if (0 == end) + goto out; + end += start - 1; + if (end >= max_blks) end = max_blks - 1; if (end <= first_data_blk)