From: sashiko-bot@kernel.org
To: "Bibo Mao" <maobibo@loongson.cn>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v3 3/3] LoongArch: KVM: Use internal API to deliver interrupt in kernel mode
Date: Mon, 29 Jun 2026 02:41:35 +0000 [thread overview]
Message-ID: <20260629024137.2F3391F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260629023213.597030-4-maobibo@loongson.cn>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Multiple pre-existing WARN_ONCE and WARN_ON_ONCE macros are reachable by unprivileged host userspace and malicious guests, allowing a host-side DoS if `panic_on_warn` is enabled.
- [High] Uninitialized array `vector` is conditionally assigned but unconditionally evaluated and used to modify hardware CSRs.
--
commit f75612ad87b1cded57456f721c300aad7e8b6150
Author: Bibo Mao <maobibo@loongson.cn>
LoongArch: KVM: Use internal API to deliver interrupt in kernel mode
This commit updates KVM on LoongArch to use internal APIs
kvm_queue_irq() and kvm_dequeue_irq() for delivering interrupts in kernel
mode, rather than the user mode kvm_vcpu_ioctl_interrupt(). It also moves
IPI injection and ack operations within lock protection to reduce contention.
> diff --git a/arch/loongarch/kvm/intc/dmsintc.c b/arch/loongarch/kvm/intc/dmsintc.c
> index 708abbcd55bff..ed85532247759 100644
> --- a/arch/loongarch/kvm/intc/dmsintc.c
> +++ b/arch/loongarch/kvm/intc/dmsintc.c
> @@ -47,7 +47,6 @@ void dmsintc_inject_irq(struct kvm_vcpu *vcpu)
[Severity: High]
This isn't a bug introduced by this patch, but looking at dmsintc_inject_irq()
just above this change, is the vector array properly initialized?
arch/loongarch/kvm/intc/dmsintc.c:dmsintc_inject_irq() {
unsigned long vector[4], old;
...
for (i = 0; i < 4; i++) {
old = atomic64_read(&(ds->vector_map[i]));
if (old)
vector[i] = atomic64_xchg(&(ds->vector_map[i]), 0);
}
if (vector[0]) {
old = kvm_read_hw_gcsr(LOONGARCH_CSR_ISR0);
kvm_write_hw_gcsr(LOONGARCH_CSR_ISR0, vector[0] | old);
}
}
If atomic64_read() returns zero, vector[i] is left uninitialized. When it
checks if (vector[0]) later, could this evaluate to true using stack garbage
and write random data into the guest CSRs?
> int dmsintc_deliver_msi_to_vcpu(struct kvm *kvm,
> struct kvm_vcpu *vcpu, u32 vector, int level)
> {
[ ... ]
> diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c
> index 361fca46e2b32..265aaad633157 100644
> --- a/arch/loongarch/kvm/vcpu.c
> +++ b/arch/loongarch/kvm/vcpu.c
> @@ -1465,6 +1465,9 @@ int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu, struct kvm_interrupt *irq)
> if (vector >= EXCCODE_INT_NUM)
> return -EINVAL;
>
> + if (kvm_arch_irqchip_in_kernel(vcpu->kvm))
> + return -EINVAL;
> +
[Severity: High]
This is a pre-existing issue, but I noticed there are several WARN_ONCE and
WARN_ON_ONCE macros reachable by unprivileged host userspace and malicious
guests in this subsystem.
For example, in kvm_vcpu_ioctl_interrupt(), providing an intr == 0
unconditionally hits a fallback block that calls:
WARN_ONCE(1, "%s: invalid interrupt ioctl %d\n", __func__, irq->irq);
Similarly, in ipi_send() and eiointc_update_irq(), guest-controlled CPU IDs
can yield a NULL vCPU, directly triggering:
WARN_ONCE(1, "%s: invalid target cpu: %d\n", __func__, cpu);
And in loongarch_ipi_readl(), a guest unaligned MMIO read triggers:
WARN_ON_ONCE(offset & (len - 1));
Could these be converted to pr_warn_once(), return an error, or drop the
assertions entirely? These could allow a host-side denial of service if
panic_on_warn is enabled.
> if (!kvm_guest_has_msgint(&vcpu->arch) && (vector == INT_AVEC))
> return -EINVAL;
>
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260629023213.597030-1-maobibo@loongson.cn?part=3
prev parent reply other threads:[~2026-06-29 2:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-29 2:32 [PATCH v3 0/3] LoongArch: KVM: Harden interrupt injection Bibo Mao
2026-06-29 2:32 ` [PATCH v3 1/3] LoongArch: KVM: Set default MAILBOX access size with 8 Bibo Mao
2026-06-29 2:45 ` sashiko-bot
2026-06-29 2:32 ` [PATCH v3 2/3] LoongArch: KVM: Replace kvm_err() with WARN_ONCE() Bibo Mao
2026-06-29 2:37 ` sashiko-bot
2026-06-30 4:27 ` Huacai Chen
2026-06-29 2:32 ` [PATCH v3 3/3] LoongArch: KVM: Use internal API to deliver interrupt in kernel mode Bibo Mao
2026-06-29 2:41 ` 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=20260629024137.2F3391F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=maobibo@loongson.cn \
--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