Skip to content

Commit 868778a

Browse files
yonghuahacrnsi
authored andcommitted
hv: fix vulnerability when VM is destroyed
In hypervisor fuzzing test, hypervisor will hang if issuing HV_VM_SET_MEMORY_REGIONS hypercall after target VM is destroyed. this patch is to fix above vulnerability. Tracked-On: #2849 Signed-off-by: Yonghua Huang <yonghua.huang@intel.com> Acked-by: Anthony Xu <anthony.xu@intel.com>
1 parent 5a7be9b commit 868778a

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

hypervisor/arch/x86/guest/vm.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,8 @@ int32_t shutdown_vm(struct acrn_vm *vm)
448448

449449
/* Only allow shutdown paused vm */
450450
if (vm->state == VM_PAUSED) {
451+
vm->state = VM_STATE_INVALID;
452+
451453
foreach_vcpu(i, vm, vcpu) {
452454
reset_vcpu(vcpu);
453455
offline_vcpu(vcpu);

hypervisor/common/hypercall.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -665,20 +665,19 @@ int32_t hcall_set_vm_memory_regions(struct acrn_vm *vm, uint64_t param)
665665
struct set_regions regions;
666666
struct vm_memory_region mr;
667667
struct acrn_vm *target_vm;
668+
uint16_t target_vm_id;
668669
uint32_t idx;
669-
int32_t ret = 0;
670+
int32_t ret = -EFAULT;
670671

671672

672673
(void)memset((void *)&regions, 0U, sizeof(regions));
673674

674-
if (copy_from_gpa(vm, &regions, param, sizeof(regions)) != 0) {
675-
pr_err("%s: Unable copy param from vm\n", __func__);
676-
ret = -EFAULT;
677-
} else {
675+
if (copy_from_gpa(vm, &regions, param, sizeof(regions)) == 0) {
678676
target_vm = get_vm_from_vmid(regions.vmid);
679-
if ((target_vm == NULL) || is_sos_vm(target_vm)) {
677+
target_vm_id = target_vm->vm_id;
678+
if ((target_vm_id >= CONFIG_MAX_VM_NUM) || (get_vm_config(target_vm_id)->type != NORMAL_VM)
679+
|| (target_vm->state == VM_STATE_INVALID)) {
680680
pr_err("%p %s:target_vm is invalid or Targeting to service vm", target_vm, __func__);
681-
ret = -EFAULT;
682681
} else {
683682
idx = 0U;
684683
while (idx < regions.mr_num) {

hypervisor/include/arch/x86/guest/vm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ struct vm_pm_info {
8585
#define VM_MONO_GUEST 0x01
8686
/* Enumerated type for VM states */
8787
enum vm_state {
88-
VM_STATE_UNKNOWN = 0,
88+
VM_STATE_INVALID = 0,
8989
VM_CREATED, /* VM created / awaiting start (boot) */
9090
VM_STARTED, /* VM started (booted) */
9191
VM_PAUSED, /* VM paused */

0 commit comments

Comments
 (0)