mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mostafa Saleh <smostafa@google.com>
To: iommu@lists.linux.dev, linux-kernel@vger.kernel.org
Cc: joro@8bytes.org, will@kernel.org, robin.murphy@arm.com,
	 Mostafa Saleh <smostafa@google.com>,
	Sashiko <sashiko-bot@kernel.org>
Subject: [PATCH v2 1/2] iommu: debug-pagealloc: Fix overflow checks
Date: Wed,  2 Dec 2026 11:20:45 +0000	[thread overview]
Message-ID: <20261202112047.509228-2-smostafa@google.com> (raw)
In-Reply-To: <20261202112047.509228-1-smostafa@google.com>

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@kernel.org>
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@google.com>
---
 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


  reply	other threads:[~2026-12-02 11:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 11:20 [PATCH v2 0/2] iommu: debug-pagealloc: Small fixes for corner cases Mostafa Saleh
2026-12-02 11:20 ` Mostafa Saleh [this message]
2026-12-02 11:20 ` [PATCH v2 2/2] iommu: debug-pagealloc: Fix mappings starting at phys 0 Mostafa Saleh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202112047.509228-2-smostafa@google.com \
    --to=smostafa@google.com \
    --cc=iommu@lists.linux.dev \
    --cc=joro@8bytes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=sashiko-bot@kernel.org \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®