From: Hannes Reinecke <hare@suse.de>
To: Yehyeong Lee <yhlee@isslab.korea.ac.kr>,
hch@lst.de, kbusch@kernel.org, sagi@grimberg.me
Cc: kamaljit.singh@opensource.wdc.com,
linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] nvme: reject a controller type change on reinitialization
Date: Thu, 26 Nov 2026 10:52:33 +0100 [thread overview]
Message-ID: <a1ddba64-d9b5-476f-b658-99f3e65744c1@suse.de> (raw)
In-Reply-To: <20261125145902.254297-1-yhlee@isslab.korea.ac.kr>
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
prev parent reply other threads:[~2026-11-26 9:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 13:31 [PATCH] nvme: reject an administrative controller type " 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 message]
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=a1ddba64-d9b5-476f-b658-99f3e65744c1@suse.de \
--to=hare@suse.de \
--cc=hch@lst.de \
--cc=kamaljit.singh@opensource.wdc.com \
--cc=kbusch@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
--cc=yhlee@isslab.korea.ac.kr \
/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
all inboxes | Powered by JetHome®