[PATCH 11/20] scsi: ibmvfc: fix UAF and hang in ibmvfc_cancel_all_mq() on send failure
From: Tyrel Datwyler
Date: Wed Sep 16 2026 - 19:14:38 EST
ibmvfc_cancel_all_mq() discards the return value of ibmvfc_send_event().
When ibmvfc_send_event() fails due to H_CLOSED it internally frees the
event before returning SCSI_MLQUEUE_HOST_BUSY. The caller then performs
list_add_tail() on the freed event — a use-after-free — and subsequently
blocks indefinitely on wait_for_completion(&evt->comp) for a completion
that will never arrive.
Fix by capturing the return value. On failure, drop the locks, log the
error (consistent with ibmvfc_cancel_all_sq()), drain and free any
cancel events already queued from earlier loop iterations, then return 0.
Returning 0 on send failure is correct: when the adapter closes the CRQ
the firmware delivers a transport event through ibmvfc_handle_crq() which
completes all outstanding commands, so the error recovery caller will
naturally see them return.
Fixes: 5ca8f4e826ff ("ibmvfc: don't call locked done variant for MADs on send failure")
Signed-off-by: Tyrel Datwyler <tyreld@xxxxxxxxxxxxx>
---
drivers/scsi/ibmvscsi/ibmvfc-core.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/drivers/scsi/ibmvscsi/ibmvfc-core.c b/drivers/scsi/ibmvscsi/ibmvfc-core.c
index e2f2fa42bcfd..190410847efb 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc-core.c
+++ b/drivers/scsi/ibmvscsi/ibmvfc-core.c
@@ -2693,6 +2693,7 @@ static int ibmvfc_cancel_all_mq(struct scsi_device *sdev, int type)
unsigned long flags;
int num_hwq, i;
int fail = 0;
+ int rc;
LIST_HEAD(cancelq);
u16 status;
@@ -2719,7 +2720,18 @@ static int ibmvfc_cancel_all_mq(struct scsi_device *sdev, int type)
return -ENOMEM;
}
evt->sync_iu = &queues[i].cancel_rsp;
- ibmvfc_send_event(evt, vhost, default_timeout);
+ rc = ibmvfc_send_event(evt, vhost, default_timeout);
+ if (rc) {
+ spin_unlock(queues[i].q_lock);
+ spin_unlock_irqrestore(&vhost->host->host_lock, flags);
+ sdev_printk(KERN_ERR, sdev, "Failed to send cancel event. rc=%d\n", rc);
+ list_for_each_entry_safe(evt, temp, &cancelq, cancel) {
+ wait_for_completion(&evt->comp);
+ list_del(&evt->cancel);
+ ibmvfc_free_event(evt);
+ }
+ return 0;
+ }
list_add_tail(&evt->cancel, &cancelq);
}
--
2.55.0