Commit Graph

3738 Commits (master)

Author SHA1 Message Date
David Garske d7e78d3bb6
Merge pull request #901 from danielinux/update-wolfssl-submodule
Update wolfssl submodule to master 4aa1ad7a5
2026-09-17 11:17:59 -07:00
Daniele Lacamera 703065b68f Fix wolfCrypt build and footprint limits after the wolfSSL update
The wolfSSL bump to master 4aa1ad7a5 wraps all of coding.h in
"#ifndef NO_CODING".  That block also holds the auto-enable that turns
WOLFSSL_KEY_GEN into WOLFSSL_BASE64_ENCODE, so wolfBoot configurations
that set both WOLFSSL_KEY_GEN (SECURE_PKCS11) and NO_CODING lost the
Base64_Encode() declaration -- and coding.c compiles to nothing under
NO_CODING, so the definition is gone too.  settings.h still derives
WOLFSSL_DER_TO_PEM from WOLFSSL_KEY_GEN, so asn.c kept compiling
wc_DerToPemEx() and failed with an implicit declaration of
Base64_Encode().  This broke every TrustZone and PKCS11 target.

wolfBoot never emits PEM, so define WOLFSSL_NO_DER_TO_PEM whenever
NO_CODING is set rather than pulling base64 back in.  The check sits
after the HAVE_FIPS block, which may undef NO_CODING.  wolfTPM's
wc_DerToPem() callers are themselves guarded by WOLFSSL_DER_TO_PEM, so
they simply drop their optional PEM encoding path.

Separately, the update grows wolfboot by 8-136 bytes depending on the
configuration, so re-measure every test-size-all entry with the CI
container and record the new sizes.
2026-09-17 19:13:42 +02:00
Daniele Lacamera f709767e94 Update wolfssl submodule to master 4aa1ad7a5
wolfssl master advanced 1287 commits past the pinned v5.9.2-stable
(e71b086f).
2026-09-17 17:30:41 +02:00
David Garske 8bac8cc589
Merge pull request #892 from danielinux/fenrir-fixes-2026-09-15
Update_ram fallback fixes + fenrir fixes 2026 09 15
2026-09-17 08:10:03 -07:00
Aidan Garske b8254ba33f Document the STM32H5 fwTPM secure RAM budget and stack reservation 2026-09-17 13:06:11 +02:00
Aidan Garske 670280e5b3 Assert the STM32H5 secure link leaves room for the stack 2026-09-17 13:06:11 +02:00
Aidan Garske 8b3e843495 Shrink unused fwTPM NV slots so the STM32H5 secure stack fits 2026-09-17 13:06:11 +02:00
Aidan Garske 16637119f8 Update wolfTPM submodule to v4.2.0 2026-09-17 13:06:11 +02:00
David Garske a8c8c19fe8 Add LS1028A eSDHC SD card disk boot support 2026-09-17 12:33:19 +02:00
Daniele Lacamera edf41b1c35 Verify partition isolation in custom-trailer state test
After writing both partitions, re-read BOOT and confirm it still
holds TESTING, so a backend that routes both IDs to the same
trailer is caught (previously each read followed its own write).

Verification: make -C tools/unit-tests unit-custom-trailer-nopart
exits 0; suite runs 1 check, 0 failures.
2026-09-17 09:29:03 +02:00
Daniele Lacamera d0ec587c7a Use literal exit codes in unit-custom-trailer-nopart
Replace EXIT_SUCCESS/EXIT_FAILURE with 0/1; the test does not
include <stdlib.h> and does not need the named macros.

Verification: make -C tools/unit-tests unit-custom-trailer-nopart
exits 0; suite runs 1 check, 0 failures.
2026-09-17 00:10:32 +02:00
Daniele Lacamera 80f109ea15 Drop tautology test from unit-custom-trailer-nopart
test_fixed_partition_apis_absent only asserted the build config
(0==0 when WOLFBOOT_FIXED_PARTITIONS is off), which the successful
compile of the same target already proves. Reviewer nit.

