Skip to content

Commit d72e65c

Browse files
JasonChenCJlijinxia
authored andcommitted
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 <jason.cj.chen@intel.com>
1 parent 8773dfb commit d72e65c

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

hypervisor/arch/x86/trusty.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ void destroy_secure_world(struct vm *vm, bool need_clr_mem)
158158
pr_err("Parse vm0 context failed.");
159159
return;
160160
}
161+
162+
if (vm->arch_vm.sworld_eptp == NULL) {
163+
pr_err("sworld eptp is NULL, it's not created");
164+
return;
165+
}
166+
161167
if (need_clr_mem) {
162168
/* clear trusty memory space */
163169
(void)memset(hpa2hva(hpa), 0U, size);
@@ -176,17 +182,13 @@ void destroy_secure_world(struct vm *vm, bool need_clr_mem)
176182
}
177183

178184
/* Free trusty ept page-structures */
179-
if (vm->arch_vm.sworld_eptp != NULL) {
180-
pdpt_addr =
185+
pdpt_addr =
181186
(void *)pml4e_page_vaddr(*(uint64_t *)vm->arch_vm.sworld_eptp);
182-
/* memset PDPTEs except trusty memory */
183-
(void)memset(pdpt_addr, 0UL,
184-
NON_TRUSTY_PDPT_ENTRIES * sizeof(uint64_t));
185-
free_ept_mem((uint64_t *)vm->arch_vm.sworld_eptp);
186-
vm->arch_vm.sworld_eptp = NULL;
187-
} else {
188-
pr_err("sworld eptp is NULL");
189-
}
187+
/* memset PDPTEs except trusty memory */
188+
(void)memset(pdpt_addr, 0UL,
189+
NON_TRUSTY_PDPT_ENTRIES * sizeof(uint64_t));
190+
free_ept_mem((uint64_t *)vm->arch_vm.sworld_eptp);
191+
vm->arch_vm.sworld_eptp = NULL;
190192
}
191193

192194
static void save_world_ctx(struct vcpu *vcpu, struct ext_context *ext_ctx)

0 commit comments

Comments
 (0)