Commit Graph

3100 Commits (d175c819cd1589bfbfcd08a4d2ff92f87846bfb0)

Author SHA1 Message Date
Daniele Lacamera d175c819cd F-4645: bound load_linux kernel size to prevent syssize*16 overflow
load_linux() computed the protected-mode kernel size as the uint32_t
product param.hdr.syssize * 16 (src/x86/linux_loader.c), where syssize
is copied verbatim from the (authenticated) bzImage at offset 0x1f4.
The multiplication wraps for any syssize > 0x0FFFFFFF: syssize=0x10000000
yields kernel_size=0 (DoS), and syssize=0x1FFFFFFF/0xFFFFFFFF yields
kernel_size=0xFFFFFFF0 (~4 GiB). That value fed straight into
memcpy((uint8_t*)KERNEL_LOAD_ADDRESS, linux_image + param_size,
kernel_size) with no cap, overwriting wolfBoot stage2, FSP data, and the
heap (CWE-190 -> CWE-680).

Fix at the root: linux_kernel_size() computes syssize * 16 in 64-bit and
rejects the image (panic) when the result is zero or does not fit in the
destination window [KERNEL_LOAD_ADDRESS, tolum). tolum is the top of low
usable memory the FSP already reports and that the ELF boot path uses as
its load upper bound (src/boot_x86_fsp_payload.c). The kernel load only
runs under WOLFBOOT_FSP (the non-FSP path panics earlier at the memory
map step), so tolum is always available there.

Add unit-linux-loader-syssize regression test (x86 32bit, standalone)
that feeds the PoC overflow values and asserts they are rejected while a
legitimate kernel and the exact-fit boundary are accepted.
2026-06-05 19:33:51 +02:00
Daniele Lacamera 2766450123 F-4710: reject oversized FDT property length to prevent ~4GB FIT memcpy
fdt_next_tag() advanced its struct cursor with
  offset += sizeof(struct fdt_property) - FDT_TAGSIZE + fdt32_to_cpu(*lenp);
using unsigned arithmetic. A property whose len field is 0xFFFFFFFF
wrapped this to a +7 advance, so the malformed node slipped past the
fdt_offset_ptr() bounds check at the end of fdt_next_tag(). The bogus
length then propagated up through fdt_get_property_by_offset() /
fdt_getprop() and was returned by fit_load_image() as *lenp = -1.

In the MMU FIT boot path, wolfBoot_start() (src/update_ram.c:465) aliases
that out-parameter through (int*)&dts_size, turning -1 into a uint32_t
0xFFFFFFFF, and the only guard before the relocation is dts_ptr != NULL,
so memcpy(WOLFBOOT_LOAD_DTS_ADDRESS, dts_ptr, 0xFFFFFFFF) ran (CWE-680).
A FIT subimage with no "load" property reaches this with the inner copy
skipped, so the giant size hits the outer DTS relocation directly.

Fix at the root: a property value can never exceed the blob, so reject
any FDT_PROP whose declared length is greater than fdt_totalsize()
before the cursor arithmetic. This closes the wrap for every caller of
fdt_next_tag() (including the other fit_load_image() sinks), not just the
DTS path. Legitimate properties (len <= size_dt_struct < totalsize) are
unaffected.

Add a regression test to unit-fdt: a hand-built FIT whose /images/kernel-1
"data" property declares len=0xFFFFFFFF must make fit_load_image_ex()
fail closed (return NULL) instead of handing back a live pointer with a
negative length. The test fails before this change and passes after.
2026-06-05 19:26:28 +02:00
Daniele Lacamera a8a9eec96b F-4711: bound e820 entries to prevent boot_params stack overflow
e820_add_entry_cb() appended every FSP-supplied resource descriptor into
boot_params->e820_table[] with no check against E820_MAX_ENTRIES_ZEROPAGE
(128). A HOB list with more than 128 EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
entries therefore wrote FSP-controlled addr/size/type triples past the
fixed-size table into the stack-allocated boot_params in load_linux(),
corrupting adjacent fields and the saved return address.

