In lpfc_nvmet_xmt_fcp_release(), when LPFC_NVME_ABORT_OP or LPFC_NVME_XBUSY is set, lpfc_nvmet_defer_release() marks LPFC_NVME_CTX_RLS and moves ctxp to lpfc_abts_nvmet_ctx_list before dropping ctxp->ctxlock. Once ctxlock is released, the deferred release path can repost ctxp to the free pool for reuse by a new NVMe-oF command (immediately in lpfc_sli4_nvmet_xri_aborted() when LPFC_NVME_XBUSY is set and LPFC_NVME_ABORT_OP is clear, or once the abort completion handler clears LPFC_NVME_ABORT_OP). Reading ctxp->oxid/ctxp->state and clearing LPFC_NVME_TNOTIFY on ctxp->flag after spin_unlock_irqrestore(&ctxp->ctxlock, flags) therefore races with concurrent flag updates under ctxlock and can corrupt a recycled context. Clear LPFC_NVME_TNOTIFY and snapshot oxid and state while still holding ctxp->ctxlock so ctxp is not touched after unlocking on the aborting path. Found by LLM-assisted static analysis. Compile-tested on x86_64. Fixes: 79d8c4ce01b2 ("scsi: lpfc: Fix nvmet handling of received ABTS for unmapped frames") Cc: stable@vger.kernel.org Signed-off-by: Ziheng Wei --- drivers/scsi/lpfc/lpfc_nvmet.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/lpfc/lpfc_nvmet.c b/drivers/scsi/lpfc/lpfc_nvmet.c index 72f3f6f94..977b37d78 100644 --- a/drivers/scsi/lpfc/lpfc_nvmet.c +++ b/drivers/scsi/lpfc/lpfc_nvmet.c @@ -1195,6 +1195,7 @@ lpfc_nvmet_xmt_fcp_release(struct nvmet_fc_target_port *tgtport, container_of(rsp, struct lpfc_async_xchg_ctx, hdlrctx.fcp_req); struct lpfc_hba *phba = ctxp->phba; unsigned long flags; + u16 oxid, state; bool aborting = false; spin_lock_irqsave(&ctxp->ctxlock, flags); @@ -1215,13 +1216,15 @@ lpfc_nvmet_xmt_fcp_release(struct nvmet_fc_target_port *tgtport, /* let the abort path do the real release */ lpfc_nvmet_defer_release(phba, ctxp); } + ctxp->flag &= ~LPFC_NVME_TNOTIFY; + oxid = ctxp->oxid; + state = ctxp->state; spin_unlock_irqrestore(&ctxp->ctxlock, flags); - lpfc_nvmeio_data(phba, "NVMET FCP FREE: xri x%x ste %d abt %d\n", ctxp->oxid, - ctxp->state, aborting); + lpfc_nvmeio_data(phba, "NVMET FCP FREE: xri x%x ste %d abt %d\n", oxid, + state, aborting); atomic_inc(&lpfc_nvmep->xmt_fcp_release); - ctxp->flag &= ~LPFC_NVME_TNOTIFY; if (aborting) return; base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa -- 2.43.0