From: sashiko-bot@kernel.org
To: "Nigel Kirkland" <nkirkland2304@gmail.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v5 04/10] lpfc: Check fc4_xpt_flags before decrementing ndlp kref on FDISC error
Date: Mon, 28 Sep 2026 18:19:10 +0000 [thread overview]
Message-ID: <20260928181910.B127C1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260928181757.21959-5-nkirkland2304@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] lpfc: TOCTOU race in lpfc_cmpl_els_fdisc() leads to Use-After-Free
--
commit 46ec54ed5cbeb514e9e9362594a41ca2f9b3aa3d
Author: Nigel Kirkland <nkirkland2304@gmail.com>
lpfc: Check fc4_xpt_flags before decrementing ndlp kref on FDISC error
The current initial kref count drop logic for an ndlp that fails FDISC
assumes that the ndlp has never registered with transport layer and thus
the lpfc_dev_loss_tmo_callbk never called. However, a failed FDISC can
occur after a successful transport layer registration too. So,
lpfc_dev_loss_tmo_callbk can occur and there is a potential use-after-free
on the ndlp.
> diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c
> index 6f6394a0047c2..45aad4cd2dc80 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,
[ ... ]
> - /* 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]
Does this lockless check introduce a time-of-check to time-of-use race
condition that could lead to a use-after-free?
If an FDISC error occurs concurrently with a devloss timeout for the same
ndlp, lpfc_dev_loss_tmo_callbk() could execute on another CPU:
CPU1 in lpfc_dev_loss_tmo_callbk():
set_bit(NLP_IN_DEV_LOSS, &ndlp->nlp_flag);
spin_lock_irqsave(&ndlp->lock, iflags);
/* ... */
ndlp->fc4_xpt_flags &= ~SCSI_XPT_REGD;
Because set_bit() lacks a full memory barrier and spin_lock() provides only
an ACQUIRE barrier, could the clearing of SCSI_XPT_REGD become visible to
CPU2 before NLP_IN_DEV_LOSS is seen?
If CPU2 is executing this new check in lpfc_cmpl_els_fdisc() locklessly and
without read barriers, it might see both SCSI_XPT_REGD == 0 and
NLP_IN_DEV_LOSS == 0.
Could this cause CPU2 to erroneously evaluate the condition as true, execute
lpfc_nlp_put(ndlp), and prematurely drop the initial reference, leading to a
use-after-free when CPU1 later tries to use the ndlp pointer?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260928181757.21959-1-nkirkland2304@gmail.com?part=4
next prev parent reply other threads:[~2026-09-28 18:19 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-28 18:17 [PATCH v5 00/10] lpfc: Update lpfc to revision 15.0.0.1 Nigel Kirkland
2026-09-28 18:17 ` [PATCH v5 01/10] lpfc: Fix use-after-free in lpfc_cmpl_ct_cmd_vmid Nigel Kirkland
2026-09-28 18:17 ` [PATCH v5 02/10] lpfc: Early return out of lpfc_els_abort when HBA_SETUP flag is not set Nigel Kirkland
2026-09-28 18:17 ` [PATCH v5 03/10] lpfc: Fix kernel oops when unmapping scsi dma buffers for an aborted cmd Nigel Kirkland
2026-09-28 18:17 ` [PATCH v5 04/10] lpfc: Check fc4_xpt_flags before decrementing ndlp kref on FDISC error Nigel Kirkland
2026-09-28 18:19 ` sashiko-bot [this message]
2026-09-28 18:17 ` [PATCH v5 05/10] lpfc: Add handling for when PLOGI or PRLI is dropped during link failure Nigel Kirkland
2026-09-28 18:17 ` sashiko-bot
2026-09-28 18:17 ` [PATCH v5 06/10] lpfc: Fix ndlp use-after-free during repeated RSCN and rediscovery sequence Nigel Kirkland
2026-09-28 18:09 ` sashiko-bot
2026-09-28 18:17 ` [PATCH v5 07/10] lpfc: Rework I/O flush ordering when unloading driver Nigel Kirkland
2026-09-28 18:18 ` sashiko-bot
2026-09-28 18:17 ` [PATCH v5 08/10] lpfc: Refactor calls on fc_disctmo to lpfc_set_disctmo in RSCN handler Nigel Kirkland
2026-09-28 18:17 ` [PATCH v5 09/10] lpfc: Update correct ndlp refcnt when rejecting an unsolicited PLOGI Nigel Kirkland
2026-09-28 18:14 ` sashiko-bot
2026-09-28 18:17 ` [PATCH v5 10/10] lpfc: Update lpfc version to 15.0.0.1 Nigel Kirkland
2026-10-01 18:12 ` [PATCH v5 00/10] lpfc: Update lpfc to revision 15.0.0.1 Nigel Kirkland
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=20260928181910.B127C1F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=nkirkland2304@gmail.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox