Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move SVN field from ImageTocEntry to ImageHeader. #1909

Merged
merged 2 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions image/gen/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ impl<Crypto: ImageGeneratorCrypto> ImageGenerator<Crypto> {
flags: Self::DEFAULT_FLAGS,
toc_len: MAX_TOC_ENTRY_COUNT,
toc_digest: digest,
svn: config.runtime.svn(),
..Default::default()
};

Expand Down Expand Up @@ -437,8 +438,7 @@ impl<Crypto: ImageGeneratorCrypto> ImageGenerator<Crypto> {
r#type: r#type.into(),
revision: *image.rev(),
version: image.version(),
svn: image.svn(),
reserved: 0,
reserved: [0; 2],
load_addr: image.load_addr(),
entry_point: image.entry_point(),
offset,
Expand Down
10 changes: 5 additions & 5 deletions image/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ impl ImageBundle {
}

/// Calipatra Image Manifest
///
/// NOTE: only the header, fmc, and runtime portions of this struct are covered by signature.
#[repr(C)]
#[derive(AsBytes, FromBytes, Clone, Copy, Debug, Zeroize)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
Expand Down Expand Up @@ -518,6 +520,8 @@ pub struct ImageHeader {
/// TOC Digest
pub toc_digest: ImageDigest384,

pub svn: u32,

/// Vendor Data
pub vendor_data: VendorSignedData,

Expand Down Expand Up @@ -571,12 +575,8 @@ pub struct ImageTocEntry {
// Firmware release number
pub version: u32,

/// Security Version Number
/// Only read for Runtime entries. Not read for FMC.
pub svn: u32,

/// Reserved field
pub reserved: u32,
pub reserved: [u32; 2],

/// Entry Point
pub load_addr: u32,
Expand Down
12 changes: 3 additions & 9 deletions image/verify/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,7 @@ impl<Env: ImageVerificationEnv> ImageVerifier<Env> {
// Verify Runtime
let runtime_info = self.verify_runtime(image_info.runtime)?;

// The FMC and RT FW images within the bundle each include an SVN, for
// backwards compatibility with 1.x. ROM only inspects the RT FW SVN.
let fw_svn = image_info.runtime.svn;

self.verify_svn(fw_svn)?;
self.verify_svn(manifest.header.svn)?;

let effective_fuse_svn = self.effective_fuse_svn();

Expand All @@ -149,15 +145,15 @@ impl<Env: ImageVerificationEnv> ImageVerifier<Env> {
owner_pub_keys_digest_in_fuses: header_info.owner_pub_keys_digest_in_fuses,
fmc: fmc_info,
runtime: runtime_info,
fw_svn,
fw_svn: manifest.header.svn,
effective_fuse_svn,
log_info: ImageVerificationLogInfo {
vendor_ecc_pub_key_idx: header_info.vendor_ecc_pub_key_idx,
fuse_vendor_ecc_pub_key_revocation: header_info.vendor_ecc_pub_key_revocation,
fuse_vendor_pqc_pub_key_revocation: header_info.vendor_pqc_pub_key_revocation,
vendor_pqc_pub_key_idx: header_info.vendor_pqc_pub_key_idx,
fw_log_info: FirmwareSvnLogInfo {
manifest_svn: fw_svn,
manifest_svn: manifest.header.svn,
reserved: 0,
fuse_svn: self.env.runtime_fuse_svn(),
},
Expand Down Expand Up @@ -2258,7 +2254,6 @@ mod tests {
let verify_info = ImageTocEntry {
load_addr: ICCM_ORG,
entry_point: ICCM_ORG,
svn: 1,
size: 100,
..Default::default()
};
Expand Down Expand Up @@ -2321,7 +2316,6 @@ mod tests {
let verify_info = ImageTocEntry {
load_addr: ICCM_ORG,
entry_point: ICCM_ORG,
svn: 1,
size: 100,
..Default::default()
};
Expand Down
16 changes: 16 additions & 0 deletions rom/dev/tests/rom_integration_tests/test_image_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2357,6 +2357,22 @@ fn test_runtime_svn_less_than_fuse_svn() {
}
}

#[test]
fn test_runtime_svn_corruption() {
let (mut hw, mut image_bundle) = hw_and_mldsa_image_bundle();

// Change SVN.
image_bundle.manifest.header.svn += 1;

assert_eq!(
hw.upload_firmware(&image_bundle.to_bytes().unwrap())
.unwrap_err(),
ModelError::MailboxCmdFailed(
CaliptraError::IMAGE_VERIFIER_ERR_VENDOR_ECC_SIGNATURE_INVALID.into()
)
);
}

#[test]
fn cert_test_with_custom_dates() {
for pqc_key_type in helpers::PQC_KEY_TYPE.iter() {
Expand Down
2 changes: 1 addition & 1 deletion test/tests/caliptra_integration_tests/smoke_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ fn smoke_test() {
owner_pub_key_hash_from_fuses: true,
ecc_vendor_pub_key_index: image.manifest.preamble.vendor_ecc_pub_key_idx,
fmc_digest: image.manifest.fmc.digest,
fmc_svn: image.manifest.fmc.svn,
fmc_svn: image.manifest.header.svn,
// This is from the SVN in the fuses (7 bits set)
fmc_fuse_svn: 7,
lms_vendor_pub_key_index: image.manifest.header.vendor_pqc_pub_key_idx,
Expand Down