Re: [PATCH] LoongArch: KVM: Fix uninitialized stack read in dmsintc_inject_irq()
From: Tao Cui
Date: Mon Nov 16 2026 - 21:24:55 EST
Hello,Daolong,
在 2026/11/17 10:03, Daolong Zhang 写道:
> In dmsintc_inject_irq(), the local array 'vector[4]' is declared on the
> stack without initialization, and each element 'vector[i]' is only
> assigned when atomic64_read(&ds->vector_map[i]) is non-zero.
>
> Whenever any of the four 64-bit words in ds->vector_map[] is zero (for
> example, when an MSI interrupt targets a single word, or when INT_AVEC
> is injected via KVM_INTERRUPT with an empty vector_map), the remaining
> elements of 'vector[]' retain uninitialized kernel stack contents. The
> subsequent checks on vector[0..3] then OR those uninitialized stack
> values into the guest's hardware LOONGARCH_CSR_ISR0..3 registers,
> injecting spurious interrupt vectors into the guest and leaking host
> kernel stack data into guest-visible CSRs.
>
> Zero-initialize 'vector[4]' on declaration to prevent reading
> uninitialized stack memory.
>
This was already fixed by commit 81aa3a58b542 ("LoongArch: KVM: Fix
uninitialized stack variable issue with dmsintc"). The loop now reads
vector[i] = old ? atomic64_xchg(&ds->vector_map[i], 0) : 0, so every
element is assigned and no uninitialized stack read is left.
Thanks,
Tao
> Fixes: 03de5eecb0f0 ("LoongArch: KVM: Add DMSINTC inject msi to vCPU")
> Signed-off-by: Daolong Zhang <dlzhangak@xxxxxxxxxxxxxx>
> ---
> arch/loongarch/kvm/intc/dmsintc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/loongarch/kvm/intc/dmsintc.c b/arch/loongarch/kvm/intc/dmsintc.c
> index de25735ce039..ef6c064e52f1 100644
> --- a/arch/loongarch/kvm/intc/dmsintc.c
> +++ b/arch/loongarch/kvm/intc/dmsintc.c
> @@ -11,7 +11,7 @@
> void dmsintc_inject_irq(struct kvm_vcpu *vcpu)
> {
> unsigned int i;
> - unsigned long vector[4], old;
> + unsigned long vector[4] = {}, old;
> struct dmsintc_state *ds = &vcpu->arch.dmsintc_state;
>
> if (!ds)