LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 0/6] KVM: nVMX: propperly handle enlightened vmptrld failure conditions
@ 2020-03-09 15:52 Vitaly Kuznetsov
  2020-03-09 15:52 ` [PATCH 1/6] KVM: nVMX: avoid NULL pointer dereference with incorrect EVMCS GPAs Vitaly Kuznetsov
                   ` (6 more replies)
  0 siblings, 7 replies; 13+ messages in thread
From: Vitaly Kuznetsov @ 2020-03-09 15:52 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Jim Mattson, Sean Christopherson, kvm, linux-kernel, Liran Alon,
	Miaohe Lin

Miaohe Lin noticed that we incorrectly handle enlightened vmptrld failures
in nested_vmx_run(). Trying to handle errors correctly, I fixed
a few things:
- NULL pointer dereference with invalid eVMCS GPAs [PATCH1]
- moved eVMCS mapping after migration to nested_get_vmcs12_pages() from
  nested_sync_vmcs12_to_shadow() [PATCH2]
- added propper nested_vmx_handle_enlightened_vmptrld() error handling
  [PATCH3]
- added selftests for incorrect eVMCS revision id and GPA [PATCHes4-6]

PATCH1 fixes a DoS and thus marked for stable@.

Vitaly Kuznetsov (6):
  KVM: nVMX: avoid NULL pointer dereference with incorrect EVMCS GPAs
  KVM: nVMX: stop abusing need_vmcs12_to_shadow_sync for eVMCS mapping
  KVM: nVMX: properly handle errors in
    nested_vmx_handle_enlightened_vmptrld()
  KVM: selftests: define and use EVMCS_VERSION
  KVM: selftests: test enlightened vmenter with wrong eVMCS version
  KVM: selftests: enlightened VMPTRLD with an incorrect GPA

 arch/x86/kvm/vmx/evmcs.h                      |  7 ++
 arch/x86/kvm/vmx/nested.c                     | 64 +++++++++++++------
 tools/testing/selftests/kvm/include/evmcs.h   |  2 +
 tools/testing/selftests/kvm/lib/x86_64/vmx.c  |  2 +-
 .../testing/selftests/kvm/x86_64/evmcs_test.c | 25 ++++++--
 5 files changed, 72 insertions(+), 28 deletions(-)

-- 
2.24.1


^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: [PATCH 1/6] KVM: nVMX: avoid NULL pointer dereference with incorrect EVMCS GPAs
@ 2020-03-10  2:15 linmiaohe
  0 siblings, 0 replies; 13+ messages in thread
From: linmiaohe @ 2020-03-10  2:15 UTC (permalink / raw)
  To: Vitaly Kuznetsov
  Cc: Paolo Bonzini, Jim Mattson, Sean Christopherson, kvm,
	linux-kernel, Liran Alon

Hi:
Vitaly Kuznetsov <vkuznets@redhat.com> writes:
>When an EVMCS enabled L1 guest on KVM will tries doing enlightened VMEnter with EVMCS GPA = 0 the host crashes because the
>
>evmcs_gpa != vmx->nested.hv_evmcs_vmptr
>
>condition in nested_vmx_handle_enlightened_vmptrld() will evaluate to false (as nested.hv_evmcs_vmptr is zeroed after init). The crash will happen on vmx->nested.hv_evmcs pointer dereference.
>
>Another problematic EVMCS ptr value is '-1' but it only causes host crash after nested_release_evmcs() invocation. The problem is exactly the same as with '0', we mistakenly think that the EVMCS pointer hasn't changed and thus nested.hv_evmcs_vmptr is valid.
>
>Resolve the issue by adding an additional !vmx->nested.hv_evmcs check to nested_vmx_handle_enlightened_vmptrld(), this way we will always be trying kvm_vcpu_map() when nested.hv_evmcs is NULL and this is supposed to catch all invalid EVMCS GPAs.
>
>Also, initialize hv_evmcs_vmptr to '0' in nested_release_evmcs() to be consistent with initialization where we don't currently set hv_evmcs_vmptr to '-1'.
>
>Cc: stable@vger.kernel.org
>Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
>---
> arch/x86/kvm/vmx/nested.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)

Good catch! Patch looks good for me. Thanks!
Reviewed-by: Miaohe Lin <linmiaohe@huawei.com>


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-03-15  3:56 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-09 15:52 [PATCH 0/6] KVM: nVMX: propperly handle enlightened vmptrld failure conditions Vitaly Kuznetsov
2020-03-09 15:52 ` [PATCH 1/6] KVM: nVMX: avoid NULL pointer dereference with incorrect EVMCS GPAs Vitaly Kuznetsov
2020-03-09 15:52 ` [PATCH 2/6] KVM: nVMX: stop abusing need_vmcs12_to_shadow_sync for eVMCS mapping Vitaly Kuznetsov
2020-03-09 15:52 ` [PATCH 3/6] KVM: nVMX: properly handle errors in nested_vmx_handle_enlightened_vmptrld() Vitaly Kuznetsov
2020-03-10 20:08   ` kbuild test robot
2020-03-10 20:08   ` [RFC PATCH] KVM: nVMX: nested_vmx_handle_enlightened_vmptrld() can be static kbuild test robot
2020-03-11 11:49     ` Vitaly Kuznetsov
2020-03-11 17:45       ` Paolo Bonzini
2020-03-09 15:52 ` [PATCH 4/6] KVM: selftests: define and use EVMCS_VERSION Vitaly Kuznetsov
2020-03-09 15:52 ` [PATCH 5/6] KVM: selftests: test enlightened vmenter with wrong eVMCS version Vitaly Kuznetsov
2020-03-09 15:52 ` [PATCH 6/6] KVM: selftests: enlightened VMPTRLD with an incorrect GPA Vitaly Kuznetsov
2020-03-14 11:52 ` [PATCH 0/6] KVM: nVMX: propperly handle enlightened vmptrld failure conditions Paolo Bonzini
2020-03-10  2:15 [PATCH 1/6] KVM: nVMX: avoid NULL pointer dereference with incorrect EVMCS GPAs linmiaohe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).