Skip to content

Commit 82c3cef

Browse files
LuBaolujoergroedel
authored andcommitted
iommu: Don't use lazy flush for untrusted device
The lazy IOTLB flushing setup leaves a time window, in which the device can still access some system memory, which has already been unmapped by the device driver. It's not suitable for untrusted devices. A malicious device might use this to attack the system by obtaining data that it shouldn't obtain. Fixes: c588072 ("iommu/vt-d: Convert intel iommu driver to the iommu ops") Signed-off-by: Lu Baolu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 765a9d1 commit 82c3cef

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

drivers/iommu/dma-iommu.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,11 @@ static void iommu_dma_flush_iotlb_all(struct iova_domain *iovad)
311311
domain->ops->flush_iotlb_all(domain);
312312
}
313313

314+
static bool dev_is_untrusted(struct device *dev)
315+
{
316+
return dev_is_pci(dev) && to_pci_dev(dev)->untrusted;
317+
}
318+
314319
/**
315320
* iommu_dma_init_domain - Initialise a DMA mapping domain
316321
* @domain: IOMMU domain previously prepared by iommu_get_dma_cookie()
@@ -365,8 +370,9 @@ static int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base,
365370

366371
init_iova_domain(iovad, 1UL << order, base_pfn);
367372

368-
if (!cookie->fq_domain && !iommu_domain_get_attr(domain,
369-
DOMAIN_ATTR_DMA_USE_FLUSH_QUEUE, &attr) && attr) {
373+
if (!cookie->fq_domain && (!dev || !dev_is_untrusted(dev)) &&
374+
!iommu_domain_get_attr(domain, DOMAIN_ATTR_DMA_USE_FLUSH_QUEUE, &attr) &&
375+
attr) {
370376
if (init_iova_flush_queue(iovad, iommu_dma_flush_iotlb_all,
371377
iommu_dma_entry_dtor))
372378
pr_warn("iova flush queue initialization failed\n");
@@ -508,11 +514,6 @@ static void __iommu_dma_unmap_swiotlb(struct device *dev, dma_addr_t dma_addr,
508514
iova_align(iovad, size), dir, attrs);
509515
}
510516

511-
static bool dev_is_untrusted(struct device *dev)
512-
{
513-
return dev_is_pci(dev) && to_pci_dev(dev)->untrusted;
514-
}
515-
516517
static dma_addr_t __iommu_dma_map(struct device *dev, phys_addr_t phys,
517518
size_t size, int prot, u64 dma_mask)
518519
{

0 commit comments

Comments
 (0)