Skip to content

Commit

Permalink
ext3: Avoid underflow of in ext3_trim_fs()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Lukas Czerner authored and Jan Kara committed Nov 19, 2012
1 parent 7af1168 commit ae49eee
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions fs/ext3/balloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2101,8 +2101,9 @@ int ext3_trim_fs(struct super_block *sb, struct fstrim_range *range)
end = start + (range->len >> sb->s_blocksize_bits) - 1;
minlen = range->minlen >> sb->s_blocksize_bits;

if (unlikely(minlen > EXT3_BLOCKS_PER_GROUP(sb)) ||
unlikely(start >= max_blks))
if (minlen > EXT3_BLOCKS_PER_GROUP(sb) ||
start >= max_blks ||
range->len < sb->s_blocksize)
return -EINVAL;
if (end >= max_blks)
end = max_blks - 1;
Expand Down

0 comments on commit ae49eee

Please sign in to comment.