Linux SCSI subsystem development
 help / color / mirror / Atom feed
* [PATCH] scsi: lpfc: avoid post-loop iterator use in lpfc_sli_process_unsol_iocb()
@ 2026-12-05  7:44 Ziheng Wei
  2026-12-05  8:04 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Ziheng Wei @ 2026-12-05  7:44 UTC (permalink / raw)
  To: Justin Tee, Paul Ely, James E . J . Bottomley,
	Martin K . Petersen
  Cc: linux-scsi, linux-kernel, stable

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.

Set iocbq = saveq when !found so the final-response branch unlinks and
processes saveq itself.

Found by LLM-assisted static analysis. Compile-tested on x86_64.

Fixes: 9c2face68782 ("[SCSI] lpfc 8.2.4 : Fix Unsolicited Data items")
Cc: stable@vger.kernel.org
Signed-off-by: Ziheng Wei <zihengw03@163.com>
---
 drivers/scsi/lpfc/lpfc_sli.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index 9173263c8..8bf28619d 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -3566,9 +3566,11 @@ lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
 				break;
 			}
 		}
-		if (!found)
+		if (!found) {
 			list_add_tail(&saveq->clist,
 				      &pring->iocb_continue_saveq);
+			iocbq = saveq;
+		}
 
 		if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
 			list_del_init(&iocbq->clist);

base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] scsi: lpfc: avoid post-loop iterator use in lpfc_sli_process_unsol_iocb()
  2026-12-05  7:44 [PATCH] scsi: lpfc: avoid post-loop iterator use in lpfc_sli_process_unsol_iocb() Ziheng Wei
@ 2026-12-05  8:04 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-05  8:04 UTC (permalink / raw)
  To: Ziheng Wei; +Cc: linux-scsi

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] scsi: lpfc: lpfc_sli_process_unsol_iocb() dispatches orphaned
  CONT64 IOCB
--

commit 512b23b139e6040d1e5f73875f3035d605cf2039
Author: Ziheng Wei <zihengw03@163.com>

scsi: lpfc: avoid post-loop iterator use in lpfc_sli_process_unsol_iocb()

This commit sets iocbq = saveq when no matching entry is found on
pring->iocb_continue_saveq in lpfc_sli_process_unsol_iocb(), avoiding
post-loop iterator use when saveq->iocb.ulpStatus is not
IOSTAT_INTERMED_RSP.

> diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
> index 9173263c87f93..8bf28619d7d03 100644
> --- a/drivers/scsi/lpfc/lpfc_sli.c
> +++ b/drivers/scsi/lpfc/lpfc_sli.c
> @@ -3566,9 +3566,11 @@ lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
>  				break;
>  			}
>  		}
> -		if (!found)
> +		if (!found) {
>  			list_add_tail(&saveq->clist,
>  				      &pring->iocb_continue_saveq);
> +			iocbq = saveq;
> +		}
>  
>  		if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
>  			list_del_init(&iocbq->clist);

[Severity: Medium]
Should an orphaned CMD_IOCB_RCV_CONT64_CX IOCB be dispatched as a standalone
sequence here?

Reaching the ulpStatus != IOSTAT_INTERMED_RSP branch with !found only happens
for a CMD_IOCB_RCV_CONT64_CX continuation whose sequence head is missing from
pring->iocb_continue_saveq.  Setting iocbq = saveq queues and immediately
unlinks saveq, then falls through to process it as a sequence-start IOCB.

Downstream code assumes saveq is a sequence-start IOCB.  NPIV vport lookup
skips CMD_IOCB_RCV_CONT64_CX and leaves traffic on phba->pport, and handlers
like lpfc_els_unsol_buffer() parse mid-sequence payload bytes as an ELS
command while reading rcv_seq64 word 5 fields as the remote NPort DID.

If lpfc_complete_unsol_iocb() finds no matching handler, returning 1 also
leaks saveq->cmd_dmabuf and saveq->bpl_dmabuf.

When !found and saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP, freeing
saveq->cmd_dmabuf and saveq->bpl_dmabuf with lpfc_in_buf_free() and returning
1 would drop the orphaned continuation IOCB instead of dispatching it.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205074457.84293-1-zihengw03@163.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-05  8:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05  7:44 [PATCH] scsi: lpfc: avoid post-loop iterator use in lpfc_sli_process_unsol_iocb() Ziheng Wei
2026-12-05  8:04 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox