Skip to content

Commit 9d808d7

Browse files
committed
kms: fix SNP tests for image-invariant os_image_hash
Two tests asserted the old behavior where os_image_hash changed with any MeasurementInput field. Now that os_image_hash is the image-invariant projection, per-deployment fields (app_id, vcpus) must NOT change it: - app_id_changes_host_data_and_authorization_binding: app_id changes the authorization binding but leaves os_image_hash unchanged. - measured_input_changes_reject_until_measurement_is_recomputed: assert os_image_hash changes only for image fields (kernel_hash), not vcpus. (These run under the full test suite; my earlier 'snp'-filtered local run missed them.)
1 parent 4b412d3 commit 9d808d7

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

kms/src/main_service/amd_attest.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,7 +1535,11 @@ mod tests {
15351535

15361536
assert_ne!(boot_info.app_id, changed_boot_info.app_id);
15371537
assert_ne!(boot_info.instance_id, changed_boot_info.instance_id);
1538-
assert_ne!(boot_info.os_image_hash, changed_boot_info.os_image_hash);
1538+
// app_id is an authorization input, not part of the OS image identity.
1539+
assert_eq!(
1540+
boot_info.os_image_hash, changed_boot_info.os_image_hash,
1541+
"app_id must not change the os_image_hash"
1542+
);
15391543
assert_ne!(boot_info.mr_aggregated, changed_boot_info.mr_aggregated);
15401544
assert_eq!(boot_info.mr_system, changed_boot_info.mr_system);
15411545
Ok(())
@@ -1548,10 +1552,13 @@ mod tests {
15481552
let chip_id = [0xef; 64];
15491553
let boot_info = build_amd_snp_boot_info(&config(), &verified, &chip_id, &input).unwrap();
15501554

1551-
for mutate in [
1552-
|i: &mut MeasurementInput| i.kernel_hash = hex_of(0x56, 32),
1553-
|i: &mut MeasurementInput| i.vcpus = 3,
1554-
] {
1555+
// (mutation, is_image_field): both change the SNP measurement (so a stale
1556+
// verified measurement rejects), but only image fields change os_image_hash.
1557+
let cases: [(fn(&mut MeasurementInput), bool); 2] = [
1558+
(|i| i.kernel_hash = hex_of(0x56, 32), true),
1559+
(|i| i.vcpus = 3, false),
1560+
];
1561+
for (mutate, is_image_field) in cases {
15551562
let mut changed = input.clone();
15561563
mutate(&mut changed);
15571564
let err = build_amd_snp_boot_info(&config(), &verified, &chip_id, &changed)
@@ -1564,7 +1571,17 @@ mod tests {
15641571
.expect("recomputed measurement should build boot info");
15651572
assert_ne!(boot_info.mr_aggregated, changed_boot_info.mr_aggregated);
15661573
assert_ne!(boot_info.mr_system, changed_boot_info.mr_system);
1567-
assert_ne!(boot_info.os_image_hash, changed_boot_info.os_image_hash);
1574+
if is_image_field {
1575+
assert_ne!(
1576+
boot_info.os_image_hash, changed_boot_info.os_image_hash,
1577+
"image fields must change os_image_hash"
1578+
);
1579+
} else {
1580+
assert_eq!(
1581+
boot_info.os_image_hash, changed_boot_info.os_image_hash,
1582+
"per-deployment fields (vcpus) must not change os_image_hash"
1583+
);
1584+
}
15681585
}
15691586
}
15701587

0 commit comments

Comments
 (0)