Reject any entry once the table is full (return non-zero, which aborts the
HOB iteration). e820_entries stays uint8_t since it is a fixed-offset field
in the Linux zero-page layout and the cap makes the 256 wrap unreachable.

Add unit-linux-loader-e820 regression test (x86 32bit, standalone) that
feeds 200 descriptors and asserts the table never overflows.
2026-06-05 19:19:05 +02:00
Daniele Lacamera 277e8013cc F-4965: bound hdr->pos in bitmap_put to prevent OOB write from corrupted vault
A power fault during cache_commit(0) can leave a node header in the
keyvault with valid magic/tok/obj/type but pos left as erased flash
(0xFFFFFFFF). On the next boot find_object_buffer() detects the
data-sector mismatch and calls delete_object(), which reaches
bitmap_put(0xFFFFFFFF, 0). bitmap_put computed octet = pos/8 and indexed
cached_sector[4 + octet] with no bounds check, writing ~512 MB past the
static sector buffer. Reject pos >= KEYVAULT_MAX_ITEMS so a corrupted
header can no longer turn into an out-of-bounds write.

Adds a unit test that seeds a node with pos=PKCS11_INVALID_ID and
confirms delete_object() no longer faults.
2026-06-05 19:13:36 +02:00
Daniele Lacamera 8cff2e8792 F-5672: cache NS in_vec[1].len in ARM_TEE_PS_SET to close TOCTOU double-fetch
The ARM_TEE_PS_SET branch of arm_tee_psa_call() read in_vec[1].len
directly from non-secure memory four times: the WOLFBOOT_PS_MAX_DATA
bounds check, the null-data guard, the copy gate, the XMEMCPY length,
and the entry->size assignment. in_vec lives in NS RAM, and on ARMv8-M
with AIRCR.PRIS=0 a higher-priority NS interrupt can preempt Secure
thread-mode execution (and an NS-accessible DMA engine can mutate NS RAM
independently) between the bounds check and the copy. An NS attacker
racing either mechanism could grow the length past WOLFBOOT_PS_MAX_DATA
after it was validated, overflowing the fixed entry->data[512] buffer in
Secure SRAM into adjacent Secure globals.

Snapshot the length once into a Secure-stack local (data_len) right
after capturing the in_vec bases and use only that local for every
subsequent check, the XMEMCPY operand, and entry->size. This follows the
standard PSA/CMSE practice of copying NS-supplied scalars to the Secure
stack before validating and using them.
2026-06-05 18:50:47 +02:00
David Garske e27e81f659 Improve SRAM partitioning for Ethernet DMA 2026-06-03 10:54:20 +02:00
David Garske 1e4fbc49b2 Peer review fixes (thanks Copilot) 2026-06-03 10:54:20 +02:00
David Garske bbb4d66479 stm32h5: clear MPCBB SRAM2/3 PRIVCFGR so NS ETH DMA can access them 2026-06-03 10:54:20 +02:00
David Garske 5b51344421 stm32h5: cede SRAM2 + clear GPIO SECCFGR for NS apps (TZEN=1) 2026-06-03 10:54:20 +02:00
David Garske 8fe46bb40f Peer review fixes (thanks Copilot)
hal/stm32g4.c:
- hal_flash_write unaligned path: rebase the aligned doubleword on
  (address + i), not the initial address; index as dst[0]/dst[1].
  The old form skipped to the wrong DW once i advanced past 8 with
  an unaligned starting address.
- hal_flash_erase: end_address was address + len - 1 paired with a
  strict less-than, which dropped the last page when len straddled a
  page boundary by one byte. Use address + len.
- flash_clear_errors / EOP clear at end of hal_flash_write: FLASH_SR
  bits are W1C. Read-modify-write via |= can clear unrelated W1C
  bits that happen to be set. Write the mask directly.
- uart_write: cast through uint8_t before promoting to uint32_t so
  high-bit chars do not sign-extend into TDR.

hal/stm32g4.h:
- DMB/ISB/DSB: add the "memory" clobber so the compiler also treats
  them as scheduling barriers, not just hardware-level fences.

hal/stm32g4.ld:
- Rename the output section .edidx to .ARM.exidx to match the
  input-section pattern and standard Cortex-M linker scripts.
