Skip to content

Commit

Permalink
[sw/host] Update text end address in signer tool.
Browse files Browse the repository at this point in the history
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 <miguelosorio@google.com>
  • Loading branch information
moidx committed Oct 19, 2021
1 parent 4ee0e27 commit 7a0e654
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions sw/host/rom_ext_image_tools/signer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
18 changes: 12 additions & 6 deletions sw/host/rom_ext_image_tools/signer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")?
Expand Down Expand Up @@ -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."
);
Expand Down

0 comments on commit 7a0e654

Please sign in to comment.