Skip to content

Commit 901a65c

Browse files
jsun26intelacrnsi
authored andcommitted
HV: inject exception for invalid vmcall
For non-trusty hypercalls, HV should inject #GP(0) to vCPU if they are from non-ring0 or inject #UD if they are from ring0 of non-SOS. Also we should not modify RAX of vCPU for these invalid vmcalls. Tracked-On: #3497 Signed-off-by: Victor Sun <victor.sun@intel.com>
1 parent c4f6681 commit 901a65c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

hypervisor/arch/x86/guest/vmcall.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ int32_t vmcall_vmexit_handler(struct acrn_vcpu *vcpu)
233233

234234
if (!is_hypercall_from_ring0()) {
235235
pr_err("hypercall is only allowed from RING-0!\n");
236+
vcpu_inject_gp(vcpu, 0U);
236237
ret = -EACCES;
237238
} else if (hypcall_id == HC_WORLD_SWITCH) {
238239
ret = hcall_world_switch(vcpu);
@@ -248,10 +249,13 @@ int32_t vmcall_vmexit_handler(struct acrn_vcpu *vcpu)
248249
ret = dispatch_sos_hypercall(vcpu);
249250
} else {
250251
pr_err("hypercall %d is only allowed from SOS_VM!\n", hypcall_id);
252+
vcpu_inject_ud(vcpu);
251253
ret = -ENODEV;
252254
}
253255

254-
vcpu_set_gpreg(vcpu, CPU_REG_RAX, (uint64_t)ret);
256+
if ((ret != -EACCES) && (ret != -ENODEV)) {
257+
vcpu_set_gpreg(vcpu, CPU_REG_RAX, (uint64_t)ret);
258+
}
255259
TRACE_2L(TRACE_VMEXIT_VMCALL, vm->vm_id, hypcall_id);
256260

257261
return 0;

0 commit comments

Comments
 (0)