* [PATCH] nvme: reject an administrative controller type on reinitialization
@ 2026-11-24 13:31 Yehyeong Lee
2026-11-25 5:16 ` Christoph Hellwig
2026-11-25 14:59 ` [PATCH v2] nvme: reject a controller type change " Yehyeong Lee
0 siblings, 2 replies; 6+ 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 related [flat|nested] 6+ 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
2026-11-25 15:04 ` Yehyeong Lee
2026-11-25 14:59 ` [PATCH v2] nvme: reject a controller type change " Yehyeong Lee
1 sibling, 1 reply; 6+ 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] 6+ messages in thread
* Re: [PATCH] nvme: reject an administrative controller type on reinitialization
2026-11-25 5:16 ` Christoph Hellwig
@ 2026-11-25 15:04 ` Yehyeong Lee
0 siblings, 0 replies; 6+ messages in thread
From: Yehyeong Lee @ 2026-11-25 15:04 UTC (permalink / raw)
To: hch, kbusch, sagi; +Cc: kamaljit.singh, linux-nvme, linux-kernel
On Wed, Nov 25, 2026 at 06:16:08AM +0100, Christoph Hellwig wrote:
> 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.
v2 does both. The check now sits in nvme_init_identify(), right before
ctrl->cntrltype is overwritten, and rejects any controller type change on
an already initialized controller rather than only the I/O-to-admin
override. The commit message is cut down to the bug and the fix.
https://lore.kernel.org/linux-nvme/20261125145902.254297-1-yhlee@isslab.korea.ac.kr/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] nvme: reject a controller type change 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
@ 2026-11-25 14:59 ` Yehyeong Lee
2026-11-26 8:48 ` Christoph Hellwig
2026-11-26 9:52 ` Hannes Reinecke
1 sibling, 2 replies; 6+ messages in thread
From: Yehyeong Lee @ 2026-11-25 14:59 UTC (permalink / raw)
To: hch, kbusch, sagi; +Cc: kamaljit.singh, linux-nvme, linux-kernel
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@vger.kernel.org
Signed-off-by: Yehyeong Lee <yhlee@isslab.korea.ac.kr>
---
v1: https://lore.kernel.org/linux-nvme/20261124133122.4167640-1-yhlee@isslab.korea.ac.kr/
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
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH v2] nvme: reject a controller type change on reinitialization
2026-11-25 14:59 ` [PATCH v2] nvme: reject a controller type change " Yehyeong Lee
@ 2026-11-26 8:48 ` Christoph Hellwig
2026-11-26 9:52 ` Hannes Reinecke
1 sibling, 0 replies; 6+ messages in thread
From: Christoph Hellwig @ 2026-11-26 8:48 UTC (permalink / raw)
To: Yehyeong Lee; +Cc: kbusch, sagi, kamaljit.singh, linux-nvme, linux-kernel
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] nvme: reject a controller type change on reinitialization
2026-11-25 14:59 ` [PATCH v2] nvme: reject a controller type change " Yehyeong Lee
2026-11-26 8:48 ` Christoph Hellwig
@ 2026-11-26 9:52 ` Hannes Reinecke
1 sibling, 0 replies; 6+ messages in thread
From: Hannes Reinecke @ 2026-11-26 9:52 UTC (permalink / raw)
To: Yehyeong Lee, hch, kbusch, sagi; +Cc: kamaljit.singh, linux-nvme, linux-kernel
On 11/25/26 3:59 PM, Yehyeong Lee wrote:
> 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@vger.kernel.org
> Signed-off-by: Yehyeong Lee <yhlee@isslab.korea.ac.kr>
> ---
> v1: https://lore.kernel.org/linux-nvme/20261124133122.4167640-1-yhlee@isslab.korea.ac.kr/
>
> 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;
>
Reviewed-by: Hannes Reinecke <hare@kernel.org>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-26 9:52 UTC | newest]
Thread overview: 6+ 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
2026-11-25 15:04 ` Yehyeong Lee
2026-11-25 14:59 ` [PATCH v2] nvme: reject a controller type change " Yehyeong Lee
2026-11-26 8:48 ` Christoph Hellwig
2026-11-26 9:52 ` Hannes Reinecke
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox