Skip to content

Fix broken CRC32 checks for signed bzimage files.#2547

Merged
probot-auto-merge[bot] merged 4 commits into
u-root:mainfrom
abrender:fixchecksum
Nov 5, 2022
Merged

Fix broken CRC32 checks for signed bzimage files.#2547
probot-auto-merge[bot] merged 4 commits into
u-root:mainfrom
abrender:fixchecksum

Conversation

@abrender

@abrender abrender commented Nov 1, 2022

Copy link
Copy Markdown
Contributor

Fixes #2513.

CRC32 checks are broken for signed images because the image signing process changes the bootcode data, therefore the CRC32 in the original image is invalid.

This PR adds basic support for parsing PE files (https://learn.microsoft.com/en-us/windows/win32/debug/pe-format) and resets the PE checksum and Certificate Table which restores the bootcode contents back to their pre-signing state and the CRC32 checksums pass.

This code does not add PE checksum verification or kernel signature verification.

2x signed test kernels are added:

Signed-off-by: Avi avibrender@gmail.com

@codecov

codecov Bot commented Nov 1, 2022

Copy link
Copy Markdown

Codecov Report

Base: 73.66% // Head: 73.67% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (d9133e6) compared to base (8a781b5).
Patch coverage: 77.41% of modified lines in pull request are covered.

❗ Current head d9133e6 differs from pull request most recent head baa8f28. Consider uploading reports for the commit baa8f28 to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2547   +/-   ##
=======================================
  Coverage   73.66%   73.67%           
=======================================
  Files         405      405           
  Lines       41231    41281   +50     
=======================================
+ Hits        30374    30414   +40     
- Misses      10857    10867   +10     
Impacted Files Coverage Δ
pkg/boot/bzimage/bzimage.go 66.66% <77.41%> (+2.07%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@abrender abrender marked this pull request as ready for review November 2, 2022 01:16
@abrender abrender requested a review from rminnich November 2, 2022 01:17
@abrender abrender marked this pull request as draft November 2, 2022 13:38
…signed images.

Fixes #2513.

CRC32 checks are broken for signed images because the image signing process changes the bootcode data, therefore the CRC32 in the original image is invalid.

This PR adds basic support for parsing PE files (https://learn.microsoft.com/en-us/windows/win32/debug/pe-format) and resets the PE checksum and Certificate Table which restores the bootcode contents back to their pre-signing state and the CRC32 checksums pass.

This code does not add PE checksum verification or kernel signature verification.

2x signed test kernels are added:
* bzImage-debian-signed-linux5.10.0-6-amd64_5.10.28-1_amd64 which is signed using sbsigntools (changes PE checksum & Certificate Table)
* bzImage-rockylinux9 (https://download.rockylinux.org/pub/rocky/9/BaseOS/x86_64/os/images/pxeboot/vmlinuz) (changes Certificate Table only)

Signed-off-by: Avi <avibrender@gmail.com>
@abrender abrender marked this pull request as ready for review November 2, 2022 14:48

@rminnich rminnich left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The data files add a lot ... is there some way to shrink them? Just commit only the header? If not, no problem.

@rminnich rminnich added the Awaiting author Waiting for new changes or feedback for author. label Nov 3, 2022
@abrender

abrender commented Nov 3, 2022

Copy link
Copy Markdown
Contributor Author

The data files add a lot ... is there some way to shrink them? Just commit only the header? If not, no problem.

Unfortunately they can't be shrunk because the kernel image is already compressed. I tried to gzip bzImage-rockylinux9 but it's basically the same size before and after.

I think it's valuable to keep the entire file because the actual signature is appended to the end of the file... and one day we will want to add signature verification, so we'll need that data.

WDYT?

@rminnich rminnich added the automerge Applying this label auto-merges the PR when ready label Nov 5, 2022
@probot-auto-merge probot-auto-merge Bot merged commit 61d707a into u-root:main Nov 5, 2022
@abrender abrender deleted the fixchecksum branch November 9, 2022 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge Applying this label auto-merges the PR when ready Awaiting author Waiting for new changes or feedback for author.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bzImage CRC32 check fails with signed kernels.

2 participants