Skip to content

Commit

Permalink
KVM: nVMX: Fix size checks in vmx_set_nested_state
Browse files Browse the repository at this point in the history
The size checks in vmx_nested_state are wrong because the calculations
are made based on the size of a pointer to a struct kvm_nested_state
rather than the size of a struct kvm_nested_state.

Reported-by: Felix Wilhelm  <[email protected]>
Signed-off-by: Jim Mattson <[email protected]>
Reviewed-by: Drew Schmitt <[email protected]>
Reviewed-by: Marc Orr <[email protected]>
Reviewed-by: Peter Shier <[email protected]>
Reviewed-by: Krish Sadhukhan <[email protected]>
Fixes: 8fcc4b5
Cc: [email protected]
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
jsmattsonjr authored and bonzini committed Apr 30, 2019
1 parent 6245242 commit e8ab8d2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions arch/x86/kvm/vmx/nested.c
Original file line number Diff line number Diff line change
Expand Up @@ -5423,7 +5423,7 @@ static int vmx_set_nested_state(struct kvm_vcpu *vcpu,
return ret;

/* Empty 'VMXON' state is permitted */
if (kvm_state->size < sizeof(kvm_state) + sizeof(*vmcs12))
if (kvm_state->size < sizeof(*kvm_state) + sizeof(*vmcs12))
return 0;

if (kvm_state->vmx.vmcs_pa != -1ull) {
Expand Down Expand Up @@ -5467,7 +5467,7 @@ static int vmx_set_nested_state(struct kvm_vcpu *vcpu,
vmcs12->vmcs_link_pointer != -1ull) {
struct vmcs12 *shadow_vmcs12 = get_shadow_vmcs12(vcpu);

if (kvm_state->size < sizeof(kvm_state) + 2 * sizeof(*vmcs12))
if (kvm_state->size < sizeof(*kvm_state) + 2 * sizeof(*vmcs12))
return -EINVAL;

if (copy_from_user(shadow_vmcs12,
Expand Down

0 comments on commit e8ab8d2

Please sign in to comment.