From: Jason Gunthorpe <jgg@ziepe.ca>
To: Alex Mastro <amastro@fb.com>
Cc: Alex Williamson <alex.williamson@redhat.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] vfio: fix VFIO_IOMMU_UNMAP_DMA when end of range would overflow u64
Date: Mon, 6 Oct 2025 09:16:18 -0300 [thread overview]
Message-ID: <20251006121618.GA3365647@ziepe.ca> (raw)
In-Reply-To: <20251005-fix-unmap-v1-1-6687732ed44e@fb.com>
On Sun, Oct 05, 2025 at 08:38:42PM -0700, Alex Mastro wrote:
> vfio_find_dma_first_node is called to find the first dma node to unmap
> given an unmap range of [iova..iova+size). The check at the end of the
> function intends to test if the dma result lies beyond the end of the
> unmap range. The condition is incorrectly satisfied when iova+size
> overflows to zero, causing the function to return NULL.
>
> The same issue happens inside vfio_dma_do_unmap's while loop.
>
> Fix by comparing to the inclusive range end, which can be expressed
> by u64.
>
> This bug was discovered after querying for vfio_iova_range's via
> VFIO_IOMMU_GET_INFO, making a VFIO_IOMMU_MAP_DMA inside the last range,
> and then attempting to unmap the entirety of the last range i.e.
> VFIO_IOMMU_UNMAP_DMA(iova=r.start, size=r.end-r.start+1).
>
> ---
> I don't think iommufd is susceptible to the same issue since
> iopt_unmap_iova computes the inclusive end using checked addition, and
> iopt_unmap_iova_range acts on an inclusive range.
Yeah, iommufd was careful to use inclusive ranges so that ULONG_MAX
can be a valid IOVA.
This doesn't seem complete though, if the range ends at the ULONG_MAX
then these are not working either:
if (start < dma->iova + dma->size) {
?
And I see a few more instances like that eg in
vfio_iova_dirty_bitmap(), vfio_dma_do_unmap(), vfio_iommu_replay()
Jason
next prev parent reply other threads:[~2025-10-06 12:16 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-06 3:38 [PATCH] vfio: fix VFIO_IOMMU_UNMAP_DMA when end of range would overflow u64 Alex Mastro
2025-10-06 12:16 ` Jason Gunthorpe [this message]
2025-10-06 16:29 ` Alex Mastro
2025-10-06 22:50 ` Jason Gunthorpe
2025-10-07 0:39 ` Alex Mastro
2025-10-07 1:23 ` Alejandro Jimenez
2025-10-07 4:24 ` Alex Mastro
2025-10-07 14:41 ` Alejandro Jimenez
2025-10-07 20:43 ` Alex Williamson
2025-10-07 22:57 ` Alex Mastro
2025-10-07 11:48 ` Jason Gunthorpe
2025-10-07 14:46 ` Alejandro Jimenez
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=20251006121618.GA3365647@ziepe.ca \
--to=jgg@ziepe.ca \
--cc=alex.williamson@redhat.com \
--cc=amastro@fb.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.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