]> git.hungrycats.org Git - linux/commitdiff
KVM: x86/mmu: Bug the VM if KVM attempts to walk more levels than the MMU has
authorSean Christopherson <seanjc@google.com>
Wed, 2 Sep 2026 23:20:26 +0000 (16:20 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 6 Nov 2026 17:06:09 +0000 (12:06 -0500)
commit 115f9405a2ed6d78ee7ad8436bdd638743f6d1d4 upstream.

Extend the "EFER.LMA && !CR4.PAE" check, which exists largely to guard
against KVM configuring a paging32 MMU with more than 2 levels of paging,
with a very explicit check for exactly that: that KVM isn't trying to walk
more levels of paging than the MMU template provides.  I.e. harden KVM
against all bugs that would cause KVM to generates accesses beyond the
bounds of guest_walker's arrays, regardless of how KVM ended up with the
misconfigured MMU.

Note, don't use w->cpu_role.base.level directly as the paging64 template
only provides two levels of page tables for PAE paging on 32-bit hosts, and
handles the third level by manually emulating the PDPTR access.

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

index a298955834d0be517f2b6a058956af7146cf2858..4e84b5a1eeaaad55054bf7f8d682f7f098eb0951 100644 (file)
@@ -349,13 +349,14 @@ retry_walk:
        pte_access = ~0;
 
        /*
-        * Queue a page fault for injection if this assertion fails, as callers
-        * assume that walker.fault contains sane info on a walk failure.  I.e.
-        * avoid making the situation worse by inducing even worse badness
-        * between when the assertion fails and when KVM kicks the vCPU out to
-        * userspace (because the VM is bugged).
+        * Queue a page fault for injection if any of the below assertions fail,
+        * as callers assume that walker.fault contains sane info on a walk
+        * failure.  I.e. avoid making the situation worse by inducing even
+        * worse badness between when the assertion fails and when KVM kicks
+        * the vCPU out to userspace (because the VM is bugged).
         */
-       if (KVM_BUG_ON(is_long_mode(vcpu) && !is_pae(vcpu), vcpu->kvm))
+       if (KVM_BUG_ON(is_long_mode(vcpu) && !is_pae(vcpu), vcpu->kvm) ||
+           KVM_BUG_ON(walker->max_level > PT_MAX_FULL_LEVELS, vcpu->kvm))
                goto error;
 
        ++walker->level;