diff options
author | Zhong Jinghua <zhongjinghua@huawei.com> | 2023-06-05 15:21:59 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2023-07-27 09:44:36 +0300 |
commit | 4a2c62c8d67cdbf42f217744ffa0fd9d077a589f (patch) | |
tree | 8b9376d4956a1ce5b2ea215316f6e42305397a55 | |
parent | 5f84a34b646f6e52fa8d39bd6f586264c0e68703 (diff) | |
download | linux-4a2c62c8d67cdbf42f217744ffa0fd9d077a589f.tar.xz |
nbd: Add the maximum limit of allocated index in nbd_dev_add
[ Upstream commit f12bc113ce904777fd6ca003b473b427782b3dde ]
If the index allocated by idr_alloc greater than MINORMASK >> part_shift,
the device number will overflow, resulting in failure to create a block
device.
Fix it by imiting the size of the max allocation.
Signed-off-by: Zhong Jinghua <zhongjinghua@huawei.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20230605122159.2134384-1-zhongjinghua@huaweicloud.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r-- | drivers/block/nbd.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index b6940f0a9c90..e0f805ca0e72 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -1723,7 +1723,8 @@ static int nbd_dev_add(int index) if (err == -ENOSPC) err = -EEXIST; } else { - err = idr_alloc(&nbd_index_idr, nbd, 0, 0, GFP_KERNEL); + err = idr_alloc(&nbd_index_idr, nbd, 0, + (MINORMASK >> part_shift) + 1, GFP_KERNEL); if (err >= 0) index = err; } |