mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-27 21:03:32 +00:00
block: fix overflow in blk_ioctl_discard()
[ Upstream commit 22d24a544b
]
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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
c5d5160d7e
commit
e1d38cde2b
1 changed files with 3 additions and 2 deletions
|
@ -89,7 +89,7 @@ static int blk_ioctl_discard(struct block_device *bdev, blk_mode_t mode,
|
||||||
unsigned long arg)
|
unsigned long arg)
|
||||||
{
|
{
|
||||||
uint64_t range[2];
|
uint64_t range[2];
|
||||||
uint64_t start, len;
|
uint64_t start, len, end;
|
||||||
struct inode *inode = bdev->bd_inode;
|
struct inode *inode = bdev->bd_inode;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
@ -110,7 +110,8 @@ static int blk_ioctl_discard(struct block_device *bdev, blk_mode_t mode,
|
||||||
if (len & 511)
|
if (len & 511)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (start + len > bdev_nr_bytes(bdev))
|
if (check_add_overflow(start, len, &end) ||
|
||||||
|
end > bdev_nr_bytes(bdev))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
filemap_invalidate_lock(inode->i_mapping);
|
filemap_invalidate_lock(inode->i_mapping);
|
||||||
|
|
Loading…
Reference in a new issue