Skip to content

Commit 886bbcc

Browse files
sean-jcbonzini
authored andcommitted
KVM: x86: Check CR3 GPA for validity regardless of vCPU mode
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: 660a5d5 ("KVM: x86: save/load state on SMM switch") Cc: [email protected] Signed-off-by: Sean Christopherson <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent d0fe7b6 commit 886bbcc

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

arch/x86/kvm/x86.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,10 +1077,15 @@ int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
10771077
return 0;
10781078
}
10791079

1080-
if (is_long_mode(vcpu) && kvm_vcpu_is_illegal_gpa(vcpu, cr3))
1080+
/*
1081+
* Do not condition the GPA check on long mode, this helper is used to
1082+
* stuff CR3, e.g. for RSM emulation, and there is no guarantee that
1083+
* the current vCPU mode is accurate.
1084+
*/
1085+
if (kvm_vcpu_is_illegal_gpa(vcpu, cr3))
10811086
return 1;
1082-
else if (is_pae_paging(vcpu) &&
1083-
!load_pdptrs(vcpu, vcpu->arch.walk_mmu, cr3))
1087+
1088+
if (is_pae_paging(vcpu) && !load_pdptrs(vcpu, vcpu->arch.walk_mmu, cr3))
10841089
return 1;
10851090

10861091
kvm_mmu_new_pgd(vcpu, cr3, skip_tlb_flush, skip_tlb_flush);

0 commit comments

Comments
 (0)