public inbox for iommu@lists.linux-foundation.org
 help / color / mirror / Atom feed
* [PATCH V1] iommu/sva: Fix crash in iommu_sva_unbind_device()
@ 2026-02-24 18:30 Lizhi Hou
  2026-02-25  9:35 ` Yi Liu
  2026-03-02  6:50 ` Baolu Lu
  0 siblings, 2 replies; 9+ messages in thread
From: Lizhi Hou @ 2026-02-24 18:30 UTC (permalink / raw)
  To: joro, will, robin.murphy
  Cc: Lizhi Hou, iommu, linux-kernel, baolu.lu, vasant.hegde

domain->mm->iommu_mm can be freed by iommu_domain_free():
  iommu_domain_free()
    mmdrop()
      __mmdrop()
        mm_pasid_drop()
After iommu_domain_free() returns, accessing domain->mm->iommu_mm may
dereference a freed mm structure, leading to a crash.

Fix this by taking a reference to the mm via mmgrab() before
calling iommu_domain_free(), and dropping it with mmdrop() after
finishing access to domain->mm->iommu_mm.

Fixes: e37d5a2d60a3 ("iommu/sva: invalidate stale IOTLB entries for kernel address space")
Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
---
 drivers/iommu/iommu-sva.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c
index 07d64908a05f..523b8c65c86f 100644
--- a/drivers/iommu/iommu-sva.c
+++ b/drivers/iommu/iommu-sva.c
@@ -179,6 +179,7 @@ void iommu_sva_unbind_device(struct iommu_sva *handle)
 		return;
 	}
 
+	mmgrab(domain->mm);
 	iommu_detach_device_pasid(domain, dev, iommu_mm->pasid);
 	if (--domain->users == 0) {
 		list_del(&domain->next);
@@ -190,6 +191,7 @@ void iommu_sva_unbind_device(struct iommu_sva *handle)
 		if (list_empty(&iommu_sva_mms))
 			iommu_sva_present = false;
 	}
+	mmdrop(domain->mm);
 
 	mutex_unlock(&iommu_sva_lock);
 	kfree(handle);
-- 
2.34.1


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

end of thread, other threads:[~2026-03-04 21:25 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-24 18:30 [PATCH V1] iommu/sva: Fix crash in iommu_sva_unbind_device() Lizhi Hou
2026-02-25  9:35 ` Yi Liu
2026-02-25 22:09   ` Lizhi Hou
2026-02-28 12:14     ` Yi Liu
2026-03-03 18:33       ` Lizhi Hou
2026-03-04 10:10         ` Yi Liu
2026-03-04 21:25           ` Lizhi Hou
2026-03-02  6:50 ` Baolu Lu
2026-03-02 11:04   ` Yi Liu

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