* [PATCH] nvme: reject an administrative controller type on reinitialization
@ 2026-11-24 13:31 Yehyeong Lee
2026-11-25 5:16 ` Christoph Hellwig
0 siblings, 1 reply; 2+ messages in thread
From: Yehyeong Lee @ 2026-11-24 13:31 UTC (permalink / raw)
To: hch, kbusch, sagi; +Cc: linux-nvme, linux-kernel, kamaljit.singh
nvme_init_ctrl_finish() takes the controller type from the Identify
Controller data, and for an administrative controller it overrides
ctrl->queue_count to 1 so that only an admin queue is created. The
Identify data is read again on every reconnect, so a controller that
reported itself as an I/O controller on the first connect, and whose
namespaces are in use, can report itself as an administrative controller
on a reconnect.
Nothing absorbs that. nvme_tcp_setup_ctrl() skips
nvme_tcp_configure_io_queues() because queue_count is 1, so the I/O
queues that nvme_tcp_error_recovery_work() freed are not reallocated and
queue->sock stays NULL. The controller is switched to NVME_CTRL_LIVE
anyway, while the namespace, its gendisk and its tag set are all still
there, and the I/O queues have been unquiesced on purpose to fail fast
the pending requests. nvme_check_ready() returns true for any request
once the state is LIVE, without consulting NVME_TCP_Q_LIVE, so blk-mq
dispatches to the freed queue and the send path dereferences the NULL
socket:
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000003: 0000 [#1] SMP KASAN NOPTI
KASAN: null-ptr-deref in range [0x0000000000000018-0x000000000000001f]
CPU: 0 UID: 0 PID: 81 Comm: kworker/0:1H Not tainted 7.4.0-rc4 #1 PREEMPT(lazy)
Workqueue: kblockd blk_mq_run_work_fn
RIP: 0010:selinux_socket_sendmsg+0x76/0x2f0
RSP: 0018:ffffc900008ef528 EFLAGS: 00010206
RAX: dffffc0000000000 RBX: ffffc900008ef730 RCX: ffffffff822ab089
RDX: 0000000000000003 RSI: 0000000000000000 RDI: ffffc900008ef738
RBP: 0000000000000000 R08: 0000000000000005 R09: 0000000000000000
R10: 0000000000000001 R11: ffffffff84c14740 R12: 0000000000000000
R13: 0000000000000018 R14: 0000000000000000 R15: 0000000000000000
FS: 0000000000000000(0000) GS:ffff8880e6931000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f52b4001b78 CR3: 0000000009275003 CR4: 0000000000770ef0
PKRU: 55555554
Call Trace:
<TASK>
security_socket_sendmsg+0x6f/0x90
sock_sendmsg+0x117/0x390
nvme_tcp_try_send_cmd_pdu+0x4b7/0x9d0
nvme_tcp_try_send+0x20e/0xbf0
nvme_tcp_queue_rq+0x1148/0x1510
blk_mq_dispatch_rq_list+0x3e3/0x1e30
__blk_mq_sched_dispatch_requests+0x218/0x15c0
blk_mq_sched_dispatch_requests+0xd7/0x1b0
blk_mq_run_work_fn+0xe4/0x190
process_one_work+0x747/0x11c0
worker_thread+0x57c/0xcb0
kthread+0x327/0x430
ret_from_fork+0x394/0x770
ret_from_fork_asm+0x1a/0x30
The state it leaves behind is stable, not a teardown race: the
controller stays live with cntrltype "admin", queue_count 1 and the
namespace still present, and every I/O submitted to it from then on
takes the host down.
So only override queue_count for a controller that has not been
initialized yet. A controller that already completed initialization
with I/O queues cannot lose them, so fail the reinitialization and let
the transport retry the reconnect or remove the controller.
An nvme-tcp controller is a remote network peer, and the host driver
already validates its response data as untrusted input elsewhere
(CVE-2026-89481, CVE-2026-89973). This is the same kind of validation,
on one byte of Identify Controller data.
nvme-rdma and nvme-fc gate their I/O queue setup on queue_count the same
way, so they are exposed to the same sequence; only nvme-tcp was tested.
Fixes: e715b8733df60a ("nvme: add capability to connect to an administrative controller")
Cc: stable@vger.kernel.org
Signed-off-by: Yehyeong Lee <yhlee@isslab.korea.ac.kr>
---
drivers/nvme/host/core.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index f43582e5f6c4a9..831f4c184ddc7c 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3826,7 +3826,17 @@ int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl, bool was_suspended)
/*
* An admin controller has one admin queue, but no I/O queues.
* Override queue_count so it only creates an admin queue.
+ *
+ * Only do that for a controller that has not been initialized
+ * yet: dropping the I/O queues of a controller that already
+ * has namespaces leaves them without a transport queue to
+ * submit to.
*/
+ if (ctrl->identified && ctrl->queue_count > 1) {
+ dev_err(ctrl->device,
+ "rejecting administrative controller type for an initialized I/O controller\n");
+ return -EINVAL;
+ }
dev_dbg(ctrl->device,
"Subsystem %s is an administrative controller",
ctrl->subsys->subnqn);
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] nvme: reject an administrative controller type on reinitialization
2026-11-24 13:31 [PATCH] nvme: reject an administrative controller type on reinitialization Yehyeong Lee
@ 2026-11-25 5:16 ` Christoph Hellwig
0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2026-11-25 5:16 UTC (permalink / raw)
To: Yehyeong Lee; +Cc: hch, kbusch, sagi, linux-nvme, linux-kernel, kamaljit.singh
On Tue, Nov 24, 2026 at 10:31:22PM +0900, Yehyeong Lee wrote:
> nvme_init_ctrl_finish() takes the controller type from the Identify
> Controller data, and for an administrative controller it overrides
> ctrl->queue_count to 1 so that only an admin queue is created. The
> Identify data is read again on every reconnect, so a controller that
> reported itself as an I/O controller on the first connect, and whose
> namespaces are in use, can report itself as an administrative controller
> on a reconnect.
Well, we'll have more issues if a reconnect changes the controller
type. So please check for that just after issuing the identify
controller and reject such a shape changing controller.
And please cut the commit message down to the basics.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-25 5:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-24 13:31 [PATCH] nvme: reject an administrative controller type on reinitialization Yehyeong Lee
2026-11-25 5:16 ` Christoph Hellwig
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®