mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH -next] nbd: Add the maximum limit of allocated index in nbd_dev_add
@ 2023-06-05 12:21 Zhong Jinghua
  2023-06-07  7:37 ` Christoph Hellwig
  2023-06-07 13:52 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Zhong Jinghua @ 2023-06-05 12:21 UTC (permalink / raw)
  To: josef, axboe
  Cc: linux-block, nbd, linux-kernel, zhongjinghua, yi.zhang, yukuai3,
	yangerkun

From: Zhong Jinghua <zhongjinghua@huawei.com>

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>
---
 drivers/block/nbd.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 592cfa8b765a..cb38477f359f 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -1770,7 +1770,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;
 	}
-- 
2.31.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-06-07 13:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-05 12:21 [PATCH -next] nbd: Add the maximum limit of allocated index in nbd_dev_add Zhong Jinghua
2023-06-07  7:37 ` Christoph Hellwig
2023-06-07 13:52 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®