Skip to content

uefi: In-memory Secure Boot authentication - #710

Closed
hotline1337 wants to merge 10 commits into
Limine-Bootloader:trunkfrom
hotline1337:feat/secureboot-attestation
Closed

hotline1337 wants to merge 10 commits into
Limine-Bootloader:trunkfrom
hotline1337:feat/secureboot-attestation

Conversation

@hotline1337

@hotline1337 hotline1337 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Implemented in-memory Authenticode verification for PE/COFF Linux kernels across x86 (linux_x86.c) and RISC architectures (linux_risc.c for AArch64 and RISC-V), as well as chainloaded EFI applications via shim_load_image(). Firmwares validate PE images against db/dbx and Shim MOK, triggering EV_EFI_VARIABLE_AUTHORITY recording into TPM PCR 7.
  • Added transparent Shim integration via SHIM_LOCK_PROTOCOL (System V ABI thunking on x86) and an EFI_SECURITY2_ARCH_PROTOCOL override for in-memory image loads with strict fail-closed security, properly handling both legacy Shim and Shim 15.3+ / 16.
  • Aligned TPM measured boot with the TCG PC Client Platform Firmware Profile and the Linux TPM PCR Registry: PCR 4 (kernel image), PCR 5 (config as EV_EVENT_TAG 0xf5bc582a with description limine.conf), PCR 8 (cmdline and sanitized path descriptors), PCR 9 (initramfs / DTBs), with dual TCG2 and CC measurements on Confidential Computing platforms.
  • Enforced strict Secure Boot lockdown whenever UEFI Secure Boot is active in firmware: unconditionally disables the configuration editor, blocks UEFI Shell invocation, and rejects unverified boot volume fallbacks.
  • Preserved secure_boot_active state dynamically from UEFI variables (SecureBoot and SetupMode) regardless of config hash enrollment, ensuring upstream secure_boot = 3 signaling in boot_params (and linux,uefi-secure-boot = <3> in Device Tree) is reliably passed to the OS.
  • Hardened URI loading against polyglot MZ header bypasses by introducing is_kernel classification in uri_open(): unhashed initramfs/modules are permitted under unenrolled Secure Boot (and measured into PCR 9 for standard distro boots), while strictly mandating hashes for non-PE modules when a config hash is enrolled.
  • Centralized reusable PE/COFF header parsing and validation into common/lib/pe.c (pe_is_valid()).

More to be filled here soon....


AI assistance disclosure

The feature was designed and verified by a human, and implemented with material AI help. Commits carry the corresponding Assisted-by: trailer.

@hotline1337
hotline1337 marked this pull request as draft November 9, 2026 17:47
@hotline1337
hotline1337 force-pushed the feat/secureboot-attestation branch 2 times, most recently from 710b811 to e8f015f Compare November 9, 2026 18:25
Centralize PE/COFF image header definitions into common/lib/pe.h and
implement pe_is_valid() in common/lib/pe.c to validate DOS, NT, and
optional headers for image loading and verification.
Ensure secure_boot_active strictly reflects the firmware SecureBoot state
rather than being cleared when no config hash is enrolled in the binary.
Enforce lockdown by disabling the bootloader editor, blocking UEFI Shell
invocation, and rejecting unverified boot volume fallbacks under Secure Boot.
Scope unhashed wallpaper and font skipping to enrolled configurations.
…ot hash policy

Replace positional boolean flags with an explicit uri_flags bitmask
(URI_ALLOW_HIGH_MEM, URI_AUTH_PE_VALIDATED, URI_RESOURCE_KERNEL) and
update all protocol callers. Under Secure Boot:
- Images flagged with URI_AUTH_PE_VALIDATED (linux, chainload) are
  permitted unhashed only if they are valid uncompressed PE binaries;
  the caller guarantees Authenticode verification via firmware / Shim MOK.
- Kernels flagged with URI_RESOURCE_KERNEL (multiboot1, multiboot2,
  limine protocol) cannot be Authenticode-verified and always require an
  associated hash under Secure Boot, closing polyglot MZ header bypasses.
- Non-executable resources (modules, initramfs, DTBs) require a hash only
  when a config hash is enrolled in the binary, permitting unhashed modules
  to load and be measured into TPM PCR 9 on unenrolled configurations.
Add transparent Shim integration via SHIM_LOCK_PROTOCOL (System V ABI
thunking on x86) and an EFI_SECURITY2_ARCH_PROTOCOL override for
in-memory image loads with strict fail-closed security. Original firmware
verification hooks run first to ensure db-authenticated images log
EV_EFI_VARIABLE_AUTHORITY in PCR 7 and EV_EFI_BOOT_SERVICES_APPLICATION
in PCR 4, falling back to Shim verification for MOK-signed binaries.
…ement

Align TPM measured boot with the TCG PC Client Platform Firmware
Profile and the Linux TPM PCR Registry:
- PCR 4: Linux kernel image
- PCR 5: config as EV_EVENT_TAG 0xf5bc582a with 'limine.conf' description
- PCR 8: cmdline and sanitized path descriptors
- PCR 9: initramfs and DTB binaries
Mitigate CVE-2021-42299 via dual TCG2/CC measurements.
…and adjust PCR measurement logic

Implement shim_load_image usage in linux_x86 and linux_risc protos, ensure kernel image measurement goes to PCR 4 only when validated by shim, and propagate flag handling for high memory support.
…ment

Add test cases covering Secure Boot enforcement:
- Verify unhashed modules are permitted under unenrolled Secure Boot
- Verify unhashed modules are rejected under enrolled Secure Boot
- Verify polyglot MZ modules without hashes are rejected under enrolled Secure Boot
- Verify unhashed multiboot/ELF kernels are rejected under unenrolled Secure Boot
- Verify non-PE kernels panic under Secure Boot even when hashed
Reconcile USAGE.md, FAQ.md, and CONFIG.md with Secure Boot policies:
- Authenticode PE verification for Linux kernels and chainload images
- Hash requirements for non-PE kernels and data resources
- Breaking change: mandatory PE Authenticode signing for Linux under Secure Boot
- Align PCR 4, 5, 7, 8, and 9 documentation with TCG PC Client and Linux TPM PCR Registry
@hotline1337
hotline1337 force-pushed the feat/secureboot-attestation branch from ba61894 to 4aaf490 Compare November 9, 2026 19:08
Assisted-by: Antigravity:gemini-4-carbon-low-preview
Signed-off-by: hotline1337 <denuvo at tuta dot io>
Assisted-by: Antigravity:gemini-4-carbon-low-preview
Signed-off-by: hotline1337 <denuvo at tuta dot io>
@hotline1337
hotline1337 force-pushed the feat/secureboot-attestation branch from ab92abf to 8406a0d Compare November 9, 2026 23:35
@hotline1337

Copy link
Copy Markdown
Contributor Author

Closing this. Will resubmit the feature on a fresh trunk on the later date due to personal complications.

@hotline1337
hotline1337 deleted the feat/secureboot-attestation branch November 10, 2026 12:53
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