2026-05-29 13:10:15 +02:00
David Garske c075549ea2 Add wolfBoot support for STM32G4 2026-05-29 13:10:15 +02:00
David Garske 0cb6bd42ac Vorago VA416x0: simplify iram_write/iram_fill (single RMW path) 2026-05-29 13:09:19 +02:00
David Garske 9786f5608b Add wolfBoot port for STM32N6 (NUCLEO-N657X0-Q)
Co-authored-by: Aidan Garske <aidan@wolfssl.com>
2026-05-28 16:49:57 +02:00
Brett Nicholas a1f86fa1c2 expose root CA list as makefile var 2026-05-26 17:37:50 +02:00
Brett Nicholas b8bc0a75e5 Add support for wolfHSM multi-root certificate verification 2026-05-26 17:37:50 +02:00
Alex Lanzano a41a98551b Fix mcxn build by providing the RNG for TZ_PSA builds 2026-05-26 17:13:17 +02:00
Yosuke Shimizu f4d5340641 Add hardware-based DICE on mcxn 2026-05-21 20:49:20 +02:00
David Garske b983fa7717
Merge pull request #783 from Frauschi/mldsa_rename
Continue the ML-DSA renaming
2026-05-19 12:03:28 -07:00
Tobias Frauenschläger 6e60abd034 Continue the ML-DSA renaming 2026-05-19 11:21:20 -07:00
David Garske 6e3c43e44e
Merge pull request #781 from Frauschi/mldsa_rename
ML-DSA rename part 1
2026-05-19 06:47:22 -07:00
Tobias Frauenschläger cab04ad789 Update wolfssl submodule to latest master
* file level rename for ML-DSA
* Add missing source file to build system
* Update some macros
* Other minor fixes
* Update size limitations for some slight increases
2026-05-18 23:02:54 -07:00
David Garske c3d255d8ed Vorago VA416x0: harden iram_write/iram_fill per review
Two follow-ups to the IRAM shadow update fix (da96f5a2):

1. Mark the bulk-copy destination as volatile uint32_t * so the compiler
   cannot lower a 32-bit assignment into byte/halfword stores. Sub-word
   stores are silently dropped by the IRAM ECC, so a future codegen
   change could have broken the workaround.

2. Use (uintptr_t)3u / ~(uintptr_t)3u for alignment masking. On targets
   where uintptr_t is wider than unsigned int the bare ~3u would zero
   the high half of the address; harmless on Cortex-M4 today, but the
   helper pattern is easy to copy elsewhere.

The int len type is kept to match the wolfBoot ext_flash_* HAL signature
convention across all ports.

Verified with arm-none-eabi-objdump: aligned bulk path emits only 32-bit
str instructions (no strb/strh).
2026-05-13 18:35:30 +02:00
David Garske 08c6673407 Fix Vorago VA416x0 IRAM shadow update (use word-aligned stores)
The VA416xx code RAM (IRAM at 0x00000000-0x0003FFFF) silently drops 8-bit
and 16-bit stores when ROM_PROT.WREN=1 - only word-aligned 32-bit stores
are honored, because the ECC machinery computes parity per 32-bit word
and rejects sub-word writes (no fault is raised). wolfBoot's local
memcpy()/memset() are byte-wise (ldrb/strb), so the IRAM shadow update
in ext_flash_write/read/erase appeared to succeed but actually left
the destination unchanged. The FRAM content was updated correctly, but
after the swap wolfBoot branched into the partition at 0xB800 in IRAM
where the stale image still lived, so the running app was the OLD
version even though the partition header (read from FRAM) reported the
new version.

Add iram_write/iram_fill helpers that use 32-bit stores for the bulk
of an aligned region and read-modify-write the containing word for any
unaligned head/tail, and use them in ext_flash_write/read/erase in
place of memcpy/memset for the shadow update. Partition addresses are
sector-aligned so in practice the path is always pure 32-bit stores.

