From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Zhong Jinghua <zhongjinghua@huawei.com>,
Christoph Hellwig <hch@lst.de>, Jens Axboe <axboe@kernel.dk>,
Sasha Levin <sashal@kernel.org>,
josef@toxicpanda.com, linux-block@vger.kernel.org,
nbd@other.debian.org
Subject: [PATCH AUTOSEL 6.3 05/14] nbd: Add the maximum limit of allocated index in nbd_dev_add
Date: Sun, 2 Jul 2023 15:40:44 -0400 [thread overview]
Message-ID: <20230702194053.1777356-5-sashal@kernel.org> (raw)
In-Reply-To: <20230702194053.1777356-1-sashal@kernel.org>
From: Zhong Jinghua <zhongjinghua@huawei.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@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>
---
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 dd0adcf745ff5..f0cdc5c576d9d 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;
}
--
2.39.2
next prev parent reply other threads:[~2023-07-02 19:43 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-02 19:40 [PATCH AUTOSEL 6.3 01/14] cpu/hotplug: Reset task stack state in _cpu_up() Sasha Levin
2023-07-02 19:40 ` [PATCH AUTOSEL 6.3 02/14] io_uring: annotate offset timeout races Sasha Levin
2023-07-02 19:40 ` [PATCH AUTOSEL 6.3 03/14] x86/amd_nb: Add MI200 PCI IDs Sasha Levin
2023-07-02 19:40 ` [PATCH AUTOSEL 6.3 04/14] debugobjects: Recheck debug_objects_enabled before reporting Sasha Levin
2023-07-02 19:40 ` Sasha Levin [this message]
2023-07-02 19:40 ` [PATCH AUTOSEL 6.3 06/14] md: fix data corruption for raid456 when reshape restart while grow up Sasha Levin
2023-07-02 19:40 ` [PATCH AUTOSEL 6.3 07/14] md/raid10: prevent soft lockup while flush writes Sasha Levin
2023-07-02 19:40 ` [PATCH AUTOSEL 6.3 08/14] scsi: sg: fix blktrace debugfs entries leakage Sasha Levin
2023-07-02 19:40 ` [PATCH AUTOSEL 6.3 09/14] blk-mq: fix NULL dereference on q->elevator in blk_mq_elv_switch_none Sasha Levin
2023-07-02 19:40 ` [PATCH AUTOSEL 6.3 10/14] posix-timers: Ensure timer ID search-loop limit is valid Sasha Levin
2023-07-02 19:40 ` [PATCH AUTOSEL 6.3 11/14] btrfs: add xxhash to fast checksum implementations Sasha Levin
2023-07-02 19:40 ` [PATCH AUTOSEL 6.3 12/14] btrfs: don't check PageError in __extent_writepage Sasha Levin
2023-07-02 19:40 ` [PATCH AUTOSEL 6.3 13/14] btrfs: abort transaction at update_ref_for_cow() when ref count is zero Sasha Levin
2023-07-02 19:40 ` [PATCH AUTOSEL 6.3 14/14] erofs: Fix detection of atomic context Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230702194053.1777356-5-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=josef@toxicpanda.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nbd@other.debian.org \
--cc=stable@vger.kernel.org \
--cc=zhongjinghua@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox