7fc3fa0
From: Julian Stecklina <jsteckli@os.info.tu-dresden.de>
7fc3fa0
Subject: [PATCH] vfio, iommu: Fixed interaction of VFIO_IOMMU_MAP_DMA with IOMMU address limits
7fc3fa0
7fc3fa0
The BUG_ON in drivers/iommu/intel-iommu.c:785 can be triggered from userspace via
7fc3fa0
VFIO by calling the VFIO_IOMMU_MAP_DMA ioctl on a vfio device with any address
7fc3fa0
beyond the addressing capabilities of the IOMMU. The problem is that the ioctl code
7fc3fa0
calls iommu_iova_to_phys before it calls iommu_map. iommu_map handles the case that
7fc3fa0
it gets addresses beyond the addressing capabilities of its IOMMU.
7fc3fa0
intel_iommu_iova_to_phys does not.
7fc3fa0
7fc3fa0
This patch fixes iommu_iova_to_phys to return NULL for addresses beyond what the
7fc3fa0
IOMMU can handle. This in turn causes the ioctl call to fail in iommu_map and
7fc3fa0
(correctly) return EFAULT to the user with a helpful warning message in the kernel
7fc3fa0
log.
7fc3fa0
7fc3fa0
Signed-off-by: Julian Stecklina <jsteckli@os.inf.tu-dresden.de>
7fc3fa0
---
7fc3fa0
 drivers/iommu/intel-iommu.c | 6 +++++-
7fc3fa0
 1 file changed, 5 insertions(+), 1 deletion(-)
7fc3fa0
7fc3fa0
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
7fc3fa0
index eec0d3e..61303db 100644
7fc3fa0
--- a/drivers/iommu/intel-iommu.c
7fc3fa0
+++ b/drivers/iommu/intel-iommu.c
7fc3fa0
@@ -782,7 +782,11 @@ static struct dma_pte *pfn_to_dma_pte(struct dmar_domain *domain,
7fc3fa0
 	int offset;
7fc3fa0
 
7fc3fa0
 	BUG_ON(!domain->pgd);
7fc3fa0
-	BUG_ON(addr_width < BITS_PER_LONG && pfn >> addr_width);
7fc3fa0
+
7fc3fa0
+	if (addr_width < BITS_PER_LONG && pfn >> addr_width)
7fc3fa0
+		/* Address beyond IOMMU's addressing capabilities. */
7fc3fa0
+		return NULL;
7fc3fa0
+
7fc3fa0
 	parent = domain->pgd;
7fc3fa0
 
7fc3fa0
 	while (level > 0) {
7fc3fa0
-- 
7fc3fa0
1.8.3.1