Linux IOMMU Development
 help / color / mirror / Atom feed
* [PATCH 1/1] iommu/vt-d: Fix UAF on sva unbind with pending IOPFs
@ 2025-07-23  7:20 Lu Baolu
  2025-07-23 12:52 ` Will Deacon
  0 siblings, 1 reply; 2+ messages in thread
From: Lu Baolu @ 2025-07-23  7:20 UTC (permalink / raw)
  To: Joerg Roedel, Will Deacon, Robin Murphy, Kevin Tian,
	Jason Gunthorpe, Ethan Milon
  Cc: iommu, linux-kernel, Lu Baolu

Commit 17fce9d2336d ("iommu/vt-d: Put iopf enablement in domain attach
path") disables IOPF on device by removing the device from its IOMMU's
IOPF queue when the last IOPF-capable domain is detached from the device.
Unfortunately, it did this in a wrong place where there are still pending
IOPFs. As a result, a use-after-free error is potentially triggered and
eventually a kernel panic with a kernel trace similar to the following:

 refcount_t: underflow; use-after-free.
 WARNING: CPU: 3 PID: 313 at lib/refcount.c:28 refcount_warn_saturate+0xd8/0xe0
 Workqueue: iopf_queue/dmar0-iopfq iommu_sva_handle_iopf
 Call Trace:
   <TASK>
   iopf_free_group+0xe/0x20
   process_one_work+0x197/0x3d0
   worker_thread+0x23a/0x350
   ? rescuer_thread+0x4a0/0x4a0
   kthread+0xf8/0x230
   ? finish_task_switch.isra.0+0x81/0x260
   ? kthreads_online_cpu+0x110/0x110
   ? kthreads_online_cpu+0x110/0x110
   ret_from_fork+0x13b/0x170
   ? kthreads_online_cpu+0x110/0x110
   ret_from_fork_asm+0x11/0x20
   </TASK>
  ---[ end trace 0000000000000000 ]---

The intel_pasid_tear_down_entry() function is responsible for blocking
hardware from generating new page faults and flushing all in-flight
ones. Therefore, moving iopf_for_domain_remove() after this function
should resolve this.

Fixes: 17fce9d2336d ("iommu/vt-d: Put iopf enablement in domain attach path")
Reported-by: Ethan Milon <ethan.milon@eviden.com>
Closes: https://lore.kernel.org/r/e8b37f3e-8539-40d4-8993-43a1f3ffe5aa@eviden.com
Suggested-by: Ethan Milon <ethan.milon@eviden.com>
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/iommu/intel/iommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 7c64d88ece77..82b0cec240de 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -4081,8 +4081,8 @@ static int blocking_domain_set_dev_pasid(struct iommu_domain *domain,
 {
 	struct device_domain_info *info = dev_iommu_priv_get(dev);
 
-	iopf_for_domain_remove(old, dev);
 	intel_pasid_tear_down_entry(info->iommu, dev, pasid, false);
+	iopf_for_domain_remove(old, dev);
 	domain_remove_dev_pasid(old, dev, pasid);
 
 	return 0;
-- 
2.43.0


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

* Re: [PATCH 1/1] iommu/vt-d: Fix UAF on sva unbind with pending IOPFs
  2025-07-23  7:20 [PATCH 1/1] iommu/vt-d: Fix UAF on sva unbind with pending IOPFs Lu Baolu
@ 2025-07-23 12:52 ` Will Deacon
  0 siblings, 0 replies; 2+ messages in thread
From: Will Deacon @ 2025-07-23 12:52 UTC (permalink / raw)
  To: Joerg Roedel, Robin Murphy, Kevin Tian, Ethan Milon,
	Jason Gunthorpe, Lu Baolu
  Cc: catalin.marinas, kernel-team, Will Deacon, iommu, linux-kernel

On Wed, 23 Jul 2025 15:20:45 +0800, Lu Baolu wrote:
> Commit 17fce9d2336d ("iommu/vt-d: Put iopf enablement in domain attach
> path") disables IOPF on device by removing the device from its IOMMU's
> IOPF queue when the last IOPF-capable domain is detached from the device.
> Unfortunately, it did this in a wrong place where there are still pending
> IOPFs. As a result, a use-after-free error is potentially triggered and
> eventually a kernel panic with a kernel trace similar to the following:
> 
> [...]

Applied to iommu (intel/vt-d), thanks!

[1/1] iommu/vt-d: Fix UAF on sva unbind with pending IOPFs
      https://git.kernel.org/iommu/c/f0b9d31c6edd

Cheers,
-- 
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev

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

end of thread, other threads:[~2025-07-23 12:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-23  7:20 [PATCH 1/1] iommu/vt-d: Fix UAF on sva unbind with pending IOPFs Lu Baolu
2025-07-23 12:52 ` Will Deacon

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