@@ -47,8 +47,10 @@ pub const TDX_METADATA_SECTION_TYPE_PAYLOAD: u32 = 5;
47
47
pub const TDX_METADATA_SECTION_TYPE_PAYLOAD_PARAM : u32 = 6 ;
48
48
/// Section type for td info.
49
49
pub const TDX_METADATA_SECTION_TYPE_TD_INFO : u32 = 7 ;
50
+ /// Section type for TD Params.
51
+ pub const TDX_METADATA_SECTION_TYPE_TD_PARAMS : u32 = 8 ;
50
52
/// Max Section type
51
- pub const TDX_METADATA_SECTION_TYPE_MAX : u32 = 8 ;
53
+ pub const TDX_METADATA_SECTION_TYPE_MAX : u32 = 9 ;
52
54
53
55
pub const TDX_METADATA_SECTION_TYPE_STRS : [ & str ; TDX_METADATA_SECTION_TYPE_MAX as usize ] = [
54
56
"BFV" ,
@@ -59,6 +61,7 @@ pub const TDX_METADATA_SECTION_TYPE_STRS: [&str; TDX_METADATA_SECTION_TYPE_MAX a
59
61
"Payload" ,
60
62
"PayloadParam" ,
61
63
"TdInfo" ,
64
+ "TdParams" ,
62
65
] ;
63
66
64
67
/// Attribute flags for BFV.
@@ -204,6 +207,9 @@ pub fn validate_sections(sections: &[TdxMetadataSection]) -> Result<(), TdxMetad
204
207
let mut td_info_cnt = 0 ;
205
208
let mut td_info_start = 0 ;
206
209
let mut td_info_end = 0 ;
210
+ let mut td_params_cnt = 0 ;
211
+ let mut td_params_start = 0 ;
212
+ let mut td_params_end = 0 ;
207
213
let check_data_memory_fields =
208
214
|data_offset : u32 , data_size : u32 , memory_address : u64 , memory_size : u64 | -> bool {
209
215
if data_size == 0 && data_offset != 0 {
@@ -407,6 +413,31 @@ pub fn validate_sections(sections: &[TdxMetadataSection]) -> Result<(), TdxMetad
407
413
}
408
414
}
409
415
416
+ TDX_METADATA_SECTION_TYPE_TD_PARAMS => {
417
+ // A TD-Shim may have zero or one TdParams. If present, it shall be included in BFV section.
418
+ if td_params_cnt == i32:: MAX {
419
+ return Err ( TdxMetadataError :: InvalidSection ) ;
420
+ }
421
+ td_params_cnt += 1 ;
422
+ if td_params_cnt > 1 {
423
+ return Err ( TdxMetadataError :: InvalidSection ) ;
424
+ }
425
+ if section. attributes != 0 {
426
+ return Err ( TdxMetadataError :: InvalidSection ) ;
427
+ }
428
+ if section. raw_data_size == 0 {
429
+ return Err ( TdxMetadataError :: InvalidSection ) ;
430
+ } else {
431
+ td_params_start = section. data_offset ;
432
+ td_params_end = td_params_start + section. raw_data_size ;
433
+ }
434
+
435
+ // MemoryAddress and MemoryDataSize shall be zero.
436
+ if section. memory_address != 0 || section. memory_data_size != 0 {
437
+ return Err ( TdxMetadataError :: InvalidSection ) ;
438
+ }
439
+ }
440
+
410
441
_ => {
411
442
return Err ( TdxMetadataError :: InvalidSection ) ;
412
443
}
@@ -427,13 +458,20 @@ pub fn validate_sections(sections: &[TdxMetadataSection]) -> Result<(), TdxMetad
427
458
return Err ( TdxMetadataError :: InvalidSection ) ;
428
459
}
429
460
430
- //TdInfo. If present, it shall be included in BFV section.
461
+ // TdInfo. If present, it shall be included in BFV section.
431
462
if td_info_cnt != 0
432
463
&& ( td_info_start < bfv_start || td_info_start >= bfv_end || td_info_end > bfv_end)
433
464
{
434
465
return Err ( TdxMetadataError :: InvalidSection ) ;
435
466
}
436
467
468
+ // TdParams. If present, it shall be included in BFV section.
469
+ if td_params_cnt != 0
470
+ && ( td_params_start < bfv_start || td_params_start >= bfv_end || td_params_end > bfv_end)
471
+ {
472
+ return Err ( TdxMetadataError :: InvalidSection ) ;
473
+ }
474
+
437
475
Ok ( ( ) )
438
476
}
439
477
@@ -523,8 +561,9 @@ mod tests {
523
561
"PayloadParam"
524
562
) ;
525
563
assert_eq ! ( TdxMetadataSection :: get_type_name( 7 ) . unwrap( ) , "TdInfo" ) ;
564
+ assert_eq ! ( TdxMetadataSection :: get_type_name( 8 ) . unwrap( ) , "TdParams" ) ;
526
565
527
- assert ! ( TdxMetadataSection :: get_type_name( 8 ) . is_none( ) ) ;
566
+ assert ! ( TdxMetadataSection :: get_type_name( 9 ) . is_none( ) ) ;
528
567
}
529
568
530
569
#[ test]
0 commit comments