Skip to content

Commit

Permalink
KVM: nVMX: Add a WARN for freeing a loaded VMCS02
Browse files Browse the repository at this point in the history
When attempting to free a loaded VMCS02, add a WARN and avoid
freeing it (to avoid use-after-free situations).

Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Mark Kanda <mark.kanda@oracle.com>
Reviewed-by: Ameya More <ameya.more@oracle.com>
Reviewed-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
  • Loading branch information
Mark Kanda authored and Paolo Bonzini committed Dec 14, 2017
1 parent 00647b4 commit 276c796
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions arch/x86/kvm/vmx.c
Original file line number Diff line number Diff line change
Expand Up @@ -3846,6 +3846,19 @@ static void free_loaded_vmcs(struct loaded_vmcs *loaded_vmcs)
WARN_ON(loaded_vmcs->shadow_vmcs != NULL);
}

static void vmx_nested_free_vmcs02(struct vcpu_vmx *vmx)
{
struct loaded_vmcs *loaded_vmcs = &vmx->nested.vmcs02;

/*
* Just leak the VMCS02 if the WARN triggers. Better than
* a use-after-free.
*/
if (WARN_ON(vmx->loaded_vmcs == loaded_vmcs))
return;
free_loaded_vmcs(loaded_vmcs);
}

static void free_kvm_area(void)
{
int cpu;
Expand Down Expand Up @@ -7203,7 +7216,7 @@ static int enter_vmx_operation(struct kvm_vcpu *vcpu)
free_page((unsigned long)vmx->nested.msr_bitmap);

out_msr_bitmap:
free_loaded_vmcs(&vmx->nested.vmcs02);
vmx_nested_free_vmcs02(vmx);

out_vmcs02:
return -ENOMEM;
Expand Down Expand Up @@ -7375,7 +7388,7 @@ static void free_nested(struct vcpu_vmx *vmx)
vmx->nested.pi_desc = NULL;
}

free_loaded_vmcs(&vmx->nested.vmcs02);
vmx_nested_free_vmcs02(vmx);
}

/* Emulate the VMXOFF instruction */
Expand Down

0 comments on commit 276c796

Please sign in to comment.