From 7a0e6542803cfe67e0e74653738c4751a2e164c6 Mon Sep 17 00:00:00 2001 From: Miguel Osorio Date: Fri, 15 Oct 2021 08:20:38 -0700 Subject: [PATCH] [sw/host] Update text end address in signer tool. Update the signer tool to look for the .shutdown section as well as the .text section when calculating the end address of executable code. Signed-off-by: Miguel Osorio --- sw/host/rom_ext_image_tools/signer/Cargo.toml | 1 + sw/host/rom_ext_image_tools/signer/src/main.rs | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/sw/host/rom_ext_image_tools/signer/Cargo.toml b/sw/host/rom_ext_image_tools/signer/Cargo.toml index 908210a28b41c..16aec0e47e50e 100644 --- a/sw/host/rom_ext_image_tools/signer/Cargo.toml +++ b/sw/host/rom_ext_image_tools/signer/Cargo.toml @@ -27,6 +27,7 @@ debug = true anyhow = "1.0.40" object = "0.25.3" rom_ext_image = { path = "image" } +thiserror = "1.0.24" zerocopy = "0.5.0" [dependencies.mundane] diff --git a/sw/host/rom_ext_image_tools/signer/src/main.rs b/sw/host/rom_ext_image_tools/signer/src/main.rs index 55db46c2a159b..af44b0433161a 100644 --- a/sw/host/rom_ext_image_tools/signer/src/main.rs +++ b/sw/host/rom_ext_image_tools/signer/src/main.rs @@ -105,12 +105,17 @@ fn update_image_manifest( addr.checked_sub(manifest_addr).context("Overflow")? }, code_end: { - let text = elf - .section_by_name(".text") - .context("Could not find the `.text` section.")?; + // TODO: Consider requiring all binaries signed by this tool to have a .shutdown section. + let section = elf + .section_by_name(".shutdown") + .or(elf.section_by_name(".text")) + .context( + "Could not find the `.shutdown` or `.text` section.", + )?; let addr = u32::try_from( - text.address() - .checked_add(text.size()) + section + .address() + .checked_add(section.size()) .context("Overflow")?, )?; addr.checked_sub(manifest_addr).context("Overflow")? @@ -171,7 +176,8 @@ fn update_image_manifest( "`entry_point` is outside the code region." ); ensure!( - (manifest::MANIFEST_LENGTH_FIELD_MIN..=manifest::MANIFEST_LENGTH_FIELD_MAX) + (manifest::MANIFEST_LENGTH_FIELD_MIN + ..=manifest::MANIFEST_LENGTH_FIELD_MAX) .contains(&image.manifest.length), "`length` is outside the allowed range." );