Verification: make -C tools/unit-tests unit-custom-trailer-nopart
exits 0; suite runs 1 check, 0 failures.
2026-09-16 23:20:22 +02:00
Daniele Lacamera bb2e1a70f8 Fix DQ0 wording in p1021 erase-fail test comment
STATUS_ERASE_FAIL is 0x81, so the fail bit (DQ0) is set, not clear.
2026-09-16 19:53:59 +02:00
Daniele Lacamera 928b9d9590 Guard security_command_passphrase against in-flight async DMA
Check ata_async_info.in_progress before preparing the slot or touching
the shared buffer, so a second security command cannot clobber the
passphrase still being DMA'd. With that guard an async call always
means in flight (exec_cmd_slot_ex sets in_progress and returns BUSY),
so the post-command scrub is unconditional for the async path.
2026-09-16 19:53:59 +02:00
Daniele Lacamera 5f231a890c Fix: keep wolfBoot API declarations visible to app builds
c3f9717f guarded the success/trigger/sector-flag declarations behind
WOLFBOOT_FIXED_PARTITIONS, but wolfboot.h includes target.h only under
__WOLFBOOT, so test-apps (compiled without __WOLFBOOT) never saw the
macro and failed with implicit-declaration errors on imx95_m7, mcxa,
mcxw and mcxw-tz. Unguard the header declarations; keep the definitions
guarded and move wolfBoot_success out of the fixed-partition guard
since it only uses the partition-state API.
2026-09-16 18:31:59 +02:00
Daniele Lacamera 7feb9cbf67 Mark wolfBoot_invalidate_hdr_cache RAMFUNCTION
Called from the RAM-resident update path (update_ram.c) under
EXT_FLASH; place the body in RAM so it runs after flash remap
instead of faulting.

Verification: built unit-custom-trailer-nopart (EXT_FLASH) - compiles
clean; imx95_m7 (EXT_FLASH, CI repro) - compiles clean.
2026-09-16 18:17:48 +02:00
Daniele Lacamera c3f9717fb5 PR 892: address 3 Fenrir review findings
- libwolfboot.c: keep the partition state APIs (set/get_partition_state)
  available to CUSTOM_PARTITION_TRAILER / WOLFBOOT_NO_PARTITIONS builds;
  guard the fixed-partition APIs (sector flags, erase, trigger, success)
  behind WOLFBOOT_FIXED_PARTITIONS. Add the unit-custom-trailer-nopart
  compile target to lock in that configuration.
- unit-p1021-fcm-bytes.c: add program tests for status 0x81 (fail) and
  0x00 (write-protected), asserting no later page is programmed.
- unit-p1021-erase-advance.c: add an erase test for status 0x00
  (write-protected), asserting failure before advancing to the next block.
2026-09-16 17:19:16 +02:00
Daniele Lacamera 6814b503ef PR 892: address 6 Fenrir review findings
- hal/nxp_p1021.c: fix ONFI status polarity (bit 0 set = fail, bit 7
  clear = protected; was checking bits 0+1 set = success)
- src/libwolfboot.c: move partition state APIs under HAVE_PARTITION_TRAILERS
  so CUSTOM_PARTITION_TRAILER without WOLFBOOT_FIXED_PARTITIONS links
