From: Jason Gunthorpe <jgg@ziepe.ca>
To: Samuel Moelius <sam.moelius@trailofbits.com>
Cc: Kevin Tian <kevin.tian@intel.com>,
"Joerg Roedel (AMD)" <joro@8bytes.org>,
Will Deacon <will@kernel.org>,
Robin Murphy <robin.murphy@arm.com>,
"open list:IOMMUFD" <iommu@lists.linux.dev>,
open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3] iommu/iommufd: avoid selftest dirty bitmap size wrap
Date: Mon, 13 Jul 2026 10:50:58 -0300 [thread overview]
Message-ID: <20260713135058.GA3133966@ziepe.ca> (raw)
In-Reply-To: <20260628152331.82122.408afd7b466c.iommufd-test-dirty-bitmap-size-wrap@trailofbits.com>
On Sun, Jun 28, 2026 at 03:23:32PM +0000, Samuel Moelius wrote:
> IOMMU_TEST_OP_DIRTY sizes its temporary dirty bitmap from
> length / page_size. Very large selftest ranges can make the
> DIV_ROUND_UP() additions wrap before allocation, producing a
> zero-length allocation while the later test_bit() loop still walks the
> original number of bits.
>
> The selftest helper does not need to support unbounded dirty bitmap
> sizes. Reject requests whose range cap calculation overflows, or whose
> range exceeds SZ_16M pages, before converting the value to bitmap
> allocation and copy sizes.
I suggested to limit either the length or the kvzalloc to around 16M
as a practical limit
> @@ -1686,6 +1687,8 @@ static int iommufd_test_dirty(struct iommufd_ucmd *ucmd, unsigned int mockpt_id,
> u32 flags)
> {
> unsigned long i, max;
> + unsigned long max_pages = SZ_16M;
> + unsigned long max_length;
> struct iommu_test_cmd *cmd = ucmd->cmd;
> struct iommufd_hw_pagetable *hwpt;
> struct mock_iommu_domain *mock;
> @@ -1705,6 +1708,15 @@ static int iommufd_test_dirty(struct iommufd_ucmd *ucmd, unsigned int mockpt_id,
> goto out_put;
> }
>
> + if (check_mul_overflow(max_pages, page_size, &max_length)) {
> + rc = -EOVERFLOW;
> + goto out_put;
> + }
> + if (length > max_length) {
> + rc = -EOVERFLOW;
> + goto out_put;
> + }
This is some huge number, so big that this breaks the logic on 32 bits.
It just needs this:
+ max = length / page_size;
+ if (max > SZ_16M * BITS_PER_BYTE)
+ return -EOVERFLOW;
At the top where it validates the arguments.
I revised this patch and merged it.
Jason
next prev parent reply other threads:[~2026-07-13 13:51 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-28 15:23 Samuel Moelius
2026-07-13 13:50 ` Jason Gunthorpe [this message]
2026-07-15 0:23 ` Samuel Moelius
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=20260713135058.GA3133966@ziepe.ca \
--to=jgg@ziepe.ca \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=robin.murphy@arm.com \
--cc=sam.moelius@trailofbits.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
all inboxes | Powered by JetHome®