mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] scsi: lpfc: Put Fabric Controller ndlp initial kref only in UNUSED state
@ 2026-11-30  7:34 Seiji Nishikawa
  0 siblings, 0 replies; only message in thread
From: Seiji Nishikawa @ 2026-11-30  7:34 UTC (permalink / raw)
  To: Justin Tee, Paul Ely
  Cc: James E.J. Bottomley, Martin K. Petersen, linux-scsi,
	linux-kernel, Seiji Nishikawa

lpfc_dev_loss_tmo_callbk() crashes with a NULL pointer dereference on
the Fabric Controller ndlp (DID xfffffd) when dev_loss_tmo expires 30
seconds after a link down. The ndlp was already freed right after the
link down:

0279 lpfc_nlp_release: ndlp: xXXXXXXXXXXXXXXXX did fffffd refcnt:0 rpi:3
**** lpfc_rport_invalid: Null vport on ndlp xXXXXXXXXXXXXXXXX, DID xfffffd rport xXXXXXXXXXXXXXXXX SID xffffffff
BUG: kernel NULL pointer dereference, address: 0000000000000000
...
RIP: 0010:lpfc_dev_loss_tmo_callbk+0x54/0x5c0 [lpfc]

The ndlp is freed early because it has one reference less than it
should before the link goes down. On a port that does not crash, the
Fabric Controller ndlp has nlp_flag x80000000 and refcnt 3 at rport
unregister:

0211 DSM in event xc on NPort xfffffd in state 6 rpi x3 Data: x80000000 x5
3184 rport unregister xfffffd, rport xXXXXXXXXXXXXXXXX xptflg x2 refcnt 3

On the port that crashes, it has nlp_flag x80010000 and refcnt 2. Bit
x10000 is NLP_DROPPED, which means the initial reference was put:

0211 DSM in event xc on NPort xfffffd in state 6 rpi x3 Data: x80010000 x5
3184 rport unregister xfffffd, rport xXXXXXXXXXXXXXXXX xptflg x2 refcnt 2

Commit 0b8b15a0b74d ("scsi: lpfc: Modify kref handling for Fabric
Controller ndlps") added a put of the initial reference of the Fabric
Controller ndlp in lpfc_cmpl_els_disc_cmd():

        if ((cmd == ELS_CMD_SCR || cmd == ELS_CMD_RDF) &&
            !(ndlp->fc4_xpt_flags & SCSI_XPT_REGD) &&
            !test_and_set_bit(NLP_DROPPED, &ndlp->nlp_flag))
                lpfc_nlp_put(ndlp);

Its commit message says this is for an ndlp that remains in UNUSED
state, but the code does not check the ndlp state. It runs when an ELS
discovery cmd completes with an error and SCSI_XPT_REGD is not set. But
SCSI_XPT_REGD is not set while the REG_LOGIN issued by
lpfc_reg_fab_ctrl_node() has not finished. If the ELS discovery cmd
fails during that time, the initial reference is put on an ndlp that is
in use.

This is not the problem fixed by commit 8dbdaf88f4b9 ("scsi: lpfc:
Update correct ndlp refcnt when rejecting an unsolicited PLOGI"). The
crash happens with and without that commit.

Put the initial reference only when the ndlp is in UNUSED state.

Fixes: 0b8b15a0b74d ("scsi: lpfc: Modify kref handling for Fabric Controller ndlps")
Assisted-by: LLM
Signed-off-by: Seiji Nishikawa <snishika@redhat.com>
---
 drivers/scsi/lpfc/lpfc_els.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c
index 804aa7509b69..b1c0e23e6271 100644
--- a/drivers/scsi/lpfc/lpfc_els.c
+++ b/drivers/scsi/lpfc/lpfc_els.c
@@ -3491,10 +3491,12 @@ lpfc_cmpl_els_disc_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
 				 ulp_status, ulp_word4);
 
 		/* In the case where the ELS cmd completes with an error and
-		 * the node does not have RPI registered, the node is
-		 * outstanding and should put its initial reference.
+		 * the node is in UNUSED state and not registered with the
+		 * SCSI transport, the node is not in use, so put its initial
+		 * reference.
 		 */
 		if ((cmd == ELS_CMD_SCR || cmd == ELS_CMD_RDF) &&
+		    ndlp->nlp_state == NLP_STE_UNUSED_NODE &&
 		    !(ndlp->fc4_xpt_flags & SCSI_XPT_REGD) &&
 		    !test_and_set_bit(NLP_DROPPED, &ndlp->nlp_flag))
 			lpfc_nlp_put(ndlp);
-- 
2.56.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-30  7:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30  7:34 [PATCH] scsi: lpfc: Put Fabric Controller ndlp initial kref only in UNUSED state Seiji Nishikawa

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®