[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210828153642.19396-3-sven@svenpeter.dev>
Date: Sat, 28 Aug 2021 17:36:36 +0200
From: Sven Peter <sven@...npeter.dev>
To: iommu@...ts.linux-foundation.org
Cc: Sven Peter <sven@...npeter.dev>, Joerg Roedel <joro@...tes.org>,
Will Deacon <will@...nel.org>,
Robin Murphy <robin.murphy@....com>,
Arnd Bergmann <arnd@...nel.org>,
Mohamed Mediouni <mohamed.mediouni@...amail.com>,
Alexander Graf <graf@...zon.com>,
Hector Martin <marcan@...can.st>,
Alyssa Rosenzweig <alyssa@...enzweig.io>,
linux-kernel@...r.kernel.org
Subject: [PATCH v2 2/8] iommu/dma: Fail unaligned map requests for untrusted devs
If swiotlb is enabled we should never try to create any mappings that
would expose more memory than requested to the device.
WARN_ON and refuse those mappings just in case.
Signed-off-by: Sven Peter <sven@...npeter.dev>
---
drivers/iommu/dma-iommu.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index e8eae34e9e4f..d6e273ec3de6 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -534,13 +534,20 @@ static dma_addr_t __iommu_dma_map(struct device *dev, phys_addr_t phys,
struct iommu_dma_cookie *cookie = domain->iova_cookie;
struct iova_domain *iovad = &cookie->iovad;
size_t iova_off = iova_offset(iovad, phys);
+ size_t size_aligned = iova_align(iovad, size + iova_off);
dma_addr_t iova;
if (static_branch_unlikely(&iommu_deferred_attach_enabled) &&
iommu_deferred_attach(dev, domain))
return DMA_MAPPING_ERROR;
- size = iova_align(iovad, size + iova_off);
+ if (IS_ENABLED(CONFIG_SWIOTLB) && dev_is_untrusted(dev)) {
+ if (WARN_ON(iova_off))
+ return DMA_MAPPING_ERROR;
+ if (WARN_ON(size_aligned != size))
+ return DMA_MAPPING_ERROR;
+ }
+ size = size_aligned;
iova = iommu_dma_alloc_iova(domain, size, dma_mask, dev);
if (!iova)
--
2.25.1
Powered by blists - more mailing lists