From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796024082; b=R9x70M8Gc9jwDI8854MxbqcLtAAz++8RD6v3tZ20ntg9iXmFDY+p4JQwQPRb3pcm4yxW QO77dlkKzXIajhHNYTCCKvJWTyZuIsuiSuvya+MSJHOFN50D5onRKsiivOqLhDOCuH7ro ZYgyQzIeHRG/RhXi35mKsejUHc+A4a2KdB2ZAjti8BYNP3dO51MWInZt9ljQjQYPku/UF hsH4D5V5TywNp6J7hTAJIL4fj9fDuYSK7ouYaduxlnkH0AgXCoZ/baftnQahzMRJIIhkD vUS/+RigCYjx4WBGyqZUIP/LM+ntWoNaWuM5j9J2FCuDQfIscA7XYTzAv+8T6V4i1Ww== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796024082; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:From:To:Cc:Subject:Date: Message-ID:MIME-Version:Content-Transfer-Encoding:X-Scanned-By; bh=OayHqxfpl1ENHJaYgcff+3vE3sWao36/sOvZ+OzFoVE=; b=C3ljYk3O6HosNadsNT8xwciRLQfnXghUxUxkIHqlOKISREjl3Ye7U/8QDxFVoiS2GkqU GGyU54jl5bQS8tCw8FDCF+17Vm6Ci1YuQnUx4VRi9CjuIAXbSnqAHxTch9AFEaFjKpEuO /PllmUUDVoxFK9yWLeDtVGH4QpwQ4MWcMymJaGWy1j3As6wPzO4YscpBMrzTq1O46KLUr 5ahzfqS/+gi7q+gkH4DjIwiR3ZLYX79TSe1hon9v9TXcnW+Rfj5aCIoyOSWJavuG2BI9Y wPKU4eonZorWbC96g/HTryETSGqr3KJ9gEqCk/MREEyWHQxAXfiyiU88g6QXt351oZw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ShNis86N; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70E61606A31C for ; Mon, 30 Nov 2026 07:34:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 70E61606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ShNis86N DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796024080; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=OayHqxfpl1ENHJaYgcff+3vE3sWao36/sOvZ+OzFoVE=; b=ShNis86NgdCoo+d1wY9shSb/6Tvm3MQ+cX14Wu7fn3rSpE8SBJKdCYE/gjjeawy/ahEIlU XDuEE25IBCEKG2UmgfQGcgaBi2pnpc7z6rDLMdYqIFzJeJ3FC14s4UMkxlxdseXMF1vr+/ lg4RgL3bLwVJOEzJd5keKtpbdjrZaHE= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-624-4E-_uC2VNc2i3BRaD7VEeg-1; Mon, 30 Nov 2026 07:34:21 +0000 X-MC-Unique: 4E-_uC2VNc2i3BRaD7VEeg-1 X-Mimecast-MFC-AGG-ID: 4E-_uC2VNc2i3BRaD7VEeg_1796024060 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8FEA31800495; Mon, 30 Nov 2026 07:34:19 +0000 (UTC) Received: from snishika-thinkpadp16vgen1.tokyo.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D9CAA1956042; Mon, 30 Nov 2026 07:34:16 +0000 (UTC) From: Seiji Nishikawa To: Justin Tee , Paul Ely Cc: "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Seiji Nishikawa Subject: [PATCH] scsi: lpfc: Put Fabric Controller ndlp initial kref only in UNUSED state Date: Mon, 30 Nov 2026 16:34:09 +0900 Message-ID: <20261130073409.232816-1-snishika@redhat.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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 --- 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