Skip to content

Commit

Permalink
block: fix overflow in blk_ioctl_discard()
Browse files Browse the repository at this point in the history
[ Upstream commit 22d24a5 ]

There is no check for overflow of 'start + len' in blk_ioctl_discard().
Hung task occurs if submit an discard ioctl with the following param:
  start = 0x80000000000ff000, len = 0x8000000000fff000;
Add the overflow validation now.

Signed-off-by: Li Nan <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jens Axboe <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
Li Nan authored and Sasha Levin committed May 9, 2024
1 parent bb58e1d commit 7080f71
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions block/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static int blk_ioctl_discard(struct block_device *bdev, blk_mode_t mode,
unsigned long arg)
{
uint64_t range[2];
uint64_t start, len;
uint64_t start, len, end;
struct inode *inode = bdev->bd_inode;
int err;

Expand All @@ -110,7 +110,8 @@ static int blk_ioctl_discard(struct block_device *bdev, blk_mode_t mode,
if (len & 511)
return -EINVAL;

if (start + len > bdev_nr_bytes(bdev))
if (check_add_overflow(start, len, &end) ||
end > bdev_nr_bytes(bdev))
return -EINVAL;

filemap_invalidate_lock(inode->i_mapping);
Expand Down

0 comments on commit 7080f71

Please sign in to comment.