-
Notifications
You must be signed in to change notification settings - Fork 364
Fixes for re-signing images and dumping metadata. #10827
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
Open
lgirdwood
wants to merge
9
commits into
thesofproject:main
Choose a base branch
from
lgirdwood:topic/resign
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+376
−44
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3f71ab9
rimage: harden image detection and validate re-sign output
lrgirdwo 7879f49
rimage: clarify resign mode and disallow mixed verify
lrgirdwo 9bf93cc
tools: sof_ri_info: dump all CSS/CSE header fields
lrgirdwo 61a2730
tools: sof_ri_info: parse all plat_auth extensions
lrgirdwo 3a024e1
tools: sof_ri_info: parse remaining rimage manifest structs
lrgirdwo 2eb0742
tools: sof_ri_info: add memory map aliases for new platforms
lrgirdwo e13ca1e
tools: sof_ri_info: report PTL memory layout as Pantherlake
lrgirdwo a382b4b
tools: rimage: harden CSE header scan and re-sign cleanup
lrgirdwo 384813b
tools: sof_ri_info: fix CSE v2.5 detection and module config count
lrgirdwo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| #include <unistd.h> | ||
| #include <errno.h> | ||
| #include <string.h> | ||
| #include <stdbool.h> | ||
| #include <time.h> | ||
| #include <sys/time.h> | ||
|
|
||
|
|
@@ -26,6 +27,33 @@ | |
| #include <rimage/misc_utils.h> | ||
| #include <rimage/hash.h> | ||
|
|
||
| static bool cse_header_is_valid(const struct image *image, const void *buffer, size_t size) | ||
| { | ||
| if (image->adsp->man_v2_5 || image->adsp->man_ace_v1_5) { | ||
| const struct CsePartitionDirHeader_v2_5 *cse_hdr = buffer; | ||
|
|
||
| if (size < sizeof(*cse_hdr)) | ||
| return false; | ||
|
|
||
| return cse_hdr->header_marker == CSE_HEADER_MAKER && | ||
| cse_hdr->nb_entries == MAN_CSE_PARTS && | ||
| cse_hdr->header_length >= sizeof(*cse_hdr); | ||
| } | ||
|
|
||
| if (image->adsp->man_v1_5 || image->adsp->man_v1_5_sue || image->adsp->man_v1_8) { | ||
| const struct CsePartitionDirHeader *cse_hdr = buffer; | ||
|
|
||
| if (size < sizeof(*cse_hdr)) | ||
| return false; | ||
|
|
||
| return cse_hdr->header_marker == CSE_HEADER_MAKER && | ||
| cse_hdr->nb_entries == MAN_CSE_PARTS && | ||
| cse_hdr->header_length >= sizeof(*cse_hdr); | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| static int man_open_rom_file(struct image *image) | ||
| { | ||
| uint32_t size; | ||
|
|
@@ -1644,8 +1672,8 @@ int man_write_fw_ace_v1_5(struct image *image) | |
| int verify_image(struct image *image) | ||
| { | ||
| FILE *in_file; | ||
| int ret; | ||
| void *buffer; | ||
| int ret = -EINVAL; | ||
| void *buffer = NULL; | ||
| size_t size, read, i; | ||
|
|
||
| /* is verify supported for target ? */ | ||
|
|
@@ -1680,7 +1708,7 @@ int verify_image(struct image *image) | |
| } | ||
| for (i = 0; i + sizeof(uint32_t) <= size; i += sizeof(uint32_t)) { | ||
| /* find CSE header marker "$CPD" */ | ||
| if (*(uint32_t *)(buffer + i) == CSE_HEADER_MAKER) { | ||
| if (cse_header_is_valid(image, buffer + i, size - i)) { | ||
| image->fw_image = buffer + i; | ||
| /* size of the image from the CSE header to the end of the | ||
| * file, used by v1.5 verification and the signed-payload | ||
|
|
@@ -1706,6 +1734,7 @@ int verify_image(struct image *image) | |
| image->verify_file); | ||
| ret = -EINVAL; | ||
| out: | ||
| free(buffer); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 5fa4400. |
||
| fclose(in_file); | ||
| /* propagate verification result so callers (and the exit code) can | ||
| * detect a failed/missing verification instead of always seeing success | ||
|
|
@@ -1751,7 +1780,7 @@ int resign_image(struct image *image) | |
|
|
||
| for (i = 0; i + sizeof(uint32_t) <= size; i += sizeof(uint32_t)) { | ||
| /* find CSE header marker "$CPD" */ | ||
| if (*(uint32_t *)(buffer + i) == CSE_HEADER_MAKER) { | ||
| if (cse_header_is_valid(image, buffer + i, size - i)) { | ||
| image->fw_image = buffer + i; | ||
| break; | ||
| } | ||
|
|
@@ -1813,7 +1842,26 @@ int resign_image(struct image *image) | |
| goto out; | ||
| } | ||
|
|
||
| man_write_fw_mod(image); | ||
| ret = man_write_fw_mod(image); | ||
| if (ret < 0) | ||
| goto out; | ||
|
|
||
| /* fclose() closes the stream even when it reports an error, so clear the | ||
| * handle first to stop the caller's cleanup from closing it a second time. | ||
| */ | ||
| ret = fclose(image->out_fd); | ||
| image->out_fd = NULL; | ||
| if (ret) { | ||
| ret = file_error("unable to close file after signing", image->out_file); | ||
| goto out; | ||
| } | ||
|
|
||
| /* validate the re-signed output with the same private key */ | ||
| image->verify_file = image->out_file; | ||
| ret = verify_image(image); | ||
| image->verify_file = NULL; | ||
| if (ret < 0) | ||
| unlink(image->out_file); | ||
|
|
||
| out: | ||
| free(buffer); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.