Skip to content
/ linux Public

Commit 58abeb7

Browse files
houlz0507gregkh
authored andcommitted
iommu/sva: Fix crash in iommu_sva_unbind_device()
[ Upstream commit 06e14c3 ] 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 moving the code that accesses domain->mm->iommu_mm to before the call to iommu_domain_free(). Fixes: e37d5a2 ("iommu/sva: invalidate stale IOTLB entries for kernel address space") Signed-off-by: Lizhi Hou <lizhi.hou@amd.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Yi Liu <yi.l.liu@intel.com> Reviewed-by: Vasant Hegde <vasant.hegde@amd.com> Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com> Signed-off-by: Joerg Roedel <joerg.roedel@amd.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 3f300a4 commit 58abeb7

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

drivers/iommu/iommu-sva.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,13 @@ void iommu_sva_unbind_device(struct iommu_sva *handle)
182182
iommu_detach_device_pasid(domain, dev, iommu_mm->pasid);
183183
if (--domain->users == 0) {
184184
list_del(&domain->next);
185-
iommu_domain_free(domain);
186-
}
185+
if (list_empty(&iommu_mm->sva_domains)) {
186+
list_del(&iommu_mm->mm_list_elm);
187+
if (list_empty(&iommu_sva_mms))
188+
iommu_sva_present = false;
189+
}
187190

188-
if (list_empty(&iommu_mm->sva_domains)) {
189-
list_del(&iommu_mm->mm_list_elm);
190-
if (list_empty(&iommu_sva_mms))
191-
iommu_sva_present = false;
191+
iommu_domain_free(domain);
192192
}
193193

194194
mutex_unlock(&iommu_sva_lock);

0 commit comments

Comments
 (0)