FAILED: patch "[PATCH] scsi: lpfc: Fix buffer free/clear order in deferred receive" failed to apply to 5.4-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 5.4-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.4.y
git checkout FETCH_HEAD
git cherry-pick -x 9dba9a45c348e8460da97c450cddf70b2056deb3
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025090623-retiring-only-9b80@gregkh' --subject-prefix 'PATCH 5.4.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 9dba9a45c348e8460da97c450cddf70b2056deb3 Mon Sep 17 00:00:00 2001
From: John Evans <[email protected]>
Date: Thu, 28 Aug 2025 12:40:08 +0800
Subject: [PATCH] scsi: lpfc: Fix buffer free/clear order in deferred receive
path
Fix a use-after-free window by correcting the buffer release sequence in the deferred receive path. The code freed the RQ buffer first and only then cleared the context pointer under the lock. Concurrent paths (e.g., ABTS and the repost path) also inspect and release the same pointer under the lock, so the old order could lead to double-free/UAF.
Note that the repost path already uses the correct pattern: detach the pointer under the lock, then free it after dropping the lock. The deferred path should do the same.
drivers/scsi/lpfc/lpfc_nvmet.c +6 -4
@@ -1243,7 +1243,7 @@ lpfc_nvmet_defer_rcv(struct nvmet_fc_target_port *tgtport,struct lpfc_nvmet_tgtport *tgtp;struct lpfc_async_xchg_ctx *ctxp = container_of(rsp, struct lpfc_async_xchg_ctx, hdlrctx.fcp_req); -struct rqb_dmabuf *nvmebuf = ctxp->rqb_buffer; +struct rqb_dmabuf *nvmebuf;struct lpfc_hba *phba = ctxp->phba;unsigned long iflag;
@@ -1251,13 +1251,18 @@ lpfc_nvmet_defer_rcv(struct nvmet_fc_target_port *tgtport,lpfc_nvmeio_data (phba,"NVMET DEFERRCV: xri x%x sz %d CPU %02x\n" , ctxp->oxid, ctxp->size,raw_smp_processor_id ()); +spin_lock_irqsave (&ctxp->ctxlock, iflag); + nvmebuf = ctxp->rqb_buffer;if (!nvmebuf) { +spin_unlock_irqrestore (&ctxp->ctxlock, iflag);lpfc_printf_log (phba,KERN_INFO ,LOG_NVME_IOERR ,"6425 Defer rcv: no buffer oxid x%x: " "flg %x ste %x\n" , ctxp->oxid, ctxp->flag, ctxp->state);return ; } + ctxp->rqb_buffer =NULL ; +spin_unlock_irqrestore (&ctxp->ctxlock, iflag); tgtp = phba->targetport->private;if (tgtp)
@@ -1265,9 +1270,6 @@ lpfc_nvmet_defer_rcv(struct nvmet_fc_target_port *tgtport,/* Free the nvmebuf since a new buffer already replaced it */ nvmebuf->hrq->rqbp->rqb_free_buffer (phba, nvmebuf); -spin_lock_irqsave (&ctxp->ctxlock, iflag); - ctxp->rqb_buffer =NULL ; -spin_unlock_irqrestore (&ctxp->ctxlock, iflag); }/**
Sasha Levin
maintainerPATCH 1/1 scsi: lpfc: Fix buffer free/clear order in deferred receive path
From: John Evans <[email protected]>
[ Upstream commit 9dba9a45c348e8460da97c450cddf70b2056deb3 ]
Fix a use-after-free window by correcting the buffer release sequence in the deferred receive path. The code freed the RQ buffer first and only then cleared the context pointer under the lock. Concurrent paths (e.g., ABTS and the repost path) also inspect and release the same pointer under the lock, so the old order could lead to double-free/UAF.
Note that the repost path already uses the correct pattern: detach the pointer under the lock, then free it after dropping the lock. The deferred path should do the same.
--- drivers/scsi/lpfc/lpfc_nvmet.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/scsi/lpfc/lpfc_nvmet.c +6 -4
@@ -1172,7 +1172,7 @@ lpfc_nvmet_defer_rcv(struct nvmet_fc_target_port *tgtport,struct lpfc_nvmet_tgtport *tgtp;struct lpfc_nvmet_rcv_ctx *ctxp = container_of(rsp, struct lpfc_nvmet_rcv_ctx, ctx.fcp_req); -struct rqb_dmabuf *nvmebuf = ctxp->rqb_buffer; +struct rqb_dmabuf *nvmebuf;struct lpfc_hba *phba = ctxp->phba;unsigned long iflag;
@@ -1180,13 +1180,18 @@ lpfc_nvmet_defer_rcv(struct nvmet_fc_target_port *tgtport,lpfc_nvmeio_data (phba,"NVMET DEFERRCV: xri x%x sz %d CPU %02x\n" , ctxp->oxid, ctxp->size,raw_smp_processor_id ()); +spin_lock_irqsave (&ctxp->ctxlock, iflag); + nvmebuf = ctxp->rqb_buffer;if (!nvmebuf) { +spin_unlock_irqrestore (&ctxp->ctxlock, iflag);lpfc_printf_log (phba,KERN_INFO ,LOG_NVME_IOERR ,"6425 Defer rcv: no buffer oxid x%x: " "flg %x ste %x\n" , ctxp->oxid, ctxp->flag, ctxp->state);return ; } + ctxp->rqb_buffer =NULL ; +spin_unlock_irqrestore (&ctxp->ctxlock, iflag); tgtp = phba->targetport->private;if (tgtp)
@@ -1194,9 +1199,6 @@ lpfc_nvmet_defer_rcv(struct nvmet_fc_target_port *tgtport,/* Free the nvmebuf since a new buffer already replaced it */ nvmebuf->hrq->rqbp->rqb_free_buffer (phba, nvmebuf); -spin_lock_irqsave (&ctxp->ctxlock, iflag); - ctxp->rqb_buffer =NULL ; -spin_unlock_irqrestore (&ctxp->ctxlock, iflag); } static void
Signature · 1 line
2.51.0