[PATCH v2] scsi: lpfc: drop orphaned continuation IOCB in lpfc_sli_process_unsol_iocb()
From: Ziheng Wei
Date: Sun Dec 06 2026 - 04:03:51 EST
In lpfc_sli_process_unsol_iocb(), if list_for_each_entry() does not find
a matching XRI on pring->iocb_continue_saveq, iocbq points to a type-
confused container_of() address derived from the list head. When
saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP, the code still executes
list_del_init(&iocbq->clist) and assigns saveq = iocbq, corrupting the
list head and dereferencing invalid memory.
Reaching the non-intermediate branch with !found only happens for an
orphaned CMD_IOCB_RCV_CONT64_CX continuation IOCB whose sequence head is
missing from pring->iocb_continue_saveq, so it should not be dispatched
downstream as a sequence-start IOCB.
When !found and saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP, free the
receive buffers retrieved for saveq (and any chained HBQ entries on
saveq->list) via lpfc_in_buf_free() and return 1 so the caller releases
the orphaned IOCB. When !found and ulpStatus == IOSTAT_INTERMED_RSP,
queue saveq onto iocb_continue_saveq and return 0 directly.
Found by LLM-assisted static analysis. Compile-tested on x86_64.
Fixes: 9c2face68782 ("[SCSI] lpfc 8.2.4 : Fix Unsolicited Data items")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Ziheng Wei <zihengw03@xxxxxxx>
---
v1 -> v2:
- Drop orphaned CMD_IOCB_RCV_CONT64_CX continuation IOCBs by freeing
their receive buffers and returning 1 instead of setting iocbq = saveq
and dispatching them downstream as sequence-start IOCBs (flagged in
Sashiko v1 review).
- v1: https://lore.kernel.org/r/20261205074457.84293-1-zihengw03@xxxxxxx
drivers/scsi/lpfc/lpfc_sli.c | 37 +++++++++++++++++++++++++++++++++++-
1 file changed, 36 insertions(+), 1 deletion(-)
diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index 9173263c8..b22ab26e6 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -3417,6 +3417,35 @@ lpfc_sli_prep_unsol_wqe(struct lpfc_hba *phba,
}
}
+static void
+lpfc_sli_free_unsol_iocb_bufs(struct lpfc_hba *phba, struct lpfc_iocbq *saveq)
+{
+ struct lpfc_iocbq *iocbq;
+
+ if (saveq->iocb.ulpBdeCount != 0 ||
+ !(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
+ lpfc_in_buf_free(phba, saveq->cmd_dmabuf);
+ saveq->cmd_dmabuf = NULL;
+ }
+ if (saveq->iocb.ulpBdeCount == 2) {
+ lpfc_in_buf_free(phba, saveq->bpl_dmabuf);
+ saveq->bpl_dmabuf = NULL;
+ }
+ if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
+ return;
+
+ list_for_each_entry(iocbq, &saveq->list, list) {
+ if (iocbq->iocb.ulpBdeCount != 0) {
+ lpfc_in_buf_free(phba, iocbq->cmd_dmabuf);
+ iocbq->cmd_dmabuf = NULL;
+ }
+ if (iocbq->iocb.ulpBdeCount == 2) {
+ lpfc_in_buf_free(phba, iocbq->bpl_dmabuf);
+ iocbq->bpl_dmabuf = NULL;
+ }
+ }
+}
+
/**
* lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
* @phba: Pointer to HBA context object.
@@ -3566,9 +3595,15 @@ lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
break;
}
}
- if (!found)
+ if (!found) {
+ if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
+ lpfc_sli_free_unsol_iocb_bufs(phba, saveq);
+ return 1;
+ }
list_add_tail(&saveq->clist,
&pring->iocb_continue_saveq);
+ return 0;
+ }
if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
list_del_init(&iocbq->clist);
base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
--
2.43.0