Commit 06e14c36 authored by Lizhi Hou's avatar Lizhi Hou Committed by Joerg Roedel
Browse files

iommu/sva: Fix crash in iommu_sva_unbind_device()



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: e37d5a2d ("iommu/sva: invalidate stale IOTLB entries for kernel address space")
Signed-off-by: default avatarLizhi Hou <lizhi.hou@amd.com>
Reviewed-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Reviewed-by: default avatarYi Liu <yi.l.liu@intel.com>
Reviewed-by: default avatarVasant Hegde <vasant.hegde@amd.com>
Reviewed-by: default avatarLu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: default avatarJoerg Roedel <joerg.roedel@amd.com>
parent 45c6a2dc
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -182,15 +182,15 @@ void iommu_sva_unbind_device(struct iommu_sva *handle)
	iommu_detach_device_pasid(domain, dev, iommu_mm->pasid);
	if (--domain->users == 0) {
		list_del(&domain->next);
		iommu_domain_free(domain);
	}

		if (list_empty(&iommu_mm->sva_domains)) {
			list_del(&iommu_mm->mm_list_elm);
			if (list_empty(&iommu_sva_mms))
				iommu_sva_present = false;
		}

		iommu_domain_free(domain);
	}

	mutex_unlock(&iommu_sva_lock);
	kfree(handle);
}