Linux SCSI subsystem development
 help / color / mirror / Atom feed
* [PATCH] scsi: lpfc: fix ndlp use-after-free in RLS accept callback
@ 2026-11-04  2:53 Wentao Liang
  2026-11-04  7:10 ` Krzysztof Kozlowski
  2026-11-05 16:02 ` sashiko-bot
  0 siblings, 2 replies; 3+ messages in thread
From: Wentao Liang @ 2026-11-04  2:53 UTC (permalink / raw)
  To: Justin Tee, Paul Ely, James E.J. Bottomley, Martin K. Petersen; +Cc: linux-scsi

lpfc_els_rcv_rls() takes a reference on the ndlp for the pending
MBX_READ_LNK_STAT command.  lpfc_els_rsp_rls_acc() drops that
reference right after building the ACC IOCB, but then keeps
dereferencing ndlp in the trace message and takes a fresh reference
for the IOCB.

The node can be removed from the nodelist while the mailbox is
pending, so the put may be the last one and release ndlp through
lpfc_nlp_release().  The later ndlp->vport, ndlp->nlp_DID and
lpfc_nlp_get() calls then touch freed memory.

Move the put after the reference for the IOCB has been acquired, and
release it on the paths that bail out before that point.

Fixes: 12265f68ae92 ("[SCSI] lpfc 8.3.18: Add support of received ELS commands")
Cc: stable@vger.kernel.org
Assisted-by: DeepSeek-V4.1-Flash and OpenAI Codex
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 drivers/scsi/lpfc/lpfc_els.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c
index 804aa7509b69..0bd706b1520f 100644
--- a/drivers/scsi/lpfc/lpfc_els.c
+++ b/drivers/scsi/lpfc/lpfc_els.c
@@ -8778,10 +8778,8 @@ lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
 				     lpfc_max_els_tries, ndlp,
 				     ndlp->nlp_DID, ELS_CMD_ACC);
 
-	/* Decrement the ndlp reference count from previous mbox command */
-	lpfc_nlp_put(ndlp);
-
 	if (!elsiocb) {
+		lpfc_nlp_put(ndlp);
 		mempool_free(pmb, phba->mbox_mem_pool);
 		return;
 	}
@@ -8821,10 +8819,14 @@ lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
 	phba->fc_stat.elsXmitACC++;
 	elsiocb->ndlp = lpfc_nlp_get(ndlp);
 	if (!elsiocb->ndlp) {
+		lpfc_nlp_put(ndlp);
 		lpfc_els_free_iocb(phba, elsiocb);
 		return;
 	}
 
+	/* Decrement the ndlp reference count from previous mbox command */
+	lpfc_nlp_put(ndlp);
+
 	rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
 	if (rc == IOCB_ERROR) {
 		lpfc_els_free_iocb(phba, elsiocb);
-- 
2.34.1


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

end of thread, other threads:[~2026-11-05 16:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-04  2:53 [PATCH] scsi: lpfc: fix ndlp use-after-free in RLS accept callback Wentao Liang
2026-11-04  7:10 ` Krzysztof Kozlowski
2026-11-05 16:02 ` sashiko-bot

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