diff options
author | Zhong Jinghua <zhongjinghua@huawei.com> | 2023-06-05 14:21:59 +0200 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2023-06-07 15:50:48 +0200 |
commit | f12bc113ce904777fd6ca003b473b427782b3dde (patch) | |
tree | dc0959ce6bb5f8d3116c864c844360332e1d6eb6 /drivers/block/nbd.c | |
parent | blk-ioprio: Introduce promote-to-rt policy (diff) | |
download | linux-f12bc113ce904777fd6ca003b473b427782b3dde.tar.xz linux-f12bc113ce904777fd6ca003b473b427782b3dde.zip |
nbd: Add the maximum limit of allocated index in nbd_dev_add
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>
Diffstat (limited to 'drivers/block/nbd.c')
-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 65ecde3e2a5b..6457a094abcc 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -1776,7 +1776,8 @@ static struct nbd_device *nbd_dev_add(int index, unsigned int refs) 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; } |