lkml.org 
[lkml]   [2021]   [Aug]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH v2 2/8] iommu/dma: Fail unaligned map requests for untrusted devs
    Date
    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@svenpeter.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
    \
     
     \ /
      Last update: 2021-08-28 17:38    [W:4.437 / U:0.416 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site