Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvmet-fc: hold queue reference while freeing FCP IOD
@ 2026-11-25 11:54 Bin Luo
  2026-11-25 12:15 ` sashiko-bot
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Bin Luo @ 2026-11-25 11:54 UTC (permalink / raw)
  To: linux-nvme; +Cc: nareshgottumukkala83, paul.ely, hch, sagi, kch, gregkh

nvmet_fc_free_fcp_iod() drops the FOD's lookup reference before it locks
queue->qlock and accesses the queue lists. Association teardown may already
have dropped the owner reference, so this put can free the queue before
completion accesses it.

Take a temporary queue reference before dropping the FOD reference. Hold it
through queue/list accesses and deferred-work submission.
Release it on both FOD-return and FOD-reuse paths. The deferred request's
lookup reference stays with the recycled FOD.

Fixes: 619c62dcc62b ("nvmet-fc: correct ref counting error when deferred rcv used")

Tested: v7.4-rc1 KASAN_GENERIC x86_64 QEMU with a test-only owner-reference
injection. Unfixed baseline reports UAF; both patched runs have no KASAN.
Signed-off-by: Bin Luo <luob87709@gmail.com>
---
 drivers/nvme/target/fc.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c
index 5d6c1c7..0b3a448 100644
--- a/drivers/nvme/target/fc.c
+++ b/drivers/nvme/target/fc.c
@@ -733,6 +733,9 @@ nvmet_fc_free_fcp_iod(struct nvmet_fc_tgt_queue *queue,
 
 	tgtport->ops->fcp_req_release(&tgtport->fc_target_port, fcpreq);
 
+	/* Hold queue across the FOD reference put and queue/list accesses. */
+	kref_get(&queue->ref);
+
 	/* release the queue lookup reference on the completed IO */
 	nvmet_fc_tgt_q_put(queue);
 
@@ -742,6 +745,7 @@ nvmet_fc_free_fcp_iod(struct nvmet_fc_tgt_queue *queue,
 	if (!deferfcp) {
 		list_add_tail(&fod->fcp_list, &fod->queue->fod_list);
 		spin_unlock_irqrestore(&queue->qlock, flags);
+		nvmet_fc_tgt_q_put(queue);
 		return;
 	}
 
@@ -774,6 +778,7 @@ nvmet_fc_free_fcp_iod(struct nvmet_fc_tgt_queue *queue,
 	 */
 
 	queue_work(queue->work_q, &fod->defer_work);
+	nvmet_fc_tgt_q_put(queue);
 }
 
 static struct nvmet_fc_tgt_queue *
-- 
2.51.0.windows.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-11-26  8:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 11:54 [PATCH] nvmet-fc: hold queue reference while freeing FCP IOD Bin Luo
2026-11-25 12:15 ` sashiko-bot
2026-11-25 13:48 ` Greg KH
2026-11-25 13:50 ` Greg KH
2026-11-26  5:16 ` [PATCH v2] nvmet-fc: put queue ref after FCP IOD cleanup Bin Luo
2026-11-26  8:42   ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox