From: sashiko-bot@kernel.org
To: "Guidong Han" <2045gemini@gmail.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v2] RISC-V: KVM: Fix PMU event info array size overflow
Date: Thu, 30 Jul 2026 09:36:02 +0000 [thread overview]
Message-ID: <20260730093603.BD4631F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260730091710.1366757-1-2045gemini@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Unbounded guest-controlled `num_events` allows arbitrarily large memory allocations via `kvcalloc` and host soft lockups.
--
--- Patch [1]: [PATCH v2] RISC-V: KVM: Fix PMU event info array size overflow ---
commit 500aa03e09c05223e23f66e67acfa12d3e264362
Author: Guidong Han <2045gemini@gmail.com>
RISC-V: KVM: Fix PMU event info array size overflow
This commit fixes a slab out-of-bounds issue by storing the shared memory
size in a size_t and checking for multiplication overflow. It also switches
the allocation to use kvcalloc() with GFP_KERNEL_ACCOUNT and __GFP_NOWARN
to support large guest requests safely.
Link: https://lore.kernel.org/kvm/178345245327.72065.13249716450708539854@digiscrypt.com/
Link: https://lore.kernel.org/kvm/20260718153620.829378-1-2045gemini@gmail.com/
> diff --git a/arch/riscv/kvm/vcpu_pmu.c b/arch/riscv/kvm/vcpu_pmu.c
> index 2025b664961c8..a7f948410d531 100644
> --- a/arch/riscv/kvm/vcpu_pmu.c
> +++ b/arch/riscv/kvm/vcpu_pmu.c
[ ... ]
> @@ -479,13 +481,14 @@ int kvm_riscv_vcpu_pmu_event_info(struct kvm_vcpu *vcpu, unsigned long saddr_low
> unsigned long flags, struct kvm_vcpu_sbi_return *retdata)
> {
> struct riscv_pmu_event_info *einfo = NULL;
> - int shmem_size = num_events * sizeof(*einfo);
> + size_t shmem_size;
> gpa_t shmem;
[ ... ]
> - if (flags != 0 || (saddr_low & (SZ_16 - 1) || num_events == 0)) {
> + if (flags != 0 || (saddr_low & (SZ_16 - 1)) || num_events == 0 ||
> + check_mul_overflow(num_events, sizeof(*einfo), &shmem_size)) {
[Severity: High]
Is there a missing upper bound check for num_events here?
While check_mul_overflow() prevents integer wrap-around, it still allows a
guest to pass extremely large values for num_events (e.g., hundreds of
millions) since size_t is 64-bit on RV64.
> ret = SBI_ERR_INVALID_PARAM;
> goto out;
> }
[ ... ]
> - einfo = kzalloc(shmem_size, GFP_KERNEL);
> + einfo = kvcalloc(num_events, sizeof(*einfo),
> + GFP_KERNEL_ACCOUNT | __GFP_NOWARN);
[Severity: High]
Can this unbounded allocation lead to host memory exhaustion?
Because the patch replaces kzalloc() with kvcalloc() without adding a
functional upper limit on num_events, an untrusted guest could force the
host to allocate and zero gigabytes of vmalloc memory. Even with
GFP_KERNEL_ACCOUNT, this could cause severe memory pressure or memcg OOMs.
> if (!einfo) {
> ret = SBI_ERR_FAILURE;
> goto out;
> }
[ ... ]
> - for (int i = 0; i < num_events; i++) {
> + for (unsigned long i = 0; i < num_events; i++) {
> eidx = einfo[i].event_idx;
> etype = kvm_pmu_get_perf_event_type(eidx);
[Severity: High]
If the guest backs the request with valid memory, could this loop cause a
host soft lockup?
This block iterates num_events times synchronously. For very large inputs,
this could execute millions of times without cond_resched(), monopolizing
the host CPU and causing RCU stalls. Should num_events be bounded to a sane
architectural maximum?
> econfig = kvm_pmu_get_perf_event_config(eidx, einfo[i].event_data);
> ret = riscv_pmu_get_event_info(etype, econfig, NULL);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260730091710.1366757-1-2045gemini@gmail.com?part=1
prev parent reply other threads:[~2026-07-30 9:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-18 15:36 [PATCH] RISC-V: KVM: Fix PMU event info array size overflow Guidong Han
2026-07-18 15:49 ` sashiko-bot
2026-07-30 9:36 ` Guidong Han
2026-07-30 9:17 ` [PATCH v2] " Guidong Han
2026-07-30 9:36 ` sashiko-bot [this message]
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=20260730093603.BD4631F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=2045gemini@gmail.com \
--cc=kvm@vger.kernel.org \
--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