Skip to content

Commit 90c5def

Browse files
jgunthorpejoergroedel
authored andcommitted
iommu: Do not call drivers for empty gathers
An empty gather is coded with start=U64_MAX, end=0 and several drivers go on to convert that to a size with: end - start + 1 Which gives 2 for an empty gather. This then causes Weird Stuff to happen (for example an UBSAN splat in VT-d) that is hopefully harmless, but maybe not. Prevent drivers from being called right in iommu_iotlb_sync(). Auditing shows that AMD, Intel, Mediatek and RSIC-V drivers all do things on these empty gathers. Further, there are several callers that can trigger empty gathers, especially in unusual conditions. For example iommu_map_nosync() will call a 0 size unmap on some error paths. Also in VFIO, iommupt and other places. Cc: [email protected] Reported-by: Janusz Krzysztofik <[email protected]> Closes: https://lore.kernel.org/r/[email protected] Signed-off-by: Jason Gunthorpe <[email protected]> Reviewed-by: Lu Baolu <[email protected]> Reviewed-by: Samiullah Khawaja <[email protected]> Reviewed-by: Robin Murphy <[email protected]> Reviewed-by: Vasant Hegde <[email protected]> Signed-off-by: Joerg Roedel <[email protected]>
1 parent c369299 commit 90c5def

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

include/linux/iommu.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,8 @@ static inline void iommu_flush_iotlb_all(struct iommu_domain *domain)
980980
static inline void iommu_iotlb_sync(struct iommu_domain *domain,
981981
struct iommu_iotlb_gather *iotlb_gather)
982982
{
983-
if (domain->ops->iotlb_sync)
983+
if (domain->ops->iotlb_sync &&
984+
likely(iotlb_gather->start < iotlb_gather->end))
984985
domain->ops->iotlb_sync(domain, iotlb_gather);
985986

986987
iommu_iotlb_gather_init(iotlb_gather);

0 commit comments

Comments
 (0)