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

Add uboot CRC32 checks for kernel and device-tree #3141

Merged
merged 4 commits into from
Jun 14, 2023
Merged

Conversation

acostach
Copy link
Contributor

@acostach acostach commented May 19, 2023

This PR adds the possibility of checking if the areas where the kernel image and the device-tree have been loaded were tampered during boot, like for instance if there is a kernel - dtb overlap. Upon any potential failure, a file named overlap_detected is created in the boot partition, and its presence can be checked by the automated tests.

These scripts should not cause any boot failures however, for cases where an overlap exists but does not halt booting nor is reproducible in the test rig.

Since device repositories may have the device-specific boot scripts in various places which are not standard (i.e script header for the board, BOOT_COMMAND config variable, etc) and the kernel and fdt load address variables are not unique for all devices (some use fdtaddr, others fdt_addr), the device repositories can override these variable names and run the balena crc checks on a case by case basis, after loading the kernel/dtb and prior to calling the final boot command (i.e booti)

Tested manually on:


Contributor checklist

Reviewer Guidelines

  • When submitting a review, please pick:
    • 'Approve' if this change would be acceptable in the codebase (even if there are minor or cosmetic tweaks that could be improved).
    • 'Request Changes' if this change would not be acceptable in our codebase (e.g. bugs, changes that will make development harder in future, security/performance issues, etc).
    • 'Comment' if you don't feel you have enough information to decide either way (e.g. if you have major questions, or you don't understand the context of the change sufficiently to fully review yourself, but want to make a comment)

@acostach acostach marked this pull request as ready for review May 25, 2023 07:26
@acostach acostach requested review from floion and alexgg May 25, 2023 07:27
@flowzone-app flowzone-app bot enabled auto-merge May 25, 2023 07:41
@acostach
Copy link
Contributor Author

@resin-jenkins retest this please

@acostach acostach changed the title POC: Add uboot CRC32 checks for kernel and device-tree Add uboot CRC32 checks for kernel and device-tree May 29, 2023
@acostach acostach force-pushed the poc_uboot_crc_checks branch 3 times, most recently from c1e6515 to 7901e76 Compare May 31, 2023 11:13
@acostach acostach marked this pull request as draft May 31, 2023 14:49
auto-merge was automatically disabled May 31, 2023 14:49

Pull request was converted to draft

@acostach
Copy link
Contributor Author

acostach commented Jun 1, 2023

Builds for all device-types now but 1538d51#diff-cb2e252a0fd0dad822dde359c09cae7ac591c3fe30eb00b3be69edc688e07bd5R101 seems to cause the SPL crash for the iot-gate-imx8, will investigate why

Fixed in device-repository

@acostach acostach marked this pull request as ready for review June 5, 2023 07:24
@acostach
Copy link
Contributor Author

acostach commented Jun 5, 2023

Fixed the iot-gate-imx8 SPL crash in the device repository with balena-os/balena-iot-gate-imx8#326

This PR is ready for review

@acostach
Copy link
Contributor Author

Hi @alexgg, does this look good, shall I re-base, merge and then update device repositories to use the checks?

This helper command saves and compares crc32 sum for a memory
area where the kernel image or the device-tree is loaded.

Can be used after loading the kernel and the dtb, and also prior
to calling booti.

Signed-off-by: Alexandru Costache <alexandru@balena.io>
Change-type: patch
... and provide default values for the kernel and
fdt address variables which can be modified by
device repositories.

Signed-off-by: Alexandru Costache <alexandru@balena.io>
…validity

The balena_kernel_load_crc_save / balena_fdt_load_crc_check functions
can be used in the device repository right after the kernel or
dtb is loaded and prior to calling the main boot function,
to verify if the memory areas of the kernel or fdt overlap
or may otherwise be re-written. These functions will save
create a file named overlap_detected in the boot partition,
which can be checked during automated testing. These checks
should not prevent booting in any way.

Signed-off-by: Alexandru Costache <alexandru@balena.io>
If a kernel or dtb overlap or overwrite is detected in u-boot,
a file named overlap_detected is created in the boot partition.

In this test we check for the presence of this file.

Signed-off-by: Alexandru Costache <alexandru@balena.io>
@alexgg alexgg enabled auto-merge June 14, 2023 09:38
@alexgg alexgg merged commit b41bc58 into master Jun 14, 2023
45 checks passed
@alexgg alexgg deleted the poc_uboot_crc_checks branch June 14, 2023 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants