HV: fix potential NULL function pointer reference
- 'dispatch' will be null and be referenced if
'basic_exit_reason < ARRAY_SIZE(dispatch_table)'
if false.
@@ -191,7 +191,12 @@ int vmexit_handler(struct vcpu *vcpu)
pr_dbg("Exit Reason: 0x%016llx ", vcpu->arch_vcpu.exit_reason);
/* Ensure exit reason is within dispatch table */
- if (basic_exit_reason < ARRAY_SIZE(dispatch_table)) {
+ if (basic_exit_reason >= ARRAY_SIZE(dispatch_table)) {
+ pr_err("Invalid Exit Reason: 0x%016llx ",
+ vcpu->arch_vcpu.exit_reason);
+ return -EINVAL;
+ }
+
/* Calculate dispatch table entry */
dispatch = (struct vm_exit_dispatch *)
(dispatch_table + basic_exit_reason);
@@ -204,7 +209,6 @@ int vmexit_handler(struct vcpu *vcpu)
vcpu->arch_vcpu.exit_qualification =
exec_vmread(VMX_EXIT_QUALIFICATION);
}
- }
/* Update current vcpu in VM that caused vm exit */
vcpu->vm->current_vcpu = vcpu;
