From: Huacai Chen <chenhuacai@kernel.org>
To: Bibo Mao <maobibo@loongson.cn>
Cc: Huacai Chen <chenhuacai@loongson.cn>,
Paolo Bonzini <pbonzini@redhat.com>,
Tianrui Zhao <zhaotianrui@loongson.cn>,
kvm@vger.kernel.org, loongarch@lists.linux.dev,
linux-kernel@vger.kernel.org, Xuerui Wang <kernel@xen0n.name>,
Jiaxun Yang <jiaxun.yang@flygoat.com>,
stable@vger.kernel.org, Aurelien Jarno <aurel32@debian.org>
Subject: Re: [PATCH 1/2] LoongArch: KVM: Make kvm_get_vcpu_by_cpuid() more robust
Date: Mon, 23 Mar 2026 15:08:24 +0800 [thread overview]
Message-ID: <CAAhV-H7rFtju3k=NYkAy6-O7f8U=CTNiryu2_Kr57pScjeH-yQ@mail.gmail.com> (raw)
In-Reply-To: <676198e5-78e4-ab41-e447-4a9d24655890@loongson.cn>
On Mon, Mar 23, 2026 at 11:16 AM Bibo Mao <maobibo@loongson.cn> wrote:
>
>
>
> On 2026/3/22 下午9:53, Huacai Chen wrote:
> > kvm_get_vcpu_by_cpuid() takes a cpuid parameter whose type is int, so
> > cpuid can be negative. Let kvm_get_vcpu_by_cpuid() return NULL for this
> > case so as to make it more robust.
> >
> > This fix an out-of-bounds access to kvm_arch::phyid_map::phys_map[].
> >
> > Cc: <stable@vger.kernel.org>
> > Fixes: 73516e9da512adc ("LoongArch: KVM: Add vcpu mapping from physical cpuid")
> > Reported-by: Aurelien Jarno <aurel32@debian.org>
> > Link: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1131431
> > Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
> > ---
> > arch/loongarch/kvm/vcpu.c | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c
> > index 8ffd50a470e6..831f381a8fd1 100644
> > --- a/arch/loongarch/kvm/vcpu.c
> > +++ b/arch/loongarch/kvm/vcpu.c
> > @@ -588,6 +588,9 @@ struct kvm_vcpu *kvm_get_vcpu_by_cpuid(struct kvm *kvm, int cpuid)
> > {
> > struct kvm_phyid_map *map;
> >
> > + if (cpuid < 0)
> > + return NULL;
> > +
> > if (cpuid >= KVM_MAX_PHYID)
> > return NULL;
> >
> >
>
> if (cpuid < 0 || cpuid >= KVM_MAX_PHYID)?
> however both are OK for me.
I use a similar style as kvm_get_vcpu_by_id(). :)
But there is another warning which can't be solved by this series (and
I doubt whether it can be solved unless revert 01a8e68396a6d51f5b).
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1131431
Huacai
>
> Reviewed-by: Bibo Mao <maobibo@loongson.cn>
>
next prev parent reply other threads:[~2026-03-23 7:08 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-22 13:53 [PATCH 1/2] LoongArch: KVM: Make kvm_get_vcpu_by_cpuid() more robust Huacai Chen
2026-03-22 13:53 ` [PATCH 2/2] LoongArch: KVM: Handle the case that EIOINTC's coremap is empty Huacai Chen
2026-03-23 3:14 ` Bibo Mao
2026-03-23 3:13 ` [PATCH 1/2] LoongArch: KVM: Make kvm_get_vcpu_by_cpuid() more robust Bibo Mao
2026-03-23 7:08 ` Huacai Chen [this message]
2026-03-23 7:56 ` Bibo Mao
2026-03-23 8:08 ` Bibo Mao
2026-03-23 8:14 ` Huacai Chen
2026-03-23 9:40 ` Bibo Mao
2026-03-23 18:36 ` Aurelien Jarno
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='CAAhV-H7rFtju3k=NYkAy6-O7f8U=CTNiryu2_Kr57pScjeH-yQ@mail.gmail.com' \
--to=chenhuacai@kernel.org \
--cc=aurel32@debian.org \
--cc=chenhuacai@loongson.cn \
--cc=jiaxun.yang@flygoat.com \
--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=pbonzini@redhat.com \
--cc=stable@vger.kernel.org \
--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