- src/x86/ata.c: do not zeroize DMA buffer when another async op is
  in progress (buffer still owned by first command's transfer)
- unit-p1021-fcm-bytes/erase-advance: update mocks to ONFI status bytes
- unit-update-ram-custom-trailer: add BOOT selection assertion via
  mock_max_read_addr, PID-suffixed temp files, unlink in cleanup
- unit-update-ram-nofixed-noramboot: unlink PID-specific temp files
2026-09-16 16:18:49 +02:00
Daniele Lacamera d316af6567 PR 892: TFES PxCI check + unique test temp files
- src/x86/ata.c: verify PxCI is clear in the TFES path before scrubbing
  the DMA buffer (symmetric with the success path; prevents scrubbing
  while the HBA may still reference the buffer)
- unit-update-ram-nofixed-noramboot.c: append PID to /tmp filenames to
  avoid collisions under parallel make -j or shared runners
2026-09-16 14:40:50 +02:00
Daniele Lacamera 66be5eb520 PR 892: P1021 NAND status bits + test coverage for F-12883/F-12922
- hal/nxp_p1021.c: fix JEDEC status bit polarity (DQ0 clear = fail,
  DQ1 clear = protected; was checking set bits)
- hal/s32k1xx.c: clarify watchdog timeout comment (65535 ticks at
  128kHz LPO = ~512ms unprescaled, ~131s with 1:256 prescaler)
- unit-keygen-xmss-params.c: assert wc_ForceZero + wc_FreeRng called
  after keygen (F-12883)
- unit-mock-flash.c: track largest ext_flash_read source addr/len
- unit-p1021-erase-advance.c: add test_erase_stops_on_status_fail
  (cmd succeeds but NAND reports DQ0 clear)
- unit-update-ram-noramboot.c: verify fallback loads from UPDATE
  partition, not oversize BOOT (F-12922)
2026-09-16 14:40:42 +02:00
Daniele Lacamera cc7fec1ea2 PR 892: anti-rollback for CUSTOM_PARTITION_TRAILER targets
Add HAVE_PARTITION_TRAILERS macro (set when WOLFBOOT_FIXED_PARTITIONS or
CUSTOM_PARTITION_TRAILER is defined) and use it to gate the TESTING state
transition in update_ram.c. Previously the gate was WOLFBOOT_FIXED_PARTITIONS
only, so targets using custom partition trailers never transitioned from
UPDATING to TESTING, allowing rollback to older versions.

Add unit-update-ram-custom-trailer test covering the CUSTOM_PARTITION_TRAILER
path with mocked get/set_trailer_at callbacks.
2026-09-16 14:30:26 +02:00
Daniele Lacamera b7857b99f9 F-12077: wolfBoot_ram_decrypt is not AES-only
Decryption is ChaCha20, AES-CTR, or PKCS#11 per build config; the doc
implied AES only.
2026-09-16 12:15:37 +02:00
Daniele Lacamera 44908c3e5d F-12076: ext_flash_decrypt_read is not AES-only
Decryption is ChaCha20, AES-CTR, or PKCS#11 per build config; the doc
implied AES only.
2026-09-16 12:15:31 +02:00
Daniele Lacamera 17d6cc2604 F-12892: wolfBoot_update_trigger acts on the update partition
The function sets the update partition state to IMG_STATE_UPDATING and
erases the update partition last sector; the doc said boot partition.
2026-09-16 12:15:23 +02:00
Daniele Lacamera 180647eb1c F-12893: drop invented @return from set_update_sector_flags doc
set_update_sector_flags is void; the doc claimed a 0/-1 status return.
2026-09-16 12:15:15 +02:00
Daniele Lacamera bed6df776d F-9255: fix eMMC ready-bit polarity in comment
The code treats OCR bit 31 set as ready (response & MMC_OCR_BUSY_BIT);
the comment said busy bit cleared equals ready.
2026-09-16 12:15:08 +02:00
Daniele Lacamera c8b799bda9 F-11013: SDHCI no-base-clock path returns 0 as an error
The no-base-clock path disables the clock and returns 0 (error),
unlike the already-set path above which returns last_clock_khz.
The old NOTE claimed callers could not tell the two apart.
2026-09-16 12:15:00 +02:00
Daniele Lacamera e32ea8a659 F-12891: wolfBoot_tpm2_extend PCR range is 0-23
PCR 24 is not a valid extend target; the doc said 0-24.
2026-09-16 12:14:13 +02:00
Daniele Lacamera 43a0e59f37 F-12890: change_stack_and_invoke has no callback arg
The function takes (new_stack, other_func) only; the doc described a
nonexistent 'ptr' parameter.
2026-09-16 12:14:13 +02:00
Daniele Lacamera ae2145a380 F-9724: partial-flash-write uses bitwise NOT
The formula is data | ~current_data (bitwise); the comment used the
logical '!'
2026-09-16 12:14:13 +02:00
Daniele Lacamera c58a6905f0 F-9723: non-MMU handoff clears r0-r3, not all GPRs
The code clears only r0-r3 for the handoff; the comment said all
GPRs cleared.
2026-09-16 12:14:13 +02:00
Daniele Lacamera c527ac7ee1 F-9261: sector-size check allows equality
The #if fires on WOLFBOOT_SECTOR_SIZE < IMAGE_HEADER_SIZE, so equal
is accepted; the comment and #error said 'larger than'.
2026-09-16 12:14:13 +02:00
Daniele Lacamera b9f5cfdefe F-9260: S32K watchdog timeout is ~131s, not ~2s
WDOG_TOVAL=0xFFFF with a 1:256 prescaler at 128kHz LPO gives
~131 seconds, not ~2 seconds.
2026-09-16 12:14:13 +02:00
Daniele Lacamera d170977f50 F-9259: T2080 handoff sets TCR to 0
wolfBoot clears TCR to 0 (matching CW U-Boot pre-bootm); the
comment described the old 0x04000000 value.
2026-09-16 12:14:13 +02:00
Daniele Lacamera 96cd60d28d F-9258: SPI cont keeps CS low (asserted)
cont!=0 holds chip-select asserted (low) after the transfer; the
comment said 'not let CS go low'.
2026-09-16 12:14:13 +02:00
Daniele Lacamera 7a6e450ec6 F-9257: DDR training retry: WRCALIB is the gate
The reliability gate is WRCALIB, not PHY_TRAINING_STATUS. MTC is a
secondary gate skipped when TIP completes full training, and the
retry budget is 3 inner x 6 outer (up to 18 attempts), not 5.
2026-09-16 12:14:13 +02:00
Daniele Lacamera 36c57846f5 F-9256: rejected ELF does not rewrite the entry point
The rationale that a rejected ELF leaves load_address rewritten no
longer matches the code. The skip flag is set on each stage's
success path.
2026-09-16 12:14:13 +02:00
Daniele Lacamera a2e6238183 F-9254: XMSS import error comment named LMS params
The failing call is wc_XmssKey_ImportPubRaw; the error comment
referenced LMS parameters.
2026-09-16 12:14:13 +02:00
Daniele Lacamera 09f0c9a5a3 F-9253: disk_open accepts GPT or MBR, not GPT-only
The @return contract said 'no valid GPT partition table' but
disk_open falls back to parsing an MBR when no protective-MBR GPT
is present.
2026-09-16 12:14:13 +02:00
Daniele Lacamera 9f456bf864 F-9252: fix MPU system-control range end address
Comment said 0xE0000000:0xEFFFFFF (255M) but the system-control
region is 256M, ending at 0xEFFFFFFF.
2026-09-16 12:14:13 +02:00
Daniele Lacamera dcc6c64bd7 unit-tests: pin -std=gnu17 for host test builds
GCC 14+ defaults to gnu23, where glibc string.h defines memchr
and memcpy as _Generic macros that clash with wolfBoot's own
declarations in tests that #include a .c file (unit-string).
gnu17 matches the CI toolchain default.
2026-09-15 18:04:21 +02:00
Daniele Lacamera c1a7d89b2d unit-tests: mock wc_FreeRng for keygen_die
keygen_die() (F-9767) calls wc_FreeRng(); the test mocks
keygen.c's wolfCrypt dependencies one by one and was missing
this one, breaking the unit_tests and test_external_libs jobs.
2026-09-15 18:04:21 +02:00
Daniele Lacamera 4ca67c3063 F-13615: keep TFM_TIMING_RESISTANT for secure-mode fastmath builds
Secure-mode worlds (TZ_PSA/PKCS11/FWTPM/WOLFHSM) process private keys
in software, so a USE_FAST_MATH build of one of them must keep the
timing-resistant TFM path instead of falling back to WC_NO_HARDEN.
The old condition only covered software DICE; FIPS=1 already forces
SPMATH (options.mk M10) and all CMake presets set SPMATH, so no
shipped config changes - this closes the integrator Makefile gap.
WOLFBOOT_DICE_HW stays verify-only (requires WOLFCRYPT_TZ_PSA).
2026-09-15 16:08:57 +02:00
Daniele Lacamera 908d4ec1e3 F-7048: make UDS all-value scan constant-time
buffer_is_all_value() early-exited on the first byte differing from
the target, so the loop trip count leaked the length of the leading
0xFF/0x00 run of the UDS, the DICE root secret read in
hal_uds_derive_key().

Replace the early exit with a volatile |= accumulator over the full
buffer, matching the constant-time compare pattern already used by
image_CT_compare() and the other secret comparisons in the tree.

Verified: gcc -S -O2 shows a straight-line loop body with only the
data-independent i < len branch; arm-none-eabi-gcc (stm32h5 preset)
compiles the file clean.

Reported by Fenrir.
2026-09-15 15:48:15 +02:00
Daniele Lacamera 5f6eb05552 F-6764: scrub passphrase buffer when async ATA command completes
security_command_passphrase() only wiped the static DMA buffer on the
synchronous path; in async mode (ata_security_erase_unit) the
passphrase stayed resident in the file-static buffer for the rest of
the boot, since ata_cmd_complete_async() never scrubbed it.

Add a scrub_buffer flag to the async state, set it when the command
goes in flight (or wipe immediately if it never started), and scrub in
ata_cmd_complete_async() on both the success and task-file-error exits,
once the HBA has retired the command.

Covered by two new unit tests: scrub after async completion and after
an async port error; the in-flight state is asserted unscrubbed.

Reported by Fenrir.
2026-09-15 15:43:11 +02:00
Daniele Lacamera 19d8a42303 F-6765: scrub previous value before overwriting PSA storage
ARM_TEE_PS_SET on an existing object XMEMCPY'd the new value over the
old one without clearing the buffer first, so a SET that stores less
data (or zero data) left the tail of the previous object readable
through ARM_TEE_PS_GET.

Zero the full data area with wc_ForceZero after every validation check
passes and before the copy, matching the DELETE path.

Reported by Fenrir.
2026-09-15 15:35:10 +02:00
Daniele Lacamera b97d94deeb F-9768: rot: scrub NV auth and session state at exit
The TPM NV auth copy and the HMAC session state lived on the
stack until process teardown. Zeroize both at the common exit
label after the TPM device is unloaded, on success and error
paths alike.
2026-09-15 15:21:54 +02:00
Daniele Lacamera 483facf339 F-9767: keygen: free RNG before helper failure exit
keygen_ed25519/ed448/lms/xmss/ml_dsa have the same bypass as
the RSA/ECC helpers: exit() from their cleanup labels skips
main()'s wc_FreeRng(). Route their failure exits through
keygen_die() as well.
2026-09-15 15:19:25 +02:00
Daniele Lacamera a08badf880 F-8008: keygen: free RNG before helper failure exit
keygen_rsa/keygen_ecc exit() from their own cleanup labels,
bypassing main()'s wc_FreeRng() and leaving DRBG state resident.
Add keygen_die() that frees and zeroes the RNG before exit and
use it in the two helpers' failure paths.
2026-09-15 15:14:38 +02:00
Daniele Lacamera b1884b03d7 F-7394: sign: free RNG on RSA-PSS unsupported-hash error
The error path returned before the common wc_FreeRng(), leaving
DRBG state on the stack. Route it through the shared cleanup and
guard the sign call so hash_type/mgf are only used when set.
2026-09-15 15:14:38 +02:00