Skip to content

Commit 5e105c8

Browse files
committed
KVM: nVMX: check for invalid hdr.vmx.flags
hdr.vmx.flags is meant for future extensions to the ABI, rejecting invalid flags is necessary to avoid broken half-loads of the nVMX state. Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 0f02bd0 commit 5e105c8

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

arch/x86/kvm/vmx/nested.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6079,6 +6079,9 @@ static int vmx_set_nested_state(struct kvm_vcpu *vcpu,
60796079
~(KVM_STATE_NESTED_SMM_GUEST_MODE | KVM_STATE_NESTED_SMM_VMXON))
60806080
return -EINVAL;
60816081

6082+
if (kvm_state->hdr.vmx.flags & ~KVM_STATE_VMX_PREEMPTION_TIMER_DEADLINE)
6083+
return -EINVAL;
6084+
60826085
/*
60836086
* SMM temporarily disables VMX, so we cannot be in guest mode,
60846087
* nor can VMLAUNCH/VMRESUME be pending. Outside SMM, SMM flags

tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ void test_vmx_nested_state(struct kvm_vm *vm)
146146
state->hdr.vmx.smm.flags = 1;
147147
test_nested_state_expect_einval(vm, state);
148148

149+
/* Invalid flags are rejected. */
150+
set_default_vmx_state(state, state_sz);
151+
state->hdr.vmx.flags = ~0;
152+
test_nested_state_expect_einval(vm, state);
153+
149154
/* It is invalid to have vmxon_pa == -1ull and vmcs_pa != -1ull. */
150155
set_default_vmx_state(state, state_sz);
151156
state->hdr.vmx.vmxon_pa = -1ull;
@@ -206,6 +211,14 @@ void test_vmx_nested_state(struct kvm_vm *vm)
206211
state->flags = 0;
207212
test_nested_state(vm, state);
208213

214+
/* Invalid flags are rejected, even if no VMCS loaded. */
215+
set_default_vmx_state(state, state_sz);
216+
state->size = sizeof(*state);
217+
state->flags = 0;
218+
state->hdr.vmx.vmcs12_pa = -1;
219+
state->hdr.vmx.flags = ~0;
220+
test_nested_state_expect_einval(vm, state);
221+
209222
/* vmxon_pa cannot be the same address as vmcs_pa. */
210223
set_default_vmx_state(state, state_sz);
211224
state->hdr.vmx.vmxon_pa = 0;

0 commit comments

Comments
 (0)