Skip to content

secure-boot: bind the booted FIT config to the signed one; fail-closed fixes - #146

Open
3rdIteration wants to merge 1 commit into
mainfrom
fix/luckfox-secure-boot-review
Open

3rdIteration wants to merge 1 commit into
mainfrom
fix/luckfox-secure-boot-review

Conversation

@3rdIteration

Copy link
Copy Markdown
Owner

Fixes from a review of the Luckfox Pico secure boot chain, including the U-Boot source at the pinned SDK_COMMIT.

What changed

1. U-Boot does not bind the booted configuration to the signed one (SPL and U-Boot proper).
The SDK's fit_config_check_sig() is a 2017.09 fork that predates the upstream fix for CVE-2020-10648 (and CVE-2021-27097 / CVE-2021-27138). It verifies the signature over whatever the hashed-nodes property lists and never checks that the configuration it was asked to verify is on that list. hashed-nodes and /configurations default both sit outside the signed region, and nodes that are neither listed nor the child of a listed node are left out of the hash.

New opt/luckfox/patch-fit-config-binding.sh adds upstream's rules before the RSA check, on signed builds only:

  • the selected configuration must be in hashed-nodes;
  • no node name may contain @;
  • every node directly under /images and /configurations must be in hashed-nodes.

It is wired into os-build.sh and build-local.sh next to patch-mtd-part-parse.sh, added to assert_shared_build_files(), and assert-uboot-fit-signature.sh fails the build if the built source lacks it. Every image in existing build output (mini/max/pi, uboot.img and boot.img) already satisfies all three rules.

2. /init skipped rootfs verification when the fuse flag was absent.
With no fuse.programmed=1 on the command line it fell back to nvmem OTP byte 0x80, which bench row E4 showed is the chip ID on fused and unfused boards alike. So a missing flag read as "unfused" and skipped the check, the opposite of the rule in secure-boot.md §5.2. Now only an explicit fuse.programmed=0 skips. No flag is "unknown": it verifies and shows an orange PASSED / rootfs valid / fuse state / unknown screen. The OTP byte can only force verification on.

3. /init verified one UBI volume and mounted another (NAND dev variant).
It hashed /dev/ubi0_0 but mounted ubi0:rootfs by name. It now mounts ubi0_0.

4. A leftover key beat SEEDSIGNER_FIT_KEY_DIR.
provision_fit_build_keys reused any key triple already in the kept SDK tree before looking at the supplied key, so a build given a real key could silently sign with the public dev key. A supplied key now always wins, and a leftover key that is not the committed dev key is called out.

5. assert-uboot-fit-signature.sh failed open.
If the built U-Boot .config or sources could not be found it warned and passed. It now fails the build. Override: SEEDSIGNER_ALLOW_UNVERIFIED_UBOOT=1.

6. fitsign.py verify and luckfox_release.py check never compared payload bytes.
They checked the RSA signature over the hash nodes only, so an altered kernel or ramdisk still read VALID. Both now compare every payload with its signed sha256 and apply the same binding rules as item 1.

Docs: docs/luckfox/secure-boot.md (§4.2, §5.2, §6.5, corrections log) and AGENTS.md.

Testing

  • 166 Python tests pass, 7 of them new (tests/test_fitsign.py, class Binding).
  • New tests/test_initramfs_fuse_verdict.sh runs the real /init decision block against 12 command-line / OTP cases.
  • The stricter checker accepts the real signed uboot.img / boot.img for mini, max and pi from local build output.
  • The U-Boot patch was applied to the pinned SDK source: no-op on unsigned builds, clean apply, idempotent re-run. The assert was exercised with the patch present, absent and with no .config.

Reviewer notes

  • The U-Boot patch has not been compiled or booted. There was no C toolchain where it was written. It needs this PR's signed CI build to pass, then a boot test on an unfused board, before any fused board is updated. A mistake in it would make a board reject genuine images.
  • SPL size headroom is unchecked. The patch pulls fdt_get_path / fdt_parent_offset into the SPL.
  • The /init changes are syntax-checked and logic-tested, not booted. On a board whose bootloader passes no fuse.programmed flag at all, boot now takes a full verification pass where it used to skip.
  • Not changed, by design: the verification-failure escape hatch (key press boots an unverified rootfs) and the absence of anti-rollback.

🤖 Generated with Claude Code

…d fixes

Findings from a review of the Luckfox secure boot chain, including the
U-Boot source at the pinned SDK commit.

* U-Boot (SPL + proper): the SDK's fit_config_check_sig() predates the
  upstream fix for CVE-2020-10648 / CVE-2021-27097 / CVE-2021-27138. It
  verified the signature over whatever the unsigned `hashed-nodes` list
  named and never checked that the configuration being booted was on it.
  New patch-fit-config-binding.sh adds upstream's rules before the RSA
  check on signed builds (config in hashed-nodes, no '@' node names, no
  unsigned image/config), wired into os-build.sh and build-local.sh and
  asserted by assert-uboot-fit-signature.sh. NOT yet compiled or booted.

* initramfs /init: a missing fuse.programmed flag fell back to an nvmem
  OTP byte that is the chip ID on every board (bench row E4), so it
  skipped rootfs verification. Now only an explicit fuse.programmed=0
  skips; no flag is "unknown" and verifies. The OTP byte can only force
  verification on.

* initramfs /init: the UBIFS path hashed /dev/ubi0_0 but mounted
  ubi0:rootfs by name. Mount ubi0_0, the volume that was hashed.

* provision_fit_build_keys: a key triple left in a kept SDK tree was
  reused before SEEDSIGNER_FIT_KEY_DIR was consulted, so a build with a
  real key could silently sign with the public dev key. A supplied key
  now always wins; a leftover non-dev key is called out.

* assert-uboot-fit-signature.sh: fail the build, not warn, when the
  built U-Boot .config or sources cannot be found
  (override: SEEDSIGNER_ALLOW_UNVERIFIED_UBOOT=1).

* fitsign.py verify / luckfox_release.py check: also compare every
  payload against its signed sha256 hash node and apply the same binding
  rules; previously an altered kernel or ramdisk still read VALID.

Tests: 7 new cases in tests/test_fitsign.py and a new
tests/test_initramfs_fuse_verdict.sh that runs the real /init decision
block against each command-line / OTP case.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.

1 participant