From: sashiko-bot@kernel.org
To: "Ryan Roberts" <ryan.roberts@arm.com>
Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org,
devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org,
robh@kernel.org, conor+dt@kernel.org,
"Oliver Upton" <oupton@kernel.org>,
"Marc Zyngier" <maz@kernel.org>
Subject: Re: [RFC PATCH v2 10/15] KVM: arm64: Introduce support to pin VMIDs
Date: Thu, 15 Oct 2026 14:38:30 +0000 [thread overview]
Message-ID: <sashiko-outbox-172968@kernel.org> (raw)
In-Reply-To: <20261015142552.4128028-11-ryan.roberts@arm.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] kvm: arm64: integer underflow in max_pinned_vmids allows slab OOB write
--
commit 5166cc2f774d24bbef4a1dfb451334ee93c6273a
Author: Shameer Kolothum <skolothumtho@nvidia.com>
KVM: arm64: Introduce support to pin VMIDs
Introduce kvm_arm_pinned_vmid_get() and kvm_arm_pinned_vmid_put(), to pin
a VMID associated with a KVM instance. This will guarantee that VMID
remains the same after a rollover.
> diff --git a/arch/arm64/kvm/vmid.c b/arch/arm64/kvm/vmid.c
> index 7fe8ba1a2851c..322279f59e881 100644
> --- a/arch/arm64/kvm/vmid.c
> +++ b/arch/arm64/kvm/vmid.c
[ ... ]
> @@ -169,6 +175,49 @@ void kvm_arm_vmid_update(struct kvm_vmid *kvm_vmid)
> raw_spin_unlock_irqrestore(&cpu_vmid_lock, flags);
> }
>
> +int kvm_arm_pinned_vmid_get(struct kvm *kvm)
> +{
> + struct kvm_vmid *kvm_vmid;
> + u64 vmid;
> +
> + kvm_vmid = &kvm->arch.mmu.vmid;
> +
> + guard(raw_spinlock_irqsave)(&cpu_vmid_lock);
> + vmid = atomic64_read(&kvm_vmid->id);
> +
> + if (refcount_inc_not_zero(&kvm_vmid->pinned))
> + return (vmid & ~VMID_MASK);
> +
> + if (nr_pinned_vmids >= max_pinned_vmids)
> + return -EINVAL;
[Severity: Critical]
Does this capacity check protect against pinning exhaustion if max_pinned_vmids
underflows?
On ARM64 systems with 8-bit VMIDs (NUM_USER_VMIDS=256) and 255 or more CPUs,
the subtraction used to set max_pinned_vmids in kvm_arm_vmid_alloc_init() will
wrap around to a huge unsigned value.
This allows userspace to bypass this check and exhaust all VMIDs by pinning
them. Once fully exhausted, new_vmid()'s fallback find_next_zero_bit() returns
256, and then falls through to the set_vmid label:
arch/arm64/kvm/vmid.c:new_vmid() {
...
set_vmid:
__set_bit(vmid, vmid_map);
...
}
Can this write past the end of the 256-bit bitmap and corrupt adjacent slab
memory?
[ ... ]
> @@ -186,10 +235,24 @@ int __init kvm_arm_vmid_alloc_init(void)
> if (!vmid_map)
> return -ENOMEM;
>
> + pinned_vmid_map = bitmap_zalloc(NUM_USER_VMIDS, GFP_KERNEL);
> + if (!pinned_vmid_map) {
> + bitmap_free(vmid_map);
> + return -ENOMEM;
> + }
> + nr_pinned_vmids = 0;
> +
> + /*
> + * Ensure we have at least one empty slot available after rollover when
> + * the maximum number of VMIDs are pinned. VMID#0 is reserved.
> + */
> + max_pinned_vmids = NUM_USER_VMIDS - num_possible_cpus() - 2;
[Severity: Critical]
Is it possible for this subtraction to underflow?
If a system has 8-bit VMIDs (NUM_USER_VMIDS = 256) and 255 or more CPUs,
this will result in a negative value that wraps around to ULONG_MAX.
While there is a WARN_ON(NUM_USER_VMIDS - 1 <= num_possible_cpus()) earlier
in kvm_arm_vmid_alloc_init(), it only emits a warning and does not prevent
the initialization from proceeding and setting this underflowed value.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261015142552.4128028-1-ryan.roberts@arm.com?part=10
next prev parent reply other threads:[~2026-10-15 14:38 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-15 14:25 [RFC PATCH v2 00/15] Arm Core Local Accelerator Driver Ryan Roberts
2026-10-15 14:25 ` [RFC PATCH v2 01/15] misc/arm-cla: Add driver skeleton and documentation Ryan Roberts
2026-10-15 14:35 ` sashiko-bot
2026-10-15 14:25 ` [RFC PATCH v2 02/15] misc/arm-cla: Add launch operation helpers Ryan Roberts
2026-10-15 14:42 ` sashiko-bot
2026-10-15 16:17 ` Greg Kroah-Hartman
2026-10-15 16:32 ` Ryan Roberts
2026-10-15 14:25 ` [RFC PATCH v2 03/15] dt-bindings: misc: Add Arm Core Local Accelerator Ryan Roberts
2026-10-15 14:25 ` [RFC PATCH v2 04/15] misc/arm-cla: Probe firmware-described devices Ryan Roberts
2026-10-15 14:37 ` sashiko-bot
2026-10-15 14:25 ` [RFC PATCH v2 05/15] misc/arm-cla: Initialize devices on CPU bringup Ryan Roberts
2026-10-15 14:25 ` [RFC PATCH v2 06/15] misc/arm-cla: Accelerator context save and restore Ryan Roberts
2026-10-15 14:41 ` sashiko-bot
2026-10-15 14:25 ` [RFC PATCH v2 07/15] misc/arm-cla: Set up memory translation context Ryan Roberts
2026-10-15 14:25 ` [RFC PATCH v2 08/15] misc/arm-cla: Manage domain contexts Ryan Roberts
2026-10-15 14:38 ` sashiko-bot
2026-10-15 14:25 ` [RFC PATCH v2 09/15] misc/arm-cla: Add userspace interface Ryan Roberts
2026-10-15 14:47 ` sashiko-bot
2026-10-15 14:25 ` [RFC PATCH v2 10/15] KVM: arm64: Introduce support to pin VMIDs Ryan Roberts
2026-10-15 14:38 ` sashiko-bot [this message]
2026-10-15 14:25 ` [RFC PATCH v2 11/15] KVM: arm64: Export stage-2 MMU config Ryan Roberts
2026-10-15 14:43 ` sashiko-bot
2026-10-15 14:25 ` [RFC PATCH v2 12/15] vfio: Support VFIO devices that access the CPU MMU Ryan Roberts
2026-10-15 14:44 ` sashiko-bot
2026-10-15 16:44 ` Jason Gunthorpe
2026-10-15 14:25 ` [RFC PATCH v2 13/15] misc/arm-cla: Add stage-2 MTC and VM context switch Ryan Roberts
2026-10-15 14:40 ` sashiko-bot
2026-10-15 14:25 ` [RFC PATCH v2 14/15] misc/arm-cla: Support exclusive context assignment Ryan Roberts
2026-10-15 14:41 ` sashiko-bot
2026-10-15 14:25 ` [RFC PATCH v2 15/15] misc/arm-cla: Add vfio-mdev user interface Ryan Roberts
2026-10-15 14:49 ` sashiko-bot
2026-10-15 16:41 ` Jason Gunthorpe
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=sashiko-outbox-172968@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=robh@kernel.org \
--cc=ryan.roberts@arm.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