From: sashiko-bot@kernel.org
To: "Justin Tee" <justintee8345@gmail.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v3 04/14] lpfc: Check fc4_xpt_flags before decrementing ndlp kref on FDISC error
Date: Tue, 14 Jul 2026 00:55:36 +0000 [thread overview]
Message-ID: <20260714005537.136E71F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260714011812.106753-5-justintee8345@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Pre-existing vulnerabilities in `lpfc_cmpl_els_flogi` and `lpfc_sli4_seq_abort_rsp` due to missing NVMe checks and non-atomic `NLP_DROPPED` flag operations.
--
--- Patch [4]: [PATCH v3 04/14] lpfc: Check fc4_xpt_flags before decrementing ndlp kref on FDISC error ---
commit 0f11d01d4dc626992ac78f74f8c706c25c1fb010
Author: Justin Tee <justintee8345@gmail.com>
lpfc: Check fc4_xpt_flags before decrementing ndlp kref on FDISC error
This patch modifies FDISC error handling to ensure we check whether a node
has been registered with a transport layer before decrementing the initial
kref count. If previously registered, it delegates the kref drop to the
transport's respective dev_loss_tmo callback to avoid a potential
use-after-free.
> diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c
> index 52fc5058976d9..b756de9986ebe 100644
> --- a/drivers/scsi/lpfc/lpfc_els.c
> +++ b/drivers/scsi/lpfc/lpfc_els.c
> @@ -11427,11 +11426,22 @@ lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
> goto out;
> /* Warn FDISC status */
> lpfc_vlog_msg(vport, KERN_WARNING, LOG_ELS,
> - "0126 FDISC cmpl status: x%x/x%x)\n",
> - ulp_status, ulp_word4);
> + "0126 FDISC cmpl status: (x%x/x%x) ndlp x%px "
> + "Data: x%lx x%x x%x x%x x%x x%x x%x x%x x%x\n",
> + ulp_status, ulp_word4, ndlp, ndlp->nlp_flag,
> + ndlp->nlp_DID, ndlp->nlp_last_elscmd,
> + ndlp->nlp_type, ndlp->nlp_rpi, ndlp->nlp_state,
> + ndlp->nlp_prev_state, ndlp->fc4_xpt_flags,
> + kref_read(&ndlp->kref));
>
> - /* drop initial reference */
> - if (!test_and_set_bit(NLP_DROPPED, &ndlp->nlp_flag))
> + /* If have not previously registered with transport layer and no
> + * LPFC_EVT_DEV_LOSS work pending, then drop initial reference.
> + * Otherwise, let the dev_loss_tmo_callbk drop the initial
> + * reference.
> + */
> + if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)) &&
> + !test_bit(NLP_IN_DEV_LOSS, &ndlp->nlp_flag) &&
> + !test_and_set_bit(NLP_DROPPED, &ndlp->nlp_flag))
> lpfc_nlp_put(ndlp);
[Severity: High]
This is a pre-existing issue, but since this patch updates the logic here to
use an atomic test_and_set_bit() for the NLP_DROPPED flag and checks for both
SCSI and NVMe transport registrations, it highlights similar vulnerable code
blocks elsewhere.
For instance, in the same file, lpfc_cmpl_els_flogi() uses a non-atomic
check and set:
drivers/scsi/lpfc/lpfc_els.c:lpfc_cmpl_els_flogi() {
...
if (!test_bit(NLP_IN_DEV_LOSS, &ndlp->nlp_flag) &&
!test_bit(NLP_DROPPED, &ndlp->nlp_flag) &&
!(ndlp->fc4_xpt_flags & SCSI_XPT_REGD)) {
set_bit(NLP_DROPPED, &ndlp->nlp_flag);
lpfc_nlp_put(ndlp);
}
...
}
Can concurrent threads (like a link flap triggering lpfc_dev_loss_tmo_callbk)
evaluate test_bit(NLP_DROPPED, ...) as false and concurrently double-put the
ndlp kref here?
Also, does this FLOGI path miss the NVME_XPT_REGD check entirely, potentially
allowing premature kref drops for NVMe-only registrations?
A similar non-atomic pattern appears in sequence abort handling:
drivers/scsi/lpfc/lpfc_sli.c:lpfc_sli4_seq_abort_rsp() {
...
if (ndlp->nlp_state == NLP_STE_UNUSED_NODE &&
!test_bit(NLP_DROPPED, &ndlp->nlp_flag) &&
!(ndlp->fc4_xpt_flags & (NVME_XPT_REGD | SCSI_XPT_REGD))) {
set_bit(NLP_DROPPED, &ndlp->nlp_flag);
lpfc_nlp_put(ndlp);
}
...
}
Would it be worth updating these other paths to use the atomic
test_and_set_bit() and the unified transport checks as you did in this patch?
>
> goto fdisc_failed;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260714011812.106753-1-justintee8345@gmail.com?part=4
next prev parent reply other threads:[~2026-07-14 0:55 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-14 1:17 [PATCH v3 00/14] Update lpfc to revision 15.0.0.1 Justin Tee
2026-07-14 1:17 ` [PATCH v3 01/14] lpfc: Fix use-after-free in lpfc_cmpl_ct_cmd_vmid Justin Tee
2026-07-14 0:51 ` sashiko-bot
2026-07-14 1:18 ` [PATCH v3 02/14] lpfc: Early return out of lpfc_els_abort when HBA_SETUP flag is not set Justin Tee
2026-07-14 0:53 ` sashiko-bot
2026-07-14 1:18 ` [PATCH v3 03/14] lpfc: Fix kernel oops when unmapping scsi dma buffers for an aborted cmd Justin Tee
2026-07-14 0:57 ` sashiko-bot
2026-07-14 1:18 ` [PATCH v3 04/14] lpfc: Check fc4_xpt_flags before decrementing ndlp kref on FDISC error Justin Tee
2026-07-14 0:55 ` sashiko-bot [this message]
2026-07-14 1:18 ` [PATCH v3 05/14] lpfc: Add handling for when PLOGI or PRLI is dropped during link failure Justin Tee
2026-07-14 1:02 ` sashiko-bot
2026-07-14 1:18 ` [PATCH v3 06/14] lpfc: Fix ndlp use-after-free during repeated RSCN and rediscovery sequence Justin Tee
2026-07-14 0:50 ` sashiko-bot
2026-07-14 1:18 ` [PATCH v3 07/14] lpfc: Rework I/O flush ordering when unloading driver Justin Tee
2026-07-14 1:00 ` sashiko-bot
2026-07-14 1:18 ` [PATCH v3 08/14] lpfc: Improve PLOGI retry handling for large SAN configurations Justin Tee
2026-07-14 0:55 ` sashiko-bot
2026-07-14 1:18 ` [PATCH v3 09/14] lpfc: Send inhibited ABORT_WQE when PLOGI CQE SEQUENCE_TMO is received Justin Tee
2026-07-14 1:05 ` sashiko-bot
2026-07-14 1:18 ` [PATCH v3 10/14] lpfc: Remove slowpath cqe process limiter in slow ring event handler Justin Tee
2026-07-14 0:54 ` sashiko-bot
2026-07-14 1:18 ` [PATCH v3 11/14] lpfc: Put iocbq on phba->txq when ELS WQ is full or ELS SGL unavailable Justin Tee
2026-07-14 0:50 ` sashiko-bot
2026-07-14 1:18 ` [PATCH v3 12/14] lpfc: Update ELS ACC logging for diagnostic troubleshooting Justin Tee
2026-07-14 1:02 ` sashiko-bot
2026-07-14 1:18 ` [PATCH v3 13/14] lpfc: Refactor calls on fc_disctmo to lpfc_set_disctmo in RSCN handler Justin Tee
2026-07-14 1:00 ` sashiko-bot
2026-07-14 1:18 ` [PATCH v3 14/14] lpfc: Update lpfc version to 15.0.0.1 Justin Tee
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=20260714005537.136E71F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=justintee8345@gmail.com \
--cc=linux-scsi@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.