* [PATCH v2 0/2] KVM: x86: Ensure userspace can't run L2 with stale PFNs
@ 2026-09-21 21:16 Sean Christopherson
2026-09-21 21:16 ` [PATCH v2 1/2] KVM: x86: Re-pend GET_NESTED_STATE_PAGES if getting said pages fails Sean Christopherson
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Sean Christopherson @ 2026-09-21 21:16 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini
Cc: kvm, linux-kernel, Jinwoo Lee, Stefan Teodorescu
Fix a class of bugs where KVM (a) lets userspace run L2 with potentially stale
PFNs and (b) fails to set kvm_run appropriately and so could unintentionally
cause a well-behaved VMM to run afoul of (a).
v2:
- Re-pend KVM_REQ_GET_NESTED_STATE_PAGES in the common vcpu_enter_guest()
path.
- Fix the kvm_run bug(s).
v1: https://lore.kernel.org/all/20260813043932.3214460-1-rkskek9254@gmail.com
Sean Christopherson (2):
KVM: x86: Re-pend GET_NESTED_STATE_PAGES if getting said pages fails
KVM: x86: Fill kvm_run exit fields in common get_nested_state_pages()
error paths
arch/x86/kvm/svm/nested.c | 7 +------
arch/x86/kvm/vmx/nested.c | 15 +++++----------
arch/x86/kvm/x86.c | 4 ++++
3 files changed, 10 insertions(+), 16 deletions(-)
base-commit: 70c944caf570fda2d79baa71435589a8db39f048
--
2.55.0.1082.g2b9226bbc0-goog
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/2] KVM: x86: Re-pend GET_NESTED_STATE_PAGES if getting said pages fails
2026-09-21 21:16 [PATCH v2 0/2] KVM: x86: Ensure userspace can't run L2 with stale PFNs Sean Christopherson
@ 2026-09-21 21:16 ` Sean Christopherson
2026-09-21 21:16 ` [PATCH v2 2/2] KVM: x86: Fill kvm_run exit fields in common get_nested_state_pages() error paths Sean Christopherson
2026-09-24 21:52 ` [PATCH v2 0/2] KVM: x86: Ensure userspace can't run L2 with stale PFNs Sean Christopherson
2 siblings, 0 replies; 4+ messages in thread
From: Sean Christopherson @ 2026-09-21 21:16 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini
Cc: kvm, linux-kernel, Jinwoo Lee, Stefan Teodorescu
Re-pend GET_NESTED_STATE_PAGES before exiting to userspace if getting the
nested pages fails in the KVM_RUN path. If userspace re-runs the vCPU, and
vmcs02 holds valid PFNs from the *previous* run of L2, then KVM could
re-enter L2 with stale, unpinned PFNs mapped into e.g. the vAPIC page.
Note, both SVM and VMX (as of commit 11722439fb20 ("KVM: nVMX: Ensure
KVM_REQ_GET_NESTED_STATE_PAGES is cleared on VM-Exit") ensure the request
is cleared on VM-Exit (including the "forced" case), i.e. there is no risk
of double-mapping due to emulated VMLAUNCH/VMRESUME/VMRUN *and* the request
trying to map the nested pages.
Fixes: 671ddc700fd0 ("KVM: nVMX: Don't leak L1 MMIO regions to L2")
Cc: stable@vger.kernel.org
Reported-by: Jinwoo Lee <rkskek9254@gmail.com>
Closes: https://lore.kernel.org/all/20260813043932.3214460-1-rkskek9254@gmail.com
Reported-by: Stefan Teodorescu <fane@google.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/kvm/x86.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index af3ceee714c9..3c5d3e19ec99 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -8024,6 +8024,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
if (kvm_check_request(KVM_REQ_GET_NESTED_STATE_PAGES, vcpu)) {
if (unlikely(!kvm_nested_call(get_nested_state_pages)(vcpu))) {
+ kvm_make_request(KVM_REQ_GET_NESTED_STATE_PAGES, vcpu);
r = 0;
goto out;
}
--
2.55.0.1082.g2b9226bbc0-goog
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 2/2] KVM: x86: Fill kvm_run exit fields in common get_nested_state_pages() error paths
2026-09-21 21:16 [PATCH v2 0/2] KVM: x86: Ensure userspace can't run L2 with stale PFNs Sean Christopherson
2026-09-21 21:16 ` [PATCH v2 1/2] KVM: x86: Re-pend GET_NESTED_STATE_PAGES if getting said pages fails Sean Christopherson
@ 2026-09-21 21:16 ` Sean Christopherson
2026-09-24 21:52 ` [PATCH v2 0/2] KVM: x86: Ensure userspace can't run L2 with stale PFNs Sean Christopherson
2 siblings, 0 replies; 4+ messages in thread
From: Sean Christopherson @ 2026-09-21 21:16 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini
Cc: kvm, linux-kernel, Jinwoo Lee, Stefan Teodorescu
Fill kvm_run with "internal error, emulation" in the common error handling
paths for getting nested state pages, as requiring each check to manually
fill kvm_run is error prone and requires a non-trivial amount of copy+paste.
Specifically, both SVM and VMX fail to fill kvm_run if load_pdptrs() fails,
and SVM fails to fill kvm_run if kvm_hv_verify_vp_assist() fails. If those
flows fail, the *best* case scenario is that KVM will exit to userspace
with KVM_EXIT_UNKNOWN. The worst case scenario is that KVM exits with a
stale exit_reason and confuses userspace.
Note, SVM never exits to userspace if something goes sideways when dealing
with vmcb12 assets while emulating VMRUN, i.e. lack of SVM-specific code is
not a bug.
Fixes: 0f85722341b0 ("KVM: nVMX: delay loading of PDPTRs to KVM_REQ_GET_NESTED_STATE_PAGES")
Fixes: 232f75d3b4b5 ("KVM: nSVM: call nested_svm_load_cr3 on nested state load")
Fixes: 3f4a812edf5c ("KVM: nSVM: hyper-v: Enable L2 TLB flush")
Cc: stable@vger.kernel.org
Reported-by: Jinwoo Lee <rkskek9254@gmail.com>
Closes: https://lore.kernel.org/all/20260813043932.3214460-1-rkskek9254@gmail.com
Reported-by: Stefan Teodorescu <fane@google.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/kvm/svm/nested.c | 7 +------
arch/x86/kvm/vmx/nested.c | 15 +++++----------
arch/x86/kvm/x86.c | 3 +++
3 files changed, 9 insertions(+), 16 deletions(-)
diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
index 23d29597d6bf..82c49a24dd75 100644
--- a/arch/x86/kvm/svm/nested.c
+++ b/arch/x86/kvm/svm/nested.c
@@ -2130,13 +2130,8 @@ static bool svm_get_nested_state_pages(struct kvm_vcpu *vcpu)
return false;
}
- if (!nested_svm_merge_msrpm(vcpu)) {
- vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
- vcpu->run->internal.suberror =
- KVM_INTERNAL_ERROR_EMULATION;
- vcpu->run->internal.ndata = 0;
+ if (!nested_svm_merge_msrpm(vcpu))
return false;
- }
if (kvm_hv_verify_vp_assist(vcpu))
return false;
diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index 0e5f4d7ce9eb..56fbe73a44dc 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -3465,10 +3465,6 @@ static bool nested_get_vmcs12_pages(struct kvm_vcpu *vcpu)
} else {
pr_debug_ratelimited("%s: no backing for APIC-access address in vmcs12\n",
__func__);
- vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
- vcpu->run->internal.suberror =
- KVM_INTERNAL_ERROR_EMULATION;
- vcpu->run->internal.ndata = 0;
return false;
}
}
@@ -3539,11 +3535,6 @@ static bool vmx_get_nested_state_pages(struct kvm_vcpu *vcpu)
if (!nested_get_evmcs_page(vcpu)) {
pr_debug_ratelimited("%s: enlightened vmptrld failed\n",
__func__);
- vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
- vcpu->run->internal.suberror =
- KVM_INTERNAL_ERROR_EMULATION;
- vcpu->run->internal.ndata = 0;
-
return false;
}
#endif
@@ -3915,8 +3906,12 @@ static int nested_vmx_run(struct kvm_vcpu *vcpu, bool launch)
vmentry_failed:
vcpu->arch.nested_run_pending = 0;
- if (status == NVMX_VMENTRY_KVM_INTERNAL_ERROR)
+ if (status == NVMX_VMENTRY_KVM_INTERNAL_ERROR) {
+ vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
+ vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION;
+ vcpu->run->internal.ndata = 0;
return 0;
+ }
if (status == NVMX_VMENTRY_VMEXIT)
return 1;
WARN_ON_ONCE(status != NVMX_VMENTRY_VMFAIL);
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 3c5d3e19ec99..e9684abae4d8 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -8024,6 +8024,9 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
if (kvm_check_request(KVM_REQ_GET_NESTED_STATE_PAGES, vcpu)) {
if (unlikely(!kvm_nested_call(get_nested_state_pages)(vcpu))) {
+ vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
+ vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION;
+ vcpu->run->internal.ndata = 0;
kvm_make_request(KVM_REQ_GET_NESTED_STATE_PAGES, vcpu);
r = 0;
goto out;
--
2.55.0.1082.g2b9226bbc0-goog
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 0/2] KVM: x86: Ensure userspace can't run L2 with stale PFNs
2026-09-21 21:16 [PATCH v2 0/2] KVM: x86: Ensure userspace can't run L2 with stale PFNs Sean Christopherson
2026-09-21 21:16 ` [PATCH v2 1/2] KVM: x86: Re-pend GET_NESTED_STATE_PAGES if getting said pages fails Sean Christopherson
2026-09-21 21:16 ` [PATCH v2 2/2] KVM: x86: Fill kvm_run exit fields in common get_nested_state_pages() error paths Sean Christopherson
@ 2026-09-24 21:52 ` Sean Christopherson
2 siblings, 0 replies; 4+ messages in thread
From: Sean Christopherson @ 2026-09-24 21:52 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini
Cc: kvm, linux-kernel, Jinwoo Lee, Stefan Teodorescu
On Mon, 21 Sep 2026 14:16:06 -0700, Sean Christopherson wrote:
> Fix a class of bugs where KVM (a) lets userspace run L2 with potentially stale
> PFNs and (b) fails to set kvm_run appropriately and so could unintentionally
> cause a well-behaved VMM to run afoul of (a).
>
> v2:
> - Re-pend KVM_REQ_GET_NESTED_STATE_PAGES in the common vcpu_enter_guest()
> path.
> - Fix the kvm_run bug(s).
>
> [...]
Applied to kvm-x86 fixes, thanks!
[1/2] KVM: x86: Re-pend GET_NESTED_STATE_PAGES if getting said pages fails
https://github.com/kvm-x86/linux/commit/10180a277549
[2/2] KVM: x86: Fill kvm_run exit fields in common get_nested_state_pages() error paths
https://github.com/kvm-x86/linux/commit/c1214f293d77
--
https://github.com/kvm-x86/linux/tree/next
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-09-24 21:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-21 21:16 [PATCH v2 0/2] KVM: x86: Ensure userspace can't run L2 with stale PFNs Sean Christopherson
2026-09-21 21:16 ` [PATCH v2 1/2] KVM: x86: Re-pend GET_NESTED_STATE_PAGES if getting said pages fails Sean Christopherson
2026-09-21 21:16 ` [PATCH v2 2/2] KVM: x86: Fill kvm_run exit fields in common get_nested_state_pages() error paths Sean Christopherson
2026-09-24 21:52 ` [PATCH v2 0/2] KVM: x86: Ensure userspace can't run L2 with stale PFNs Sean Christopherson
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®