Skip to content

Commit 922daae

Browse files
YadongQijren1
authored andcommitted
trusty: add key_info for trusty bring-up
For trusty bring-up, key_info is needed. Currently, bootloader did not transfer key_info to hypervisor. So in this patch, use dummy key_info temporarily. Derive vSeed from dSeed before trusty startup, the vSeed will bind with UUID of each VM. Remove key_info from sworld_control structure. Signed-off-by: Qi Yadong <yadong.qi@intel.com>
1 parent b124e0d commit 922daae

File tree

3 files changed

+42
-10
lines changed

3 files changed

+42
-10
lines changed

hypervisor/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ ARCH_LDSCRIPT_IN = bsp/ld/link_ram.ld.in
6060

6161
INCLUDE_PATH += include
6262
INCLUDE_PATH += include/lib
63+
INCLUDE_PATH += include/lib/crypto
6364
INCLUDE_PATH += include/common
6465
INCLUDE_PATH += include/arch/x86
6566
INCLUDE_PATH += include/arch/x86/guest

hypervisor/arch/x86/trusty.c

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <hv_arch.h>
3434
#include <acrn_hv_defs.h>
3535
#include <hv_debug.h>
36+
#include <hkdf.h>
3637

3738
_Static_assert(NR_WORLD == 2, "Only 2 Worlds supported!");
3839

@@ -67,6 +68,13 @@ struct trusty_mem {
6768
uint8_t left_mem[0];
6869
};
6970

71+
static struct key_info g_key_info = {
72+
.size_of_this_struct = sizeof(g_key_info),
73+
.version = 0,
74+
.platform = 3,
75+
.num_seeds = 1
76+
};
77+
7078
_Static_assert(sizeof(struct trusty_startup_param)
7179
+ sizeof(struct key_info) < 0x1000,
7280
"trusty_startup_param + key_info > 1Page size(4KB)!");
@@ -275,15 +283,36 @@ void switch_world(struct vcpu *vcpu, int next_world)
275283
/* Put key_info and trusty_startup_param in the first Page of Trusty
276284
* runtime memory
277285
*/
278-
static void setup_trusty_info(struct vcpu *vcpu,
286+
static bool setup_trusty_info(struct vcpu *vcpu,
279287
uint32_t mem_size, uint64_t mem_base_hpa)
280288
{
289+
uint32_t i;
281290
struct trusty_mem *mem;
282291

283292
mem = (struct trusty_mem *)(HPA2HVA(mem_base_hpa));
284293

285294
/* TODO: prepare vkey_info */
286295

296+
/* copy key_info to the first page of trusty memory */
297+
mem->first_page.key_info = g_key_info;
298+
299+
memset(mem->first_page.key_info.dseed_list, 0,
300+
sizeof(mem->first_page.key_info.dseed_list));
301+
/* Derive dvseed from dseed for Trusty */
302+
for (i = 0; i < g_key_info.num_seeds; i++) {
303+
if (!hkdf_sha256(mem->first_page.key_info.dseed_list[i].seed,
304+
BUP_MKHI_BOOTLOADER_SEED_LEN,
305+
g_key_info.dseed_list[i].seed,
306+
BUP_MKHI_BOOTLOADER_SEED_LEN,
307+
NULL, 0,
308+
vcpu->vm->GUID, sizeof(vcpu->vm->GUID))) {
309+
memset(&mem->first_page.key_info, 0,
310+
sizeof(struct key_info));
311+
pr_err("%s: derive dvseed failed!", __func__);
312+
return false;
313+
}
314+
}
315+
287316
/* Prepare trusty startup info */
288317
mem->first_page.startup_param.size_of_this_struct =
289318
sizeof(struct trusty_startup_param);
@@ -297,14 +326,16 @@ static void setup_trusty_info(struct vcpu *vcpu,
297326
*/
298327
vcpu->arch_vcpu.contexts[SECURE_WORLD].guest_cpu_regs.regs.rdi
299328
= (uint64_t)TRUSTY_EPT_REBASE_GPA + sizeof(struct key_info);
329+
330+
return true;
300331
}
301332

302333
/* Secure World will reuse environment of UOS_Loder since they are
303334
* both booting from and running in 64bit mode, except GP registers.
304335
* RIP, RSP and RDI are specified below, other GP registers are leaved
305336
* as 0.
306337
*/
307-
static void init_secure_world_env(struct vcpu *vcpu,
338+
static bool init_secure_world_env(struct vcpu *vcpu,
308339
uint64_t entry_gpa,
309340
uint64_t base_hpa,
310341
uint32_t size)
@@ -316,7 +347,7 @@ static void init_secure_world_env(struct vcpu *vcpu,
316347
exec_vmwrite(VMX_GUEST_RSP,
317348
TRUSTY_EPT_REBASE_GPA + size);
318349

319-
setup_trusty_info(vcpu, size, base_hpa);
350+
return setup_trusty_info(vcpu, size, base_hpa);
320351
}
321352

322353
bool initialize_trusty(struct vcpu *vcpu, uint64_t param)
@@ -363,12 +394,14 @@ bool initialize_trusty(struct vcpu *vcpu, uint64_t param)
363394
save_world_ctx(&vcpu->arch_vcpu.contexts[NORMAL_WORLD]);
364395

365396
/* init secure world environment */
366-
init_secure_world_env(vcpu,
397+
if (init_secure_world_env(vcpu,
367398
trusty_entry_gpa - trusty_base_gpa + TRUSTY_EPT_REBASE_GPA,
368-
trusty_base_hpa, boot_param->mem_size);
399+
trusty_base_hpa, boot_param->mem_size)) {
369400

370-
/* switch to Secure World */
371-
vcpu->arch_vcpu.cur_context = SECURE_WORLD;
401+
/* switch to Secure World */
402+
vcpu->arch_vcpu.cur_context = SECURE_WORLD;
403+
return true;
404+
}
372405

373-
return true;
406+
return false;
374407
}

hypervisor/include/arch/x86/trusty.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@ struct secure_world_memory {
122122
struct secure_world_control {
123123
/* Whether secure world is enabled for current VM */
124124
bool sworld_enabled;
125-
/* key info structure */
126-
struct key_info key_info;
127125
/* Secure world memory structure */
128126
struct secure_world_memory sworld_memory;
129127
};

0 commit comments

Comments
 (0)