From: David Hildenbrand <david@redhat.com>
To: Mark Kanda <mark.kanda@oracle.com>, kvm@vger.kernel.org
Cc: pbonzini@redhat.com, rkrcmar@redhat.com, ameya.more@oracle.com,
krish.sadhukhan@oracle.com
Subject: Re: [PATCH v2 2/2] KVM: nVMX: Add a WARN for freeing a loaded VMCS02
Date: Tue, 28 Nov 2017 21:50:31 +0100 [thread overview]
Message-ID: <14fbdd78-e90f-1182-4617-65de6ceb2cfd@redhat.com> (raw)
In-Reply-To: <478de389bde1075168d7ea49ee3903674c872339.1511824198.git.mark.kanda@oracle.com>
On 28.11.2017 00:22, Mark Kanda wrote:
> 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>
> ---
> arch/x86/kvm/vmx.c | 17 +++++++++++++++--
> 1 file changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index f348445..5b2cc5f 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -3843,6 +3843,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;
> @@ -7187,7 +7200,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;
> @@ -7358,7 +7371,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 */
>
Reviewed-by: David Hildenbrand <david@redhat.com>
--
Thanks,
David / dhildenb
next prev parent reply other threads:[~2017-11-28 20:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-27 23:22 [PATCH v2 0/2] KVM: nVMX: misc changes Mark Kanda
2017-11-27 23:22 ` [PATCH v2 1/2] KVM: nVMX: Eliminate vmcs02 pool Mark Kanda
2017-11-27 23:22 ` [PATCH v2 2/2] KVM: nVMX: Add a WARN for freeing a loaded VMCS02 Mark Kanda
2017-11-28 20:50 ` David Hildenbrand [this message]
2017-11-28 10:41 ` [PATCH v2 0/2] KVM: nVMX: misc changes Paolo Bonzini
2017-12-05 21:44 ` Radim Krčmář
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=14fbdd78-e90f-1182-4617-65de6ceb2cfd@redhat.com \
--to=david@redhat.com \
--cc=ameya.more@oracle.com \
--cc=krish.sadhukhan@oracle.com \
--cc=kvm@vger.kernel.org \
--cc=mark.kanda@oracle.com \
--cc=pbonzini@redhat.com \
--cc=rkrcmar@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox