From: Yang Erkun <yangerkun@huawei.com>
To: axboe@kernel.dk, josef@toxicpanda.com, xiubli@redhat.com,
prasanna.kalever@redhat.com, ming.lei@redhat.com, yukuai@fygo.io,
nilay@linux.ibm.com
Cc: linux-block@vger.kernel.org, nbd@other.debian.org,
yangerkun@huawei.com, wangkefeng.wang@huawei.com,
leijitang@huawei.com, yi.zhang@huawei.com,
chengzhihao1@huawei.com, houtao1@huawei.com, wozizhi@huawei.com
Subject: [RFC PATCH 1/5] nbd: validate the backend identifier under config_lock
Date: Sat, 7 Nov 2026 14:46:25 +0800 [thread overview]
Message-ID: <20261107064629.4093489-2-yangerkun@huawei.com> (raw)
In-Reply-To: <20261107064629.4093489-1-yangerkun@huawei.com>
nbd_genl_reconfigure() reads nbd->backend with only nbd_index_mutex
held, while nbd_config_put() frees it under config_lock. A teardown
running concurrently triggers:
BUG: kernel NULL pointer dereference, address: 0000000000000000
#PF: supervisor read access in kernel mode
#PF: error_code(0x0000) - not-present page
Oops: Oops: 0000 [#1] SMP KASAN NOPTI
CPU: 0 UID: 0 PID: 819 Comm: a.out Not tainted 7.3.0-dirty #11 PREEMPT(lazy)
RIP: 0010:strlen+0x4/0x30
...
Call Trace:
nla_strcmp+0x20/0x100
nbd_genl_reconfigure+0x1f7/0xd00 [nbd]
genl_family_rcv_msg_doit+0x1e5/0x2c0
genl_family_rcv_msg+0x35f/0x5b0
genl_rcv_msg+0xa3/0x130
netlink_rcv_skb+0x12a/0x390
genl_rcv+0x28/0x40
netlink_unicast+0x7b2/0xb30
netlink_sendmsg+0x6fe/0xb90
__sys_sendto+0x325/0x380
__x64_sys_sendto+0xe0/0x1c0
do_syscall_64+0xc1/0x5e0
entry_SYSCALL_64_after_hwframe+0x76/0x7e
Validate the identifier after taking config_lock and a config
reference. A device that still has a backend identifier but is no
longer bound, for example because it was disconnected while the block
device stayed open, now reports "not configured" instead of a backend
mismatch.
Fixes: 6497ef8df568 ("nbd: provide a way for userspace processes to identify device backends")
Assisted-by: LLM
Signed-off-by: Yang Erkun <yangerkun@huawei.com>
---
drivers/block/nbd.c | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index ffce519bf008..fbade6ae4481 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -2401,22 +2401,6 @@ static int nbd_genl_reconfigure(struct sk_buff *skb, struct genl_info *info)
pr_err("couldn't find a device at index %d\n", index);
return -EINVAL;
}
- if (nbd->backend) {
- if (info->attrs[NBD_ATTR_BACKEND_IDENTIFIER]) {
- if (nla_strcmp(info->attrs[NBD_ATTR_BACKEND_IDENTIFIER],
- nbd->backend)) {
- mutex_unlock(&nbd_index_mutex);
- dev_err(nbd_to_dev(nbd),
- "backend image doesn't match with %s\n",
- nbd->backend);
- return -EINVAL;
- }
- } else {
- mutex_unlock(&nbd_index_mutex);
- dev_err(nbd_to_dev(nbd), "must specify backend\n");
- return -EINVAL;
- }
- }
if (!refcount_inc_not_zero(&nbd->refs)) {
mutex_unlock(&nbd_index_mutex);
pr_err("device at index %d is going down\n", index);
@@ -2441,6 +2425,22 @@ static int nbd_genl_reconfigure(struct sk_buff *skb, struct genl_info *info)
goto out;
}
+ if (nbd->backend) {
+ if (!info->attrs[NBD_ATTR_BACKEND_IDENTIFIER]) {
+ dev_err(nbd_to_dev(nbd), "must specify backend\n");
+ ret = -EINVAL;
+ goto out;
+ }
+ if (nla_strcmp(info->attrs[NBD_ATTR_BACKEND_IDENTIFIER],
+ nbd->backend)) {
+ dev_err(nbd_to_dev(nbd),
+ "backend image doesn't match with %s\n",
+ nbd->backend);
+ ret = -EINVAL;
+ goto out;
+ }
+ }
+
ret = nbd_genl_size_set(info, nbd);
if (ret)
goto out;
--
2.52.0
next prev parent reply other threads:[~2026-11-07 6:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-07 6:46 [RFC PATCH 0/5] nbd: allow parallel genetlink operations Yang Erkun
2026-11-07 6:46 ` Yang Erkun [this message]
2026-11-07 6:46 ` [RFC PATCH 2/5] nbd: decrement nbd_total_devices when a device is removed Yang Erkun
2026-11-07 6:46 ` [RFC PATCH 3/5] nbd: publish devices atomically Yang Erkun
2026-11-07 6:46 ` [RFC PATCH 4/5] nbd: hold config_lock while updating nr_hw_queues Yang Erkun
2026-11-07 6:46 ` [RFC PATCH 5/5] nbd: allow genetlink operations to run in parallel Yang Erkun
2026-11-17 4:36 ` [RFC PATCH 0/5] nbd: allow parallel genetlink operations yangerkun
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=20261107064629.4093489-2-yangerkun@huawei.com \
--to=yangerkun@huawei.com \
--cc=axboe@kernel.dk \
--cc=chengzhihao1@huawei.com \
--cc=houtao1@huawei.com \
--cc=josef@toxicpanda.com \
--cc=leijitang@huawei.com \
--cc=linux-block@vger.kernel.org \
--cc=ming.lei@redhat.com \
--cc=nbd@other.debian.org \
--cc=nilay@linux.ibm.com \
--cc=prasanna.kalever@redhat.com \
--cc=wangkefeng.wang@huawei.com \
--cc=wozizhi@huawei.com \
--cc=xiubli@redhat.com \
--cc=yi.zhang@huawei.com \
--cc=yukuai@fygo.io \
/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