Skip to content

Commit 2ab637d

Browse files
vittyvksean-jc
authored andcommitted
KVM: VMX: hyper-v: Prevent impossible NULL pointer dereference in evmcs_load()
GCC 12.3.0 complains about a potential NULL pointer dereference in evmcs_load() as hv_get_vp_assist_page() can return NULL. In fact, this cannot happen because KVM verifies (hv_init_evmcs()) that every CPU has a valid VP assist page and aborts enabling the feature otherwise. CPU onlining path is also checked in vmx_hardware_enable(). To make the compiler happy and to future proof the code, add a KVM_BUG_ON() sentinel. It doesn't seem to be possible (and logical) to observe evmcs_load() happening without an active vCPU so it is presumed that kvm_get_running_vcpu() can't return NULL. No functional change intended. Reported-by: Mirsad Todorovac <[email protected]> Suggested-by: Sean Christopherson <[email protected]> Signed-off-by: Vitaly Kuznetsov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 41ab0d5 commit 2ab637d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

arch/x86/kvm/vmx/vmx_onhyperv.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ static inline void evmcs_load(u64 phys_addr)
104104
struct hv_vp_assist_page *vp_ap =
105105
hv_get_vp_assist_page(smp_processor_id());
106106

107+
/*
108+
* When enabling eVMCS, KVM verifies that every CPU has a valid hv_vp_assist_page()
109+
* and aborts enabling the feature otherwise. CPU onlining path is also checked in
110+
* vmx_hardware_enable().
111+
*/
112+
if (KVM_BUG_ON(!vp_ap, kvm_get_running_vcpu()->kvm))
113+
return;
114+
107115
if (current_evmcs->hv_enlightenments_control.nested_flush_hypercall)
108116
vp_ap->nested_control.features.directhypercall = 1;
109117
vp_ap->current_nested_vmcs = phys_addr;

0 commit comments

Comments
 (0)