Skip to content

Commit 90a8772

Browse files
Maxim Levitskysean-jc
authored andcommitted
KVM: nVMX: fix canonical check of vmcs12 HOST_RIP
HOST_RIP canonical check should check the L1 of CR4.LA57 stored in the vmcs12 rather than the current L1's because it is legal to change the CR4.LA57 value during VM exit from L2 to L1. This is a theoretical bug though, because it is highly unlikely that a VM exit will change the CR4.LA57 from the value it had on VM entry. Signed-off-by: Maxim Levitsky <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 9245fd6 commit 90a8772

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

arch/x86/kvm/vmx/nested.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2996,6 +2996,17 @@ static int nested_vmx_check_address_space_size(struct kvm_vcpu *vcpu,
29962996
return 0;
29972997
}
29982998

2999+
static bool is_l1_noncanonical_address_on_vmexit(u64 la, struct vmcs12 *vmcs12)
3000+
{
3001+
/*
3002+
* Check that the given linear address is canonical after a VM exit
3003+
* from L2, based on HOST_CR4.LA57 value that will be loaded for L1.
3004+
*/
3005+
u8 l1_address_bits_on_exit = (vmcs12->host_cr4 & X86_CR4_LA57) ? 57 : 48;
3006+
3007+
return !__is_canonical_address(la, l1_address_bits_on_exit);
3008+
}
3009+
29993010
static int nested_vmx_check_host_state(struct kvm_vcpu *vcpu,
30003011
struct vmcs12 *vmcs12)
30013012
{
@@ -3046,7 +3057,7 @@ static int nested_vmx_check_host_state(struct kvm_vcpu *vcpu,
30463057
CC(is_noncanonical_base_address(vmcs12->host_gdtr_base, vcpu)) ||
30473058
CC(is_noncanonical_base_address(vmcs12->host_idtr_base, vcpu)) ||
30483059
CC(is_noncanonical_base_address(vmcs12->host_tr_base, vcpu)) ||
3049-
CC(is_noncanonical_address(vmcs12->host_rip, vcpu, 0)))
3060+
CC(is_l1_noncanonical_address_on_vmexit(vmcs12->host_rip, vmcs12)))
30503061
return -EINVAL;
30513062

30523063
/*

0 commit comments

Comments
 (0)