33
33
#include <hv_arch.h>
34
34
#include <acrn_hv_defs.h>
35
35
#include <hv_debug.h>
36
+ #include <hkdf.h>
36
37
37
38
_Static_assert (NR_WORLD == 2 , "Only 2 Worlds supported!" );
38
39
@@ -67,6 +68,13 @@ struct trusty_mem {
67
68
uint8_t left_mem [0 ];
68
69
};
69
70
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
+
70
78
_Static_assert (sizeof (struct trusty_startup_param )
71
79
+ sizeof (struct key_info ) < 0x1000 ,
72
80
"trusty_startup_param + key_info > 1Page size(4KB)!" );
@@ -275,15 +283,36 @@ void switch_world(struct vcpu *vcpu, int next_world)
275
283
/* Put key_info and trusty_startup_param in the first Page of Trusty
276
284
* runtime memory
277
285
*/
278
- static void setup_trusty_info (struct vcpu * vcpu ,
286
+ static bool setup_trusty_info (struct vcpu * vcpu ,
279
287
uint32_t mem_size , uint64_t mem_base_hpa )
280
288
{
289
+ uint32_t i ;
281
290
struct trusty_mem * mem ;
282
291
283
292
mem = (struct trusty_mem * )(HPA2HVA (mem_base_hpa ));
284
293
285
294
/* TODO: prepare vkey_info */
286
295
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
+
287
316
/* Prepare trusty startup info */
288
317
mem -> first_page .startup_param .size_of_this_struct =
289
318
sizeof (struct trusty_startup_param );
@@ -297,14 +326,16 @@ static void setup_trusty_info(struct vcpu *vcpu,
297
326
*/
298
327
vcpu -> arch_vcpu .contexts [SECURE_WORLD ].guest_cpu_regs .regs .rdi
299
328
= (uint64_t )TRUSTY_EPT_REBASE_GPA + sizeof (struct key_info );
329
+
330
+ return true;
300
331
}
301
332
302
333
/* Secure World will reuse environment of UOS_Loder since they are
303
334
* both booting from and running in 64bit mode, except GP registers.
304
335
* RIP, RSP and RDI are specified below, other GP registers are leaved
305
336
* as 0.
306
337
*/
307
- static void init_secure_world_env (struct vcpu * vcpu ,
338
+ static bool init_secure_world_env (struct vcpu * vcpu ,
308
339
uint64_t entry_gpa ,
309
340
uint64_t base_hpa ,
310
341
uint32_t size )
@@ -316,7 +347,7 @@ static void init_secure_world_env(struct vcpu *vcpu,
316
347
exec_vmwrite (VMX_GUEST_RSP ,
317
348
TRUSTY_EPT_REBASE_GPA + size );
318
349
319
- setup_trusty_info (vcpu , size , base_hpa );
350
+ return setup_trusty_info (vcpu , size , base_hpa );
320
351
}
321
352
322
353
bool initialize_trusty (struct vcpu * vcpu , uint64_t param )
@@ -363,12 +394,14 @@ bool initialize_trusty(struct vcpu *vcpu, uint64_t param)
363
394
save_world_ctx (& vcpu -> arch_vcpu .contexts [NORMAL_WORLD ]);
364
395
365
396
/* init secure world environment */
366
- init_secure_world_env (vcpu ,
397
+ if ( init_secure_world_env (vcpu ,
367
398
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 )) {
369
400
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
+ }
372
405
373
- return true ;
406
+ return false ;
374
407
}
0 commit comments