[PATCH 1/2] iommu/io-pgfault: unlink partial faults before freeing them
From: Qihang
Date: Mon Nov 16 2026 - 20:54:40 EST
iopf_queue_remove_device() frees the pending partial faults without
unlinking them, so fault_param->partial keeps pointing into freed
memory. A report that is still in flight can then list_add() through
those dangling pointers. The unlink has been missing since
iopf_queue_remove_device() was first added, but the race only became
reachable with a74c077b9021, which made the fault parameter
refcounted and able to outlive the removal.
Unlink each entry before freeing it, matching
iopf_queue_discard_partial().
This fixes the dangling-list access only: a partial that arrives after
the drain now leaks, because the parameter is no longer on
queue->devices and its final put does not free partial faults. The
next patch gives such a partial a defined fate.
Fixes: a74c077b9021 ("iommu: Use refcount for fault data access")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Qihang <q.h.hack.winter@xxxxxxxxx>
---
iopf_queue_discard_partial() cannot be called directly from here: it
takes queue->lock, which iopf_queue_remove_device() already holds.
drivers/iommu/io-pgfault.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/io-pgfault.c b/drivers/iommu/io-pgfault.c
index c16ff1f..55a3c29 100644
--- a/drivers/iommu/io-pgfault.c
+++ b/drivers/iommu/io-pgfault.c
@@ -479,8 +479,10 @@ void iopf_queue_remove_device(struct iopf_queue *queue, struct device *dev)
goto unlock;
mutex_lock(&fault_param->lock);
- list_for_each_entry_safe(partial_iopf, next, &fault_param->partial, list)
+ list_for_each_entry_safe(partial_iopf, next, &fault_param->partial, list) {
+ list_del(&partial_iopf->list);
kfree(partial_iopf);
+ }
list_for_each_entry_safe(group, temp, &fault_param->faults, pending_node) {
struct iopf_fault *iopf = &group->last_fault;