Verified end-to-end on VA41630-EVK with build_test.sh update: app v1
boots, trigger sets, swap runs sector-by-sector, post-swap boot prints
"Booting version: 0x2" and the running app prints v2-specific output
in TESTING state. After wolfBoot_success() and a manual reset the
second boot reports state CONFIRMED.
2026-05-13 18:35:30 +02:00
David Garske b94954eab4 Add Xilinx Zynq-7000 (ZC702) wolfBoot port 2026-05-12 12:06:05 +02:00
David Garske 7b0bee50de
Merge pull request #773 from twcook86/lpc55s69_crypto_2
Fix lingering lpc55s69 issues
2026-05-08 15:59:20 -07:00
Thomas Cook 6093b68f15 Fix lingering lpc55s69 issues 2026-05-07 17:06:35 -04:00
Mattia Moffa 1ce8234e49 Add kinetis LMS small config 2026-05-07 21:39:34 +02:00
Mattia Moffa 8a70a83039 Change ECC partitioning 2026-05-07 21:39:34 +02:00
Mattia Moffa fda8668cc3 Address Copilot comments 2026-05-07 21:39:34 +02:00
Mattia Moffa dc6cfaaf83 Kinetis KL26 port 2026-05-07 21:39:34 +02:00
Mattia Moffa 6ff19bf492 Address Copilot suggestions 2026-05-06 19:03:12 +02:00
Mattia Moffa 26981e0da5 update_flash_hwswap: remove dead code
F#3538
2026-05-06 19:03:12 +02:00
Mattia Moffa b6235ce079 OTP keystore getters: check id < 0
F#3543
2026-05-06 19:03:12 +02:00
Mattia Moffa f8bc66d825 arm_tee_psa_ipc: validate in_vec/out_vec base and length before dereferencing in crypto dispatcher
F#3541, F#3542
2026-05-06 19:03:12 +02:00
Mattia Moffa e8212dd2ec Check TLV fields' size is correct in image headers
F#3540
2026-05-06 19:03:12 +02:00
Mattia Moffa 1ec402ea18 Unit tests: check hal_flash_protect actually gets called
F#3539
2026-05-06 19:03:12 +02:00
Mattia Moffa f2b95c2563 STM32H5, STM32U5, STM32L5: fix off-by-one error in hal_flash_erase
F#3537
2026-05-06 19:03:12 +02:00
Mattia Moffa 871dd854ff Flash test: fix off-by-one error
F#3536
2026-05-06 19:03:12 +02:00
Mattia Moffa 481ff1ffdb trailer_write: exit on error
F#3535
2026-05-06 19:03:12 +02:00
Mattia Moffa 172ecdc975 Sign tool: fix wrong fread/fwrite API usage when HAVE_MMAP==0
(F#3534)
2026-05-06 19:03:12 +02:00
David Garske af40ae1471 Add STM32C5 target (NUCLEO-C5A3ZG) 2026-05-06 19:02:58 +02:00
Mattia Moffa d69086c39a
Merge pull request #772 from danielinux/otp-fix-string
Fix initialization of string in otp_keystore tag
2026-05-06 13:59:25 +02:00
Daniele Lacamera d1df8b2df0 Fix initialization of string in otp_keystore tag (fix build error)
Emerged in newer gcc15, due to -Wunterminated-string-initialization
added to -Wall
2026-05-06 10:22:59 +02:00
Brett Nicholas 9a667f2a75 set TC3 ARCH_FLASH_OFFSET with ?= 2026-05-05 16:37:54 +02:00
Brett Nicholas dd8accdc87 increase size 2026-05-05 16:37:54 +02:00
Brett Nicholas 8f191b9f3a enable WOLFBOOT_IMG_HASH_ONESHOT for all AURIX configs 2026-05-05 16:37:54 +02:00
Brett Nicholas 24841a0eb8 support AURIX hw accel 2026-05-05 16:37:54 +02:00
Brett Nicholas 8ac4838b92 tc3: disable/capture bus errors for lifetime of bootloader 2026-05-05 16:37:54 +02:00
Brett Nicholas 149db43612 tc3: add echo test to test-app when wolfHSM is enabled 2026-05-05 16:37:54 +02:00
Brett Nicholas f5a8efeb25 tc3: fix for latest wolfHSM, remove devId from cryptoCtx as it no longer exists 2026-05-05 16:37:54 +02:00