* [PATCH v2] nvme-rdma: fix NULL queue->ctrl dereference on reconnect
@ 2026-10-29 14:19 Christian Aurich Zanettini Martins
2026-10-30 10:05 ` Nilay Shroff
0 siblings, 1 reply; 2+ messages in thread
From: Christian Aurich Zanettini Martins @ 2026-10-29 14:19 UTC (permalink / raw)
To: linux-nvme
Cc: kbusch, axboe, hch, sagi, sgogte, hare, nilay, wagi,
linux-kernel, Christian Aurich Zanettini Martins, stable
Since commit 2a8513091d2f ("nvme-rdma: parallelize I/O queue allocation
and startup"), a reconnect that gets more I/O queues than before grows
the tag set before the new queues are set up. queue->ctrl is only set
by nvme_rdma_setup_io_queues(), so I/O submitted in between reaches
nvme_rdma_queue_rq() on a queue that was never allocated and
dereferences a NULL queue->ctrl:
BUG: kernel NULL pointer dereference, address: 000000000000034c
RIP: 0010:nvme_rdma_queue_rq+0x52/0xb90
Set queue->ctrl for every queue when allocating the controller. Such
requests are then requeued like on any other queue that is not live.
Fixes: 2a8513091d2f ("nvme-rdma: parallelize I/O queue allocation and startup")
Cc: stable@vger.kernel.org
Signed-off-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
---
v2:
- Only move queue->ctrl. v1 also moved queue_lock, which needs the
queue count in nvme_rdma_free_ctrl(), but opts can already be freed
there when creating the controller fails (KASAN use-after-free on a
failed connect with CONFIG_DEBUG_KOBJECT_RELEASE).
- Not carrying the Reviewed-by tags from Nilay and Christoph, as most
of the patch changed
v1: https://lore.kernel.org/linux-nvme/20261029060521.1690223-1-christian.aurichzm@gmail.com/
Based on nvme-7.4 (89480d137bf0), also applies to mainline and v7.3.
Reproduced in QEMU with nvmet-rdma over rxe and
CONFIG_NVME_MULTIPATH=n: connect with attr_qid_max=2, keep direct reads
running on the CPUs that map to the new hw queues, then raise
attr_qid_max to 4. The window is short, so the readers run at
SCHED_FIFO with nvme-wq pinned to their CPUs. Without the patch the
host oopses within two tries in all six boots. With v2, 24 of 24 tries
go live and 30 resets under I/O pass, with and without lockdep, and
failed connects are clean under KASAN.
drivers/nvme/host/rdma.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c
index 07216890f75c..32189fdfc0f5 100644
--- a/drivers/nvme/host/rdma.c
+++ b/drivers/nvme/host/rdma.c
@@ -735,7 +735,6 @@ static int nvme_rdma_setup_io_queues(struct nvme_rdma_ctrl *ctrl,
for (i = 0; i < nr_queues; i++) {
struct nvme_rdma_queue *queue = &ctrl->queues[first + i];
- queue->ctrl = ctrl;
queue->queue_size = queue_size;
ctxs[i].queue = queue;
@@ -798,7 +797,6 @@ static int nvme_rdma_configure_admin_queue(struct nvme_rdma_ctrl *ctrl,
bool pi_capable = false;
int error;
- ctrl->queues[0].ctrl = ctrl;
ctrl->queues[0].queue_size = NVME_AQ_DEPTH;
error = nvme_rdma_alloc_queue(&ctrl->queues[0]);
if (error)
@@ -2284,7 +2282,7 @@ static struct nvme_rdma_ctrl *nvme_rdma_alloc_ctrl(struct device *dev,
struct nvmf_ctrl_options *opts)
{
struct nvme_rdma_ctrl *ctrl;
- int ret;
+ int ret, i;
ctrl = kzalloc_obj(*ctrl);
if (!ctrl)
@@ -2343,6 +2341,9 @@ static struct nvme_rdma_ctrl *nvme_rdma_alloc_ctrl(struct device *dev,
if (!ctrl->queues)
goto out_free_ctrl;
+ for (i = 0; i < ctrl->ctrl.queue_count; i++)
+ ctrl->queues[i].ctrl = ctrl;
+
ret = nvme_init_ctrl(&ctrl->ctrl, dev, &nvme_rdma_ctrl_ops,
0 /* no quirks, we're perfect! */);
if (ret)
base-commit: 89480d137bf0d943a82c64f86ae2407a15276b5e
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH v2] nvme-rdma: fix NULL queue->ctrl dereference on reconnect
2026-10-29 14:19 [PATCH v2] nvme-rdma: fix NULL queue->ctrl dereference on reconnect Christian Aurich Zanettini Martins
@ 2026-10-30 10:05 ` Nilay Shroff
0 siblings, 0 replies; 2+ messages in thread
From: Nilay Shroff @ 2026-10-30 10:05 UTC (permalink / raw)
To: Christian Aurich Zanettini Martins, linux-nvme
Cc: kbusch, axboe, hch, sagi, sgogte, hare, wagi, linux-kernel, stable
On 10/29/26 7:49 PM, Christian Aurich Zanettini Martins wrote:
> Since commit 2a8513091d2f ("nvme-rdma: parallelize I/O queue allocation
> and startup"), a reconnect that gets more I/O queues than before grows
> the tag set before the new queues are set up. queue->ctrl is only set
> by nvme_rdma_setup_io_queues(), so I/O submitted in between reaches
> nvme_rdma_queue_rq() on a queue that was never allocated and
> dereferences a NULL queue->ctrl:
>
> BUG: kernel NULL pointer dereference, address: 000000000000034c
> RIP: 0010:nvme_rdma_queue_rq+0x52/0xb90
>
> Set queue->ctrl for every queue when allocating the controller. Such
> requests are then requeued like on any other queue that is not live.
>
> Fixes: 2a8513091d2f ("nvme-rdma: parallelize I/O queue allocation and startup")
> Cc:stable@vger.kernel.org
> Signed-off-by: Christian Aurich Zanettini Martins<christian.aurichzm@gmail.com>
Looks good to me:
Reviewed-by: Nilay Shroff <nilay@linux.ibm.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-30 10:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-29 14:19 [PATCH v2] nvme-rdma: fix NULL queue->ctrl dereference on reconnect Christian Aurich Zanettini Martins
2026-10-30 10:05 ` Nilay Shroff
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®