[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230702194230.1779535-2-sashal@kernel.org>
Date: Sun, 2 Jul 2023 15:42:27 -0400
From: Sasha Levin <sashal@...nel.org>
To: linux-kernel@...r.kernel.org, stable@...r.kernel.org
Cc: Zhong Jinghua <zhongjinghua@...wei.com>,
Christoph Hellwig <hch@....de>, Jens Axboe <axboe@...nel.dk>,
Sasha Levin <sashal@...nel.org>, josef@...icpanda.com,
linux-block@...r.kernel.org, nbd@...er.debian.org
Subject: [PATCH AUTOSEL 4.14 2/5] nbd: Add the maximum limit of allocated index in nbd_dev_add
From: Zhong Jinghua <zhongjinghua@...wei.com>
[ 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@...wei.com>
Reviewed-by: Christoph Hellwig <hch@....de>
Link: https://lore.kernel.org/r/20230605122159.2134384-1-zhongjinghua@huaweicloud.com
Signed-off-by: Jens Axboe <axboe@...nel.dk>
Signed-off-by: Sasha Levin <sashal@...nel.org>
---
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 eb2ca7f6ab3ab..33ad48719c124 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -1630,7 +1630,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;
}
--
2.39.2
Powered by blists - more mailing lists