[PATCH v2] nvme: reject a controller type change on reinitialization

From: Yehyeong Lee

Date: Wed Nov 25 2026 - 09:59:19 EST


nvme_init_identify() caches id->cntrltype on every initialization, and the
Identify Controller data is read again on every reconnect. A fabrics
controller that reported itself as an I/O controller on the first connect
can therefore report itself as an administrative controller on a reconnect,
after its namespaces are in use.

nvme_init_ctrl_finish() then overrides queue_count to 1, so the transport
skips I/O queue setup and the queues that error recovery freed are never
reallocated, leaving queue->sock NULL. The controller is switched to LIVE
anyway with the namespaces still present, and nvme_check_ready() lets any
request through once the state is LIVE, so blk-mq dispatches to the freed
queue:

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

Reject any controller type change on a controller that has already been
initialized.

Fixes: e715b8733df60a ("nvme: add capability to connect to an administrative controller")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Yehyeong Lee <yhlee@xxxxxxxxxxxxxxxxxx>
---
v1: https://lore.kernel.org/linux-nvme/20261124133122.4167640-1-yhlee@xxxxxxxxxxxxxxxxxx/

Changes in v2, after review feedback:
- Generalize the check and move it. v1 rejected the change from inside
the administrative-controller override in nvme_init_ctrl_finish(), and
only for the I/O-to-administrative direction. v2 checks in
nvme_init_identify(), immediately before ctrl->cntrltype is overwritten,
and rejects any controller type change on an already initialized
controller. That also covers administrative-to-I/O and changes to or
from a discovery controller, both of which v1 let through.
- Cut the commit message down to the basics: drop the walkthrough of the
resulting state, the CVE references and the note about the other fabrics
transports.
- The subject changed with the generalization ("an administrative
controller type" -> "a controller type change"); say so and it goes back
to the v1 wording.

drivers/nvme/host/core.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index f43582e5f6c4a9..ffe6a63d24e1dc 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3736,6 +3736,18 @@ static int nvme_init_identify(struct nvme_ctrl *ctrl)
ctrl->max_namespaces = le32_to_cpu(id->mnan);
ctrl->ctratt = le32_to_cpu(id->ctratt);

+ /*
+ * The controller type fixes whether the controller has I/O queues,
+ * so it must not change while the controller is in use.
+ */
+ if (ctrl->identified && ctrl->cntrltype != id->cntrltype) {
+ dev_err(ctrl->device,
+ "controller type changed from %u to %u on reinitialization\n",
+ ctrl->cntrltype, id->cntrltype);
+ ret = -EINVAL;
+ goto out_free;
+ }
+
ctrl->cntrltype = id->cntrltype;
ctrl->dctype = id->dctype;

--
2.43.0