The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Mostafa Saleh <smostafa@google.com>
To: "Jörg Rödel" <joro@8bytes.org>
Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
	will@kernel.org, robin.murphy@arm.com
Subject: Re: [PATCH v2 2/2] iommu: debug-pagealloc: Fix mappings starting at phys 0
Date: Thu, 3 Dec 2026 10:57:09 +0000	[thread overview]
Message-ID: <axFLBbMsNf2VPiJ_@google.com> (raw)
In-Reply-To: <axEeaGcZhH5BItiI@8bytes.org>

On Thu, Dec 03, 2026 at 08:48:54AM +0100, Jörg Rödel wrote:
> On Wed, Dec 02, 2026 at 11:20:46AM +0000, Mostafa Saleh wrote:
> > __iommu_debug_map() warns and counts nothing when phys is 0, but unmap
> > only skips the page that iommu_iova_to_phys() reports as 0 and
> > decrements the others,
> > Unmapping a multi-page mapping that starts at physical address 0
> > therefore underflows every other page.
> > 
> > Drop the warning and skip only that page, as unmap does.
> > 
> > Fixes: 7e84593795b3 ("iommu: debug-pagealloc: Track IOMMU pages")
> > Signed-off-by: Mostafa Saleh <smostafa@google.com>
> > ---
> >  drivers/iommu/iommu-debug-pagealloc.c | 9 +++++++--
> >  1 file changed, 7 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/iommu/iommu-debug-pagealloc.c b/drivers/iommu/iommu-debug-pagealloc.c
> > index 5faf53aa29f9..348fc4c57ed2 100644
> > --- a/drivers/iommu/iommu-debug-pagealloc.c
> > +++ b/drivers/iommu/iommu-debug-pagealloc.c
> > @@ -102,11 +102,16 @@ void __iommu_debug_map(struct iommu_domain *domain, phys_addr_t phys, size_t siz
> >  	phys_addr_t end;
> >  	size_t page_size = iommu_debug_page_size(domain);
> >  
> > -	if (!size || WARN_ON(!phys || check_add_overflow(phys, size - 1, &end)))
> > +	if (!size || WARN_ON(check_add_overflow(phys, size - 1, &end)))
> >  		return;
> 
> Do phys and size need alignment checks for page_size? Otherwise ...
> 
> >  
> > -	for (off = 0 ; off < size ; off += page_size)
> > +	for (off = 0 ; off < size ; off += page_size) {
> 
> ... off can overflow here when the above checked add with size passed but
> page_size is added here.
> 

I see, I haven't thought about unaligned addresses/sizes in that case.
I see that in iommu.c __iommu_{map, unmap}_domain_pgtbl() check for
alignment but doesn't cover the iommupt case.

However, iommu_debug_map() is called after pages are mapped with the
mapped size only so it shouldn't overflow.

iommu_debug_unmap_begin() is called before the unmap and the check so
it can overflow first.

I can add the alignment check in __iommu_debug_update_iova() but that
won't be related to this fix as this existed before the series, it can
be a new hardening patch.

Alternatively, I think in iommu.c we can move the alignment check at
the top of __iommu_unmap() and that would also cover the iommupt case.
(and maybe for iommu_map_nosync() also?). AFAIU from
99fb8afa16ad ("iommupt: Directly call iommupt's unmap_range()"),
the iommu_pgsize() calculations are not needed for iommupt as it adds
overhead, but an alignment check should be cheap.

Which of the two would you prefer?

Thanks,
Mostafa

> -Joerg

      reply	other threads:[~2026-12-03 10:57 UTC|newest]

Thread overview: 5+ 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 ` [PATCH v2 1/2] iommu: debug-pagealloc: Fix overflow checks Mostafa Saleh
2026-12-02 11:20 ` [PATCH v2 2/2] iommu: debug-pagealloc: Fix mappings starting at phys 0 Mostafa Saleh
2026-12-03  7:48   ` Jörg Rödel
2026-12-03 10:57     ` Mostafa Saleh [this message]

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=axFLBbMsNf2VPiJ_@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=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