[PATCH v2 1/2] iommu: debug-pagealloc: Fix overflow checks
From: Mostafa Saleh
Date: Wed Dec 02 2026 - 06:21:05 EST
There are few corner cases with the overflow checks:
- __iommu_debug_map() checks phys + size for overflow into a size_t.
On a 32-bit kernel with a 64-bit phys_addr_t (as ARM_LPAE) this
would report an overflow for every mapping that ends at or above
4 GiB.
The mapping warns and is not counted, and its unmap then underflows
the page refcounts.
- check_add_overflow() uses size instead of "size - 1" which would
fire if the top of the range was mapped.
And while at it, make the end in __iommu_debug_update_iova() an
unsigned long instead of size_t for consistency.
Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
Link: https://sashiko.dev/#/patchset/20261111185931.94882-1-griffoul%40gmail.com
Fixes: 7e84593795b3 ("iommu: debug-pagealloc: Track IOMMU pages")
Signed-off-by: Mostafa Saleh <smostafa@xxxxxxxxxx>
---
drivers/iommu/iommu-debug-pagealloc.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/iommu/iommu-debug-pagealloc.c b/drivers/iommu/iommu-debug-pagealloc.c
index 80164df5bab1..5faf53aa29f9 100644
--- a/drivers/iommu/iommu-debug-pagealloc.c
+++ b/drivers/iommu/iommu-debug-pagealloc.c
@@ -98,10 +98,11 @@ void __iommu_debug_check_unmapped(const struct page *page, int numpages)
void __iommu_debug_map(struct iommu_domain *domain, phys_addr_t phys, size_t size)
{
- size_t off, end;
+ size_t off;
+ phys_addr_t end;
size_t page_size = iommu_debug_page_size(domain);
- if (WARN_ON(!phys || check_add_overflow(phys, size, &end)))
+ if (!size || WARN_ON(!phys || check_add_overflow(phys, size - 1, &end)))
return;
for (off = 0 ; off < size ; off += page_size)
@@ -111,10 +112,11 @@ void __iommu_debug_map(struct iommu_domain *domain, phys_addr_t phys, size_t siz
static void __iommu_debug_update_iova(struct iommu_domain *domain,
unsigned long iova, size_t size, bool inc)
{
- size_t off, end;
+ size_t off;
+ unsigned long end;
size_t page_size = iommu_debug_page_size(domain);
- if (WARN_ON(check_add_overflow(iova, size, &end)))
+ if (!size || WARN_ON(check_add_overflow(iova, size - 1, &end)))
return;
for (off = 0 ; off < size ; off += page_size) {
--
2.56.1.911.g883d8bcb20-goog