]> git.hungrycats.org Git - linux/commitdiff
KVM: x86/mmu: Bug the VM if KVM calcs a CPU role with EFER.LMA=1 && CR4.PAE=0
authorSean Christopherson <seanjc@google.com>
Wed, 2 Sep 2026 23:20:27 +0000 (16:20 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 6 Nov 2026 17:06:09 +0000 (12:06 -0500)
commit 34dacbe7ae93f2d3c26cd0bf3e08200b1fa2c180 upstream.

Bug the VM if KVM attempts to construct a CPU role with the should-be-
impossible combination of long mode being active without PAE paging being
enabled.  KVM's MMU construction assumes that EFER.LMA can be set if and
only CR4.PAE is set, and will create a completely invalid MMU if that
assumption fails.  FNAME(walk_addr_generic) already has sanity checks to
try and mitigate the fallout, but attempt to catch such bugs earlier, as
this is (at least) the second time KVM has had bugs that escaped into
FNAME(walk_addr_generic), and it's entirely possible the bad state could
cause problems elsewhere.

Cc: stable@vger.kernel.org
Link: https://patch.msgid.link/20260902232028.2767071-5-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/x86/kvm/mmu/mmu.c

index d365bba579d280728c55f4e025549e0786b1c7ff..551d707a4f27bb0c315c098bddbb0b4924ed6e6f 100644 (file)
@@ -5639,6 +5639,9 @@ static union kvm_cpu_role kvm_calc_cpu_role(struct kvm_vcpu *vcpu,
                return role;
        }
 
+       if (KVM_BUG_ON(____is_efer_lma(regs) && !____is_cr4_pae(regs), vcpu->kvm))
+               *(u64 *)&regs->efer &= ~EFER_LMA;
+
        role.base.efer_nx = ____is_efer_nx(regs);
        role.base.cr0_wp = ____is_cr0_wp(regs);
        role.base.smep_andnot_wp = ____is_cr4_smep(regs) && !____is_cr0_wp(regs);