From: Seiji Nishikawa <snishika@redhat.com>
To: Justin Tee <justin.tee@broadcom.com>, Paul Ely <paul.ely@broadcom.com>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
"Martin K. Petersen" <mkp@kernel.org>,
linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
Seiji Nishikawa <snishika@redhat.com>
Subject: [PATCH] scsi: lpfc: Put Fabric Controller ndlp initial kref only in UNUSED state
Date: Mon, 30 Nov 2026 16:34:09 +0900 [thread overview]
Message-ID: <20261130073409.232816-1-snishika@redhat.com> (raw)
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
reply other threads:[~2026-11-30 7:34 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261130073409.232816-1-snishika@redhat.com \
--to=snishika@redhat.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=justin.tee@broadcom.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=mkp@kernel.org \
--cc=paul.ely@broadcom.com \
/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®