From: Tao Cui <cui.tao@linux.dev>
To: Daolong Zhang <dlzhangak@isoftstone.com>,
Tianrui Zhao <zhaotianrui@loongson.cn>,
Bibo Mao <maobibo@loongson.cn>,
Huacai Chen <chenhuacai@kernel.org>
Cc: cui.tao@linux.dev, WANG Xuerui <kernel@xen0n.name>,
Song Gao <gaosong@loongson.cn>,
kvm@vger.kernel.org, loongarch@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] LoongArch: KVM: Fix uninitialized stack read in dmsintc_inject_irq()
Date: Tue, 17 Nov 2026 10:24:38 +0800 [thread overview]
Message-ID: <300d6954-0470-4ac4-8602-67f428b12534@linux.dev> (raw)
In-Reply-To: <1794880990.6AFBB5DE.001.4jT7L63YwBz23sl@fangwg01>
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@isoftstone.com>
> ---
> 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)
prev parent reply other threads:[~2026-11-17 2:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 2:03 Daolong Zhang
2026-11-17 2:24 ` Tao Cui [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=300d6954-0470-4ac4-8602-67f428b12534@linux.dev \
--to=cui.tao@linux.dev \
--cc=chenhuacai@kernel.org \
--cc=dlzhangak@isoftstone.com \
--cc=gaosong@loongson.cn \
--cc=kernel@xen0n.name \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=maobibo@loongson.cn \
--cc=zhaotianrui@loongson.cn \
/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
all inboxes | Powered by JetHome®