From: sashiko-bot@kernel.org
To: lirongqing <lirongqing@baidu.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH] vfio: Validate that bitmap.pgsize is a power-of-2 in vfio_iommu_type1_unmap_dma
Date: Tue, 16 Jun 2026 11:28:57 +0000 [thread overview]
Message-ID: <20260616112859.8E45A1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260616111733.1810-1-lirongqing@baidu.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The patch correctly addresses undefined behavior by validating that user-provided bitmap.pgsize is a power-of-2 before passing it to __ffs() in vfio_iommu_type1_unmap_dma(). However, it completely misses identical vulnerabilities in vfio_iommu_type1_dirty_pages() where unvalidated user inputs are also passed to bit-scanning functions.
--
commit 6fe55d8211a4934baec28340932ad6ce53984ed4
Author: Li RongQing <lirongqing@baidu.com>
vfio: Validate that bitmap.pgsize is a power-of-2 in vfio_iommu_type1_unmap_dma
In vfio_iommu_type1_unmap_dma(), the user-supplied bitmap.pgsize is
passed directly to __ffs() without sufficient validation.
> diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
> index c8151ba54de33..b05fde8d87c65 100644
> --- a/drivers/vfio/vfio_iommu_type1.c
> +++ b/drivers/vfio/vfio_iommu_type1.c
[ ... ]
> @@ -2949,6 +2950,9 @@ static int vfio_iommu_type1_unmap_dma(struct vfio_iommu *iommu,
> if (!access_ok((void __user *)bitmap.data, bitmap.size))
> return -EINVAL;
>
> + if (unlikely(!is_power_of_2(bitmap.pgsize)))
> + return -EINVAL;
> +
[Severity: High]
This is a pre-existing issue, but while this check addresses the problem
here, does the exact same problem exist in vfio_iommu_type1_dirty_pages()
in the same file?
If userspace passes dirty.flags == 0, the invalid flag check is bypassed,
and both macros are invoked with 0, which triggers undefined behavior:
drivers/vfio/vfio_iommu_type1.c:vfio_iommu_type1_dirty_pages() {
...
/* only one flag should be set at a time */
if (__ffs(dirty.flags) != __fls(dirty.flags))
return -EINVAL;
...
}
Similarly, when VFIO_IOMMU_DIRTY_PAGES_FLAG_GET_BITMAP is requested,
range.bitmap.pgsize is passed to __ffs() without checking for 0 or
non-power-of-2:
drivers/vfio/vfio_iommu_type1.c:vfio_iommu_type1_dirty_pages() {
...
pgshift = __ffs(range.bitmap.pgsize);
ret = verify_bitmap_size(size >> pgshift,
range.bitmap.size);
...
}
Since providing 0 triggers undefined behavior, and a non-power-of-2 value
distorts the subsequent verify_bitmap_size() logic exactly as described in
the commit message, would it be better to add the same validation to
vfio_iommu_type1_dirty_pages() as well?
> pgshift = __ffs(bitmap.pgsize);
> ret = verify_bitmap_size(unmap.size >> pgshift,
> bitmap.size);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260616111733.1810-1-lirongqing@baidu.com?part=1
next prev parent reply other threads:[~2026-06-16 11:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-16 11:17 [PATCH] vfio: Validate that bitmap.pgsize is a power-of-2 in vfio_iommu_type1_unmap_dma lirongqing
2026-06-16 11:28 ` sashiko-bot [this message]
2026-06-16 23:14 ` Alex Williamson
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=20260616112859.8E45A1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=lirongqing@baidu.com \
--cc=sashiko-reviews@lists.linux.dev \
/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