Skip to contentSkip to conversation

ext3: Avoid underflow of in ext3_trim_fs()

PATCH In review Lukas Czerner 2 participants 2 messages Oct 11, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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().

---
 fs/ext3/balloc.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
fs/ext3/balloc.c +3 -2
index 7320a66..22548f5 100644
@@ -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;
Signature · 1 line
1.7.7.6
#1 lore raw
Quoted 5 lines · Lukas Czerner

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().

Thanks. I've added the patch to my tree.

Honza

Quoted 29 lines
---
 fs/ext3/balloc.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
fs/ext3/balloc.c +3 -2
index 7320a66..22548f5 100644
@@ -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;
Signature · 6 lines
1.7.7.6

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR