From: sashiko-bot@kernel.org
To: "Anup Patel" <anup.patel@oss.qualcomm.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v5 1/2] irqchip/riscv-imsic: Add nr_guest_files in per-HART local config
Date: Mon, 25 May 2026 10:18:47 +0000 [thread overview]
Message-ID: <20260525101848.430F31F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260525094945.3721783-2-anup.patel@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] The loop searching for the correct MMIO location uses `nr_mmios` as its continuation condition instead of `j < nr_mmios`. This acts as an infinite loop if `nr_mmios > 0` and can cause an out-of-bounds read on the `mmios` array.
- [High] The calculation of `nr_guest_files` can silently underflow to `0xFFFFFFFF` if the remaining MMIO resource size is smaller than a single page, leading to an incorrectly maximized guest file count.
--
commit 15182effc09715c1274ad73e7c779ccf2a70e30d
Author: Guo Ren (Alibaba DAMO Academy) <guoren@kernel.org>
irqchip/riscv-imsic: Add nr_guest_files in per-HART local config
This commit adds nr_guest_files to the per-HART local config to represent
the number of guest files available on a particular HART. This allows KVM
to use per-HART configurations for asymmetric big.Little systems instead
of relying on a global minimum.
> diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-riscv-imsic-state.c
> index e3ed874d89e73..b8d1bbbf42f73 100644
> --- a/drivers/irqchip/irq-riscv-imsic-state.c
> +++ b/drivers/irqchip/irq-riscv-imsic-state.c
> @@ -920,13 +920,12 @@ int __init imsic_setup_state(struct fwnode_handle *fwnode, void *opaque)
> local->msi_va = mmios_va[index] + reloff;
[Severity: High]
This is a pre-existing issue, but looking at the code just above this hunk
in imsic_setup_state(), the loop searching for the correct MMIO location
uses nr_mmios as its continuation condition:
for (j = 0; nr_mmios; j++) {
if (reloff < resource_size(&mmios[j])) {
...
Since nr_mmios is a constant integer greater than 0, this acts as an
unconditional loop. If the condition is never satisfied, could j increment
past nr_mmios and cause an out-of-bounds read on the dynamically allocated
mmios array?
>
> /*
> - * KVM uses global->nr_guest_files to determine the available guest
> - * interrupt files on each CPU. Take the minimum number of guest
> - * interrupt files across all CPUs to avoid KVM incorrectly allocating
> - * an unexisted or unmapped guest interrupt file on some CPUs.
> + * KVM uses both local->nr_guest_files and global->nr_guest_files
> + * to determine the available guest interrupt files on each CPU.
> */
> nr_guest_files = (resource_size(&mmios[index]) - reloff) / IMSIC_MMIO_PAGE_SZ - 1;
[Severity: High]
This is a pre-existing issue, but can this calculation silently underflow to
0xFFFFFFFF if the remaining MMIO resource size is smaller than a single
page?
If the remaining resource size is strictly greater than 0 but less than
IMSIC_MMIO_PAGE_SZ, the division yields 0. Subtracting 1 from 0 causes an
unsigned underflow.
Because min() is used in the following lines, it compares both as unsigned
and selects the maximum allowed guest files instead of 0. Could this
artificially inflate the guest file count and lead KVM to make out-of-bounds
MMIO accesses?
> - global->nr_guest_files = min(global->nr_guest_files, nr_guest_files);
> + local->nr_guest_files = min((BIT(global->guest_index_bits) - 1), nr_guest_files);
> + global->nr_guest_files = min(global->nr_guest_files, local->nr_guest_files);
>
> nr_handlers++;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260525094945.3721783-1-anup.patel@oss.qualcomm.com?part=1
next prev parent reply other threads:[~2026-05-25 10:18 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-25 9:49 [PATCH v5 0/2] RISC-V: KVM: Convert HGEI management to fully per-HART Anup Patel
2026-05-25 9:49 ` Anup Patel
2026-05-25 9:49 ` Anup Patel
2026-05-25 9:49 ` [PATCH v5 1/2] irqchip/riscv-imsic: Add nr_guest_files in per-HART local config Anup Patel
2026-05-25 9:49 ` Anup Patel
2026-05-25 9:49 ` Anup Patel
2026-05-25 10:18 ` sashiko-bot [this message]
2026-05-25 9:49 ` [PATCH v5 2/2] RISC-V: KVM: AIA: Make HGEI number management fully per-CPU Anup Patel
2026-05-25 9:49 ` Anup Patel
2026-05-25 9:49 ` Anup Patel
2026-05-25 10:58 ` sashiko-bot
2026-05-26 1:12 ` Guo Ren
2026-05-26 1:12 ` Guo Ren
2026-05-26 1:12 ` Guo Ren
2026-05-31 15:10 ` [PATCH v5 0/2] RISC-V: KVM: Convert HGEI management to fully per-HART Anup Patel
2026-05-31 15:10 ` Anup Patel
2026-05-31 15:10 ` Anup Patel
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=20260525101848.430F31F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=anup.patel@oss.qualcomm.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 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.