Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4181c30a authored by Zhong Jinghua's avatar Zhong Jinghua Committed by Greg Kroah-Hartman
Browse files

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: default avatarZhong Jinghua <zhongjinghua@huawei.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20230605122159.2134384-1-zhongjinghua@huaweicloud.com


Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent d4f1cd9b
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -1708,7 +1708,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;
	}