Skip to content

Commit 8555660

Browse files
authored
Merge pull request #238 from Freax13/feature/snp-report-v5
add support for V5 attestation report
2 parents 9c92368 + a5361e7 commit 8555660

4 files changed

Lines changed: 79 additions & 0 deletions

File tree

common/snp-types/src/attestation.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,69 +56,87 @@ pub enum MsgReportRspStatus {
5656
pub enum AttestionReport {
5757
V2(AttestionReportV2) = 2,
5858
V3(AttestionReportV3) = 3,
59+
V5(AttestionReportV5) = 5,
5960
}
6061

6162
impl AttestionReport {
6263
pub fn policy(&self) -> GuestPolicy {
6364
match self {
6465
AttestionReport::V2(report) => report.policy,
6566
AttestionReport::V3(report) => report.policy,
67+
AttestionReport::V5(report) => report.policy,
6668
}
6769
}
6870

6971
pub fn vmpl(&self) -> u32 {
7072
match self {
7173
AttestionReport::V2(report) => report.vmpl,
7274
AttestionReport::V3(report) => report.vmpl,
75+
AttestionReport::V5(report) => report.vmpl,
7376
}
7477
}
7578

7679
pub fn signature_algo(&self) -> u32 {
7780
match self {
7881
AttestionReport::V2(report) => report.signature_algo,
7982
AttestionReport::V3(report) => report.signature_algo,
83+
AttestionReport::V5(report) => report.signature_algo,
8084
}
8185
}
8286

8387
pub fn report_data(&self) -> [u8; 64] {
8488
match self {
8589
AttestionReport::V2(report) => report.report_data,
8690
AttestionReport::V3(report) => report.report_data,
91+
AttestionReport::V5(report) => report.report_data,
8792
}
8893
}
8994

9095
pub fn measurement(&self) -> [u8; 48] {
9196
match self {
9297
AttestionReport::V2(report) => report.measurement,
9398
AttestionReport::V3(report) => report.measurement,
99+
AttestionReport::V5(report) => report.measurement,
94100
}
95101
}
96102

97103
pub fn host_data(&self) -> [u8; 32] {
98104
match self {
99105
AttestionReport::V2(report) => report.host_data,
100106
AttestionReport::V3(report) => report.host_data,
107+
AttestionReport::V5(report) => report.host_data,
101108
}
102109
}
103110

104111
pub fn id_key_digest(&self) -> [u8; 48] {
105112
match self {
106113
AttestionReport::V2(report) => report.id_key_digest,
107114
AttestionReport::V3(report) => report.id_key_digest,
115+
AttestionReport::V5(report) => report.id_key_digest,
108116
}
109117
}
110118

111119
pub fn launch_tcb(&self) -> TcbVersion {
112120
match self {
113121
AttestionReport::V2(report) => report.launch_tcb,
114122
AttestionReport::V3(report) => report.launch_tcb,
123+
AttestionReport::V5(report) => report.launch_tcb,
124+
}
125+
}
126+
127+
pub fn launch_mitigation_vector(&self) -> u64 {
128+
match self {
129+
AttestionReport::V2(_) => 0,
130+
AttestionReport::V3(_) => 0,
131+
AttestionReport::V5(report) => report.launch_mitigation_vector,
115132
}
116133
}
117134

118135
pub fn signature(&self) -> [u8; 512] {
119136
match self {
120137
AttestionReport::V2(report) => report.signature,
121138
AttestionReport::V3(report) => report.signature,
139+
AttestionReport::V5(report) => report.signature,
122140
}
123141
}
124142
}
@@ -200,6 +218,48 @@ pub struct AttestionReportV3 {
200218
pub signature: [u8; 512],
201219
}
202220

221+
#[derive(Debug, Clone, Copy, CheckedBitPattern)]
222+
#[repr(C, packed)]
223+
pub struct AttestionReportV5 {
224+
pub guest_svn: u32,
225+
pub policy: GuestPolicy,
226+
pub familiy_id: u128,
227+
pub image_id: u128,
228+
pub vmpl: u32,
229+
pub signature_algo: u32,
230+
pub current_tcb: TcbVersion,
231+
pub platform_info: u64,
232+
pub fixme_key_stuff: u32,
233+
_reserved1: Reserved<4>,
234+
pub report_data: [u8; 64],
235+
pub measurement: [u8; 48],
236+
pub host_data: [u8; 32],
237+
pub id_key_digest: [u8; 48],
238+
pub author_key_digest: [u8; 48],
239+
pub report_id: [u8; 32],
240+
pub report_id_ma: [u8; 32],
241+
pub reported_tcb: TcbVersion,
242+
pub cpuid_fam_id: u8,
243+
pub cpuid_mod_id: u8,
244+
pub cpuid_step: u8,
245+
_reserved2: Reserved<21>,
246+
pub chip_id: [u8; 64],
247+
pub commited_tcb: TcbVersion,
248+
pub current_build: u8,
249+
pub current_minor: u8,
250+
pub current_major: u8,
251+
_reserved3: Reserved<1>,
252+
pub commited_build: u8,
253+
pub commited_minor: u8,
254+
pub commited_major: u8,
255+
_reserved4: Reserved<1>,
256+
pub launch_tcb: TcbVersion,
257+
pub launch_mitigation_vector: u64,
258+
pub current_mitigation_vector: u64,
259+
_reserved5: Reserved<152>,
260+
pub signature: [u8; 512],
261+
}
262+
203263
#[derive(Clone, Copy, AnyBitPattern, NoUninit)]
204264
#[repr(C)]
205265
pub struct EcdsaP384Sha384Signature {

host/mushroom-verify/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ impl Configuration {
5555
load_kasan_shadow_mappings: bool,
5656
policy: GuestPolicy,
5757
min_tcb: TcbVersion,
58+
min_mitigation_vector: u64,
5859
) -> Self {
5960
Self(ConfigurationImpl::Snp(snp::Configuration::new(
6061
supervisor,
@@ -63,6 +64,7 @@ impl Configuration {
6364
load_kasan_shadow_mappings,
6465
policy,
6566
min_tcb,
67+
min_mitigation_vector,
6668
)))
6769
}
6870

host/mushroom-verify/src/snp.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub(crate) struct Configuration {
2525
id_key_digest: [u8; 48],
2626
policy: GuestPolicy,
2727
min_tcb: TcbVersion,
28+
min_mitigation_vector: u64,
2829
}
2930

3031
impl Configuration {
@@ -35,6 +36,7 @@ impl Configuration {
3536
load_kasan_shadow_mappings: bool,
3637
policy: GuestPolicy,
3738
min_tcb: TcbVersion,
39+
min_mitigation_vector: u64,
3840
) -> Self {
3941
let commands =
4042
generate_base_load_commands(Some(supervisor), kernel, init, load_kasan_shadow_mappings);
@@ -52,6 +54,7 @@ impl Configuration {
5254
id_key_digest,
5355
policy,
5456
min_tcb,
57+
min_mitigation_vector,
5558
}
5659
}
5760

@@ -117,6 +120,13 @@ impl Configuration {
117120
});
118121
}
119122

123+
if !report.launch_mitigation_vector() & self.min_mitigation_vector != 0 {
124+
return Err(Error::MitigationVector {
125+
expected: self.min_mitigation_vector,
126+
got: report.launch_mitigation_vector(),
127+
});
128+
}
129+
120130
// Construct signature.
121131
let signature = pod_read_unaligned::<EcdsaP384Sha384Signature>(&report.signature());
122132
let signature = Signature::try_from(signature)?;
@@ -279,6 +289,8 @@ pub(crate) enum Error {
279289
expected: TcbVersion,
280290
got: TcbVersion,
281291
},
292+
#[error("expected mitigation vector to contain {expected:?} or more, got {got:?}")]
293+
MitigationVector { expected: u64, got: u64 },
282294
#[error("failed to verify report signature")]
283295
Ecdsa(#[from] ecdsa::Error),
284296
}

host/mushroom/src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,10 @@ struct TcbArgs {
377377
#[cfg(feature = "snp")]
378378
#[arg(long, default_value_t = 213)]
379379
microcode_svn: u8,
380+
/// The minimum set of mitigation vector bits.
381+
#[cfg(feature = "snp")]
382+
#[arg(long, default_value_t = 0)]
383+
mitigation_vector: u64,
380384
// TDX:
381385
/// TDX module minor SVN.
382386
#[cfg(feature = "tdx")]
@@ -445,6 +449,7 @@ async fn verify(run: VerifyCommand) -> Result<()> {
445449
run.config.kasan,
446450
run.config.policy.policy(),
447451
run.tcb_args.min_tcb(),
452+
run.tcb_args.mitigation_vector,
448453
)
449454
}
450455
#[cfg(feature = "tdx")]

0 commit comments

Comments
 (0)