]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
KVM: x86: Check CR3 GPA for validity regardless of vCPU mode
authorSean Christopherson <seanjc@google.com>
Thu, 22 Apr 2021 02:21:21 +0000 (19:21 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 14 May 2021 08:52:11 +0000 (10:52 +0200)
commit 886bbcc7a523b8d4fac60f1015d2e0fcad50db82 upstream.

Check CR3 for an invalid GPA even if the vCPU isn't in long mode.  For
bigger emulation flows, notably RSM, the vCPU mode may not be accurate
if CR0/CR4 are loaded after CR3.  For MOV CR3 and similar flows, the
caller is responsible for truncating the value.

Fixes: 660a5d517aaa ("KVM: x86: save/load state on SMM switch")
Cc: stable@vger.kernel.org
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20210422022128.3464144-3-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/x86/kvm/x86.c

index 5aa61c22fa6ec0041eccf4b0488a4818fb7776fa..3406ff421c1a3c69f38caec474ba887d5cbb0e72 100644 (file)
@@ -1072,10 +1072,15 @@ int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
                return 0;
        }
 
-       if (is_long_mode(vcpu) && kvm_vcpu_is_illegal_gpa(vcpu, cr3))
+       /*
+        * Do not condition the GPA check on long mode, this helper is used to
+        * stuff CR3, e.g. for RSM emulation, and there is no guarantee that
+        * the current vCPU mode is accurate.
+        */
+       if (kvm_vcpu_is_illegal_gpa(vcpu, cr3))
                return 1;
-       else if (is_pae_paging(vcpu) &&
-                !load_pdptrs(vcpu, vcpu->arch.walk_mmu, cr3))
+
+       if (is_pae_paging(vcpu) && !load_pdptrs(vcpu, vcpu->arch.walk_mmu, cr3))
                return 1;
 
        kvm_mmu_new_pgd(vcpu, cr3, skip_tlb_flush, skip_tlb_flush);