From: sashiko-bot@kernel.org
To: "Dan Carpenter" <dan@pereq.eu>
Cc: kvmarm@lists.linux.dev, "Oliver Upton" <oupton@kernel.org>,
"Marc Zyngier" <maz@kernel.org>
Subject: Re: [PATCH] KVM: arm64: nv: Fix NULL dereference in kvm_inject_nested()
Date: Mon, 16 Nov 2026 14:06:38 +0000 [thread overview]
Message-ID: <sashiko-outbox-217134@kernel.org> (raw)
In-Reply-To: <avsH0lxpLIF2Ug64@stanley.mountain>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] KVM: arm64: nv: unguarded kvm_pmu_nested_transition() in
kvm_inject_nested()
--
commit 7702078604222808ef62a9f6855a5c6c2add9d59
Author: Dan Carpenter <dan@pereq.eu>
KVM: arm64: nv: Fix NULL dereference in kvm_inject_nested()
This commit guards the kvm_arch_vcpu_put() and kvm_arch_vcpu_load() calls
in kvm_inject_nested() with a check that the vCPU is currently loaded.
> diff --git a/arch/arm64/kvm/emulate-nested.c b/arch/arm64/kvm/emulate-nested.c
> index 2bec816683614..22ca735a34f69 100644
> --- a/arch/arm64/kvm/emulate-nested.c
> +++ b/arch/arm64/kvm/emulate-nested.c
> @@ -2862,7 +2862,7 @@ static int kvm_inject_nested(struct kvm_vcpu *vcpu, u64 esr_el2,
> enum exception_type type)
> {
> u64 pstate, mode;
> - bool direct_inject;
> + bool direct_inject, loaded;
>
> if (!vcpu_has_nv(vcpu)) {
> kvm_err("Unexpected call to %s for the non-nesting configuration\n",
> @@ -2891,6 +2891,7 @@ static int kvm_inject_nested(struct kvm_vcpu *vcpu, u64 esr_el2,
> }
>
> preempt_disable();
> + loaded = (vcpu->cpu != -1);
>
> vcpu_set_flag(vcpu, IN_NESTED_EXCEPTION);
>
> @@ -2900,7 +2901,8 @@ static int kvm_inject_nested(struct kvm_vcpu *vcpu, u64 esr_el2,
> */
> __kvm_adjust_pc(vcpu);
>
> - kvm_arch_vcpu_put(vcpu);
> + if (loaded)
> + kvm_arch_vcpu_put(vcpu);
>
> kvm_inject_el2_exception(vcpu, esr_el2, type);
>
> @@ -2915,7 +2917,8 @@ static int kvm_inject_nested(struct kvm_vcpu *vcpu, u64 esr_el2,
> */
> __kvm_adjust_pc(vcpu);
>
> - kvm_arch_vcpu_load(vcpu, smp_processor_id());
> + if (loaded)
> + kvm_arch_vcpu_load(vcpu, smp_processor_id());
> vcpu_clear_flag(vcpu, IN_NESTED_EXCEPTION);
>
> preempt_enable();
[Severity: High]
Can kvm_pmu_nested_transition() at the end of kvm_inject_nested() still
run when the vCPU is not loaded?
Right below preempt_enable(), kvm_inject_nested() unconditionally calls
kvm_pmu_nested_transition():
arch/arm64/kvm/emulate-nested.c:kvm_inject_nested() {
...
preempt_enable();
if (kvm_vcpu_has_pmu(vcpu))
kvm_pmu_nested_transition(vcpu);
}
When KVM_SET_VCPU_EVENTS reaches kvm_inject_nested() on an unloaded vCPU,
kvm_pmu_nested_transition() calls kvm_pmu_create_perf_event() and
kvm_vcpu_pmu_restore_guest(). If the vCPU was created with
KVM_ARM_VCPU_PMU_V3_STRICT before KVM_ARM_VCPU_PMU_V3_SET_PMU is called,
kvm_pmu_create_perf_event() -> kvm_map_pmu_event() dereferences a NULL
vcpu->kvm->arch.arm_pmu. If called before KVM_ARM_VCPU_PMU_V3_INIT, it
can also queue an uninitialized vcpu->arch.pmu.overflow_work.
Even on an initialized PMU, running kvm_pmu_nested_transition() while
unloaded binds the new perf_event to current (which may be a VMM control
thread rather than the vCPU thread) and programs the physical CPU's PMU
EL0 filters via kvm_vcpu_pmu_restore_guest() without a matching
kvm_vcpu_pmu_restore_host() before returning to userspace.
--
Sashiko AI review · https://sashiko.dev/#/patchset/avsH0lxpLIF2Ug64@stanley.mountain?part=1
next prev parent reply other threads:[~2026-11-16 14:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 13:40 [PATCH] KVM: arm64: nv: Fix NULL dereference in kvm_inject_nested() Dan Carpenter
2026-11-16 14:06 ` sashiko-bot [this message]
2026-11-16 15:27 ` Dan Carpenter
2026-11-16 18:11 ` Marc Zyngier
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=sashiko-outbox-217134@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dan@pereq.eu \
--cc=kvmarm@lists.linux.dev \
--cc=maz@kernel.org \
--cc=oupton@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.