KVM: nVMX: Fix size checks in vmx_set_nested_state
authorJim Mattson <jmattson@google.com>
Thu, 17 Jan 2019 19:55:58 +0000 (11:55 -0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 30 Apr 2019 22:43:44 +0000 (00:43 +0200)
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 <fwilhelm@google.com>
Signed-off-by: Jim Mattson <jmattson@google.com>
Reviewed-by: Drew Schmitt <dasch@google.com>
Reviewed-by: Marc Orr <marcorr@google.com>
Reviewed-by: Peter Shier <pshier@google.com>
Reviewed-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
Fixes: 8fcc4b5923af5de58b80b53a069453b135693304
Cc: stable@ver.kernel.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/vmx/nested.c

index 6401eb7ef19ce0e9f9258b617e001dfdac534a2a..0c601d079cd20e4975f58c0f4fca35c36abbc9f9 100644 (file)
@@ -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) {
@@ -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,