* [BUG] iommufd: batch_to_domain() can map the wrong PFN at ULONG_MAX
@ 2026-12-01 11:20 James Widner
2026-12-02 2:52 ` Samiullah Khawaja
0 siblings, 1 reply; 2+ messages in thread
From: James Widner @ 2026-12-01 11:20 UTC (permalink / raw)
To: jgg, kevin.tian; +Cc: iommu
[-- Attachment #1: Type: text/plain, Size: 800 bytes --]
Hello,
I found an unsigned-wrap issue in iommufd’s `batch_to_domain()`
handling when an IOAS mapping ends at `ULONG_MAX`. Under the affected
mapping paths, the first PFN run can cover the following IOVA and
leave the final IOVA mapped to a page that was not requested by
userspace.
The attached report explains the trigger, affected paths, current and
stable A/B results, limitations, and proposed fix. I have also
attached the proposed source diff for convenient review.
I would appreciate your assessment of the finding and proposed fix.
Please retain reporter attribution to me in any resulting commit.
This finding was researched and validated with Codex Daybreak and
DeepSeek 4.1 Heretic. I have reviewed the submission and take
responsibility for it.
Thanks,
-JWW
[-- Attachment #2: PROPOSED-FIX.diff --]
[-- Type: application/octet-stream, Size: 1725 bytes --]
diff --git a/drivers/iommu/iommufd/pages.c b/drivers/iommu/iommufd/pages.c
index 70b55fe1a..749ced470 100644
--- a/drivers/iommu/iommufd/pages.c
+++ b/drivers/iommu/iommufd/pages.c
@@ -512,7 +512,7 @@ static int batch_to_domain(struct pfn_batch *batch, struct iommu_domain *domain,
int iommu_prot = area->iommu_prot;
unsigned int page_offset = 0;
unsigned long start_iova;
- unsigned long next_iova;
+ unsigned long size;
unsigned int cur = 0;
unsigned long iova;
int rc;
@@ -525,25 +525,27 @@ static int batch_to_domain(struct pfn_batch *batch, struct iommu_domain *domain,
/* The first index might be a partial page */
if (start_index == iopt_area_index(area))
page_offset = area->page_offset;
- next_iova = iova = start_iova =
- iopt_area_index_to_iova(area, start_index);
+ start_iova = iopt_area_index_to_iova(area, start_index);
+ iova = start_iova;
while (cur < batch->end) {
- next_iova = min(last_iova + 1,
- next_iova + batch->npfns[cur] * PAGE_SIZE -
- page_offset);
+ size = batch->npfns[cur] * PAGE_SIZE - page_offset;
+ /* Avoid representing ULONG_MAX + 1 as an exclusive end. */
+ size = min(size - 1, last_iova - iova) + 1;
if (disable_large_pages)
rc = batch_iommu_map_small(
domain, iova,
PFN_PHYS(batch->pfns[cur]) + page_offset,
- next_iova - iova, iommu_prot);
+ size, iommu_prot);
else
rc = iommu_map(domain, iova,
PFN_PHYS(batch->pfns[cur]) + page_offset,
- next_iova - iova, iommu_prot,
+ size, iommu_prot,
GFP_KERNEL_ACCOUNT);
if (rc)
goto err_unmap;
- iova = next_iova;
+ if (size - 1 == last_iova - iova)
+ return 0;
+ iova += size;
page_offset = 0;
cur++;
}
--
2.43.0
[-- Attachment #3: R18-MAINTAINER-REPORT.pdf --]
[-- Type: application/pdf, Size: 155104 bytes --]
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [BUG] iommufd: batch_to_domain() can map the wrong PFN at ULONG_MAX
2026-12-01 11:20 [BUG] iommufd: batch_to_domain() can map the wrong PFN at ULONG_MAX James Widner
@ 2026-12-02 2:52 ` Samiullah Khawaja
0 siblings, 0 replies; 2+ messages in thread
From: Samiullah Khawaja @ 2026-12-02 2:52 UTC (permalink / raw)
To: James Widner; +Cc: jgg, kevin.tian, iommu
On Tue, Dec 01, 2026 at 06:20:47AM -0500, James Widner wrote:
>Hello,
>
>I found an unsigned-wrap issue in iommufd’s `batch_to_domain()`
>handling when an IOAS mapping ends at `ULONG_MAX`. Under the affected
>mapping paths, the first PFN run can cover the following IOVA and
>leave the final IOVA mapped to a page that was not requested by
>userspace.
>
>The attached report explains the trigger, affected paths, current and
>stable A/B results, limitations, and proposed fix. I have also
>attached the proposed source diff for convenient review.
>
>I would appreciate your assessment of the finding and proposed fix.
>Please retain reporter attribution to me in any resulting commit.
>
>This finding was researched and validated with Codex Daybreak and
>DeepSeek 4.1 Heretic. I have reviewed the submission and take
>responsibility for it.
Hi,
I was working on a fix for this one and was planning to send it today.
Do you want to send the proposed fix or should I send my fix with you
mentioned in Reported-by?
Thanks,
Sami
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-02 2:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 11:20 [BUG] iommufd: batch_to_domain() can map the wrong PFN at ULONG_MAX James Widner
2026-12-02 2:52 ` Samiullah Khawaja
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.