Skip to contentSkip to conversation

block: fix a unsigned integer overflow which could bypass check

PATCH New Changming 1 participant 1 message Nov 27, 2020 Block layer

lore
Share & tools
lore

Changming

author
#0 lore raw

PATCH 1/1 block: fix a unsigned integer overflow which could bypass check

From: Changming Liu <[email protected]>

start, and len are 64 unsigned integers and purely from user-space, thus star + len can wrap-around and bypass the check at

start + len > i_size_read(bdev->bd_inode)

This overflowed value can cause trouble after passed in truncate_bdev_range.

To fix this, a wrap-around check is added just like in blk_ioctl_zeroout, so that such the overflowed value can be rejected.

---
 block/ioctl.c | 2 ++
 1 file changed, 2 insertions(+)
block/ioctl.c +2 -0
index 3fbc382eb926..3fddb1fe5b35 100644
@@ -133,6 +133,8 @@ static int blk_ioctl_discard(struct block_device *bdev, fmode_t mode,
 
 	if (start + len > i_size_read(bdev->bd_inode))
 		return -EINVAL;
+	if (start + len < start)
+		return -EINVAL;
 
 	err = truncate_bdev_range(bdev, mode, start, start + len - 1);
 	if (err)
Signature · 1 line
2.17.1