Skip to content

Commit 22d24a5

Browse files
Li Nanaxboe
authored andcommitted
block: fix overflow in blk_ioctl_discard()
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 <linan122@huawei.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20240329012319.2034550-1-linan666@huaweicloud.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent fbbd5d3 commit 22d24a5

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

block/ioctl.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static int blk_ioctl_discard(struct block_device *bdev, blk_mode_t mode,
9696
unsigned long arg)
9797
{
9898
uint64_t range[2];
99-
uint64_t start, len;
99+
uint64_t start, len, end;
100100
struct inode *inode = bdev->bd_inode;
101101
int err;
102102

@@ -117,7 +117,8 @@ static int blk_ioctl_discard(struct block_device *bdev, blk_mode_t mode,
117117
if (len & 511)
118118
return -EINVAL;
119119

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

123124
filemap_invalidate_lock(inode->i_mapping);

0 commit comments

Comments
 (0)