KVM: nVMX: avoid NULL pointer dereference with incorrect EVMCS GPAs
linmiaohe
Reviewed-byHi:
Quoted 10 lines · Vitaly Kuznetsov
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_vmptrcondition in
nested_vmx_handle_enlightened_vmptrld()will evaluate to false (as nested.hv_evmcs_vmptr is zeroed after init). The crash will happen onvmx->nested.hv_evmcspointer 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 tryingkvm_vcpu_map()when nested.hv_evmcs is NULL and this is supposed to catch all invalid EVMCS GPAs.
Quoted 7 lines
Also, initialize
hv_evmcs_vmptrto '0' innested_release_evmcs()to be consistent with initialization where we don't currently sethv_evmcs_vmptrto '-1'.Signed-off-by Vitaly Kuznetsov <[email protected]>---
arch/x86/kvm/vmx/nested.c| 5 +++--1 file changed, 3 insertions(+), 2 deletions(-)
Good catch! Patch looks good for me. Thanks!