diff options
author | Li Nan <linan122@huawei.com> | 2024-03-29 04:23:19 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2024-05-17 13:02:13 +0300 |
commit | e1d38cde2b7b0fbd1c48082e7a98c37d750af59b (patch) | |
tree | bc274afa4d7680698649a4f68a3db4db009b0178 | |
parent | c5d5160d7e00dcb829b93c95f846e4d3a4177027 (diff) | |
download | linux-e1d38cde2b7b0fbd1c48082e7a98c37d750af59b.tar.xz |
block: fix overflow in blk_ioctl_discard()
[ Upstream commit 22d24a544b0d49bbcbd61c8c0eaf77d3c9297155 ]
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>
-rw-r--r-- | block/ioctl.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/block/ioctl.c b/block/ioctl.c index d1d8e8391279..68265f914c27 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -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; @@ -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); |