From 3aa7d59497530c6f4920a74fc3ffb9ebe0014323 Mon Sep 17 00:00:00 2001 From: "Yan, Like" Date: Tue, 17 Jul 2018 22:59:33 +0800 Subject: [PATCH] hv: check eptp value before calling free_ept_mem() There is chance to destroy vm whose ept table was not created, for example, dm fails to setup mem for vm. In this case, it's better to check the value of eptp before calling free_ept_mem() rather than relying on assertion in the function. Signed-off-by: Yan, Like Acked-by: Anthony Xu --- hypervisor/arch/x86/ept.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hypervisor/arch/x86/ept.c b/hypervisor/arch/x86/ept.c index 8845c918f..0f98f22a0 100644 --- a/hypervisor/arch/x86/ept.c +++ b/hypervisor/arch/x86/ept.c @@ -98,8 +98,10 @@ static void free_ept_mem(void *pml4_addr) void destroy_ept(struct vm *vm) { - free_ept_mem(HPA2HVA(vm->arch_vm.nworld_eptp)); - free_ept_mem(HPA2HVA(vm->arch_vm.m2p)); + if (vm->arch_vm.nworld_eptp != 0U) + free_ept_mem(HPA2HVA(vm->arch_vm.nworld_eptp)); + if (vm->arch_vm.m2p != 0U) + free_ept_mem(HPA2HVA(vm->arch_vm.m2p)); /* * If secure world is initialized, destroy Secure world ept.