From d72e65c91a14103be69b4afb48ef4abf49a09ef0 Mon Sep 17 00:00:00 2001 From: Jason Chen CJ Date: Sat, 8 Sep 2018 15:29:32 +0800 Subject: [PATCH] trusty: do not destroy secure world if it's not created check sworld_eptp before real destroy_secure_world Tracked-On: #1200 Signed-off-by: Jason Chen CJ --- hypervisor/arch/x86/trusty.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/hypervisor/arch/x86/trusty.c b/hypervisor/arch/x86/trusty.c index 6a0d6e633..1c31eccaa 100644 --- a/hypervisor/arch/x86/trusty.c +++ b/hypervisor/arch/x86/trusty.c @@ -158,6 +158,12 @@ void destroy_secure_world(struct vm *vm, bool need_clr_mem) pr_err("Parse vm0 context failed."); return; } + + if (vm->arch_vm.sworld_eptp == NULL) { + pr_err("sworld eptp is NULL, it's not created"); + return; + } + if (need_clr_mem) { /* clear trusty memory space */ (void)memset(hpa2hva(hpa), 0U, size); @@ -176,17 +182,13 @@ void destroy_secure_world(struct vm *vm, bool need_clr_mem) } /* Free trusty ept page-structures */ - if (vm->arch_vm.sworld_eptp != NULL) { - pdpt_addr = + pdpt_addr = (void *)pml4e_page_vaddr(*(uint64_t *)vm->arch_vm.sworld_eptp); - /* memset PDPTEs except trusty memory */ - (void)memset(pdpt_addr, 0UL, - NON_TRUSTY_PDPT_ENTRIES * sizeof(uint64_t)); - free_ept_mem((uint64_t *)vm->arch_vm.sworld_eptp); - vm->arch_vm.sworld_eptp = NULL; - } else { - pr_err("sworld eptp is NULL"); - } + /* memset PDPTEs except trusty memory */ + (void)memset(pdpt_addr, 0UL, + NON_TRUSTY_PDPT_ENTRIES * sizeof(uint64_t)); + free_ept_mem((uint64_t *)vm->arch_vm.sworld_eptp); + vm->arch_vm.sworld_eptp = NULL; } static void save_world_ctx(struct vcpu *vcpu, struct ext_context *ext_ctx)