wolfBoot/tools/unit-tests
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
..
Makefile F-4645: bound load_linux kernel size to prevent syssize*16 overflow 2026-06-05 19:33:51 +02:00
README.md
gpt-sfdisk-test.h
target.h Preparing release v2.8.0 + update copyright 2026-04-16 13:11:56 +02:00
txt_filler.h
unit-boot-x86_fsp.c
unit-common.c Preparing release v2.8.0 + update copyright 2026-04-16 13:11:56 +02:00
unit-delta.c Cap backward delta match length 2026-04-29 11:34:23 +02:00
unit-disk.c Add GPT single-sector partition test 2026-04-29 12:24:41 +02:00
unit-enc-nvm.c Preparing release v2.8.0 + update copyright 2026-04-16 13:11:56 +02:00
unit-extflash.c Preparing release v2.8.0 + update copyright 2026-04-16 13:11:56 +02:00
unit-fdt.c F-4710: reject oversized FDT property length to prevent ~4GB FIT memcpy 2026-06-05 19:26:28 +02:00
unit-fit-gzip.c Peer review fixes (copilot) 2026-05-05 10:16:16 +02:00
unit-fwtpm-stub.c Proper interface renaming + documentation 2026-04-22 14:14:28 +02:00
unit-gzip.c Peer review fixes (copilot) 2026-05-05 10:16:16 +02:00
unit-image.c review feedback 2026-05-05 16:37:54 +02:00
unit-keygen-xmss-params.c Fix XMSS keygen param fallback 2026-04-29 12:30:23 +02:00
unit-keystore.c Preparing release v2.8.0 + update copyright 2026-04-16 13:11:56 +02:00
unit-linux-loader-e820.c F-4711: bound e820 entries to prevent boot_params stack overflow 2026-06-05 19:19:05 +02:00
unit-linux-loader-syssize.c F-4645: bound load_linux kernel size to prevent syssize*16 overflow 2026-06-05 19:33:51 +02:00
unit-loader-tpm-init.c
unit-max-space.c
unit-mock-flash.c Preparing release v2.8.0 + update copyright 2026-04-16 13:11:56 +02:00
unit-mock-state.c Preparing release v2.8.0 + update copyright 2026-04-16 13:11:56 +02:00
unit-multiboot.c Fix multiboot debug header length guard 2026-04-29 11:27:58 +02:00
unit-nvm.c Preparing release v2.8.0 + update copyright 2026-04-16 13:11:56 +02:00
unit-parser.c Preparing release v2.8.0 + update copyright 2026-04-16 13:11:56 +02:00
unit-pci.c Preparing release v2.8.0 + update copyright 2026-04-16 13:11:56 +02:00
unit-pkcs11_store.c F-4965: bound hdr->pos in bitmap_put to prevent OOB write from corrupted vault 2026-06-05 19:13:36 +02:00
unit-policy-create.c
unit-policy-sign.c
unit-psa_store.c
unit-qspi-flash.c Abort QSPI writes after WE failure 2026-04-29 12:13:40 +02:00
unit-rot-auth.c
unit-sdhci-disk-unaligned.c
unit-sdhci-response-bits.c
unit-sectorflags.c Add sector flag unit coverage 2026-04-29 12:26:55 +02:00
unit-sign-encrypted-output.c
unit-sign-encrypted-output.mkfrag Update wolfssl submodule to latest master 2026-05-18 23:02:54 -07:00
unit-spi-flash.c Preparing release v2.8.0 + update copyright 2026-04-16 13:11:56 +02:00
unit-store-sbrk.c Preparing release v2.8.0 + update copyright 2026-04-16 13:11:56 +02:00
unit-string.c Preparing release v2.8.0 + update copyright 2026-04-16 13:11:56 +02:00
unit-tpm-api-names.c Bound TPM name fallback copies 2026-04-29 12:16:03 +02:00
unit-tpm-blob.c
unit-tpm-check-rot-auth.c
unit-tpm-rsa-exp.c
unit-uart-flash.c Addressed copilot's comments 2026-04-29 13:15:52 +02:00
unit-update-disk.c Unit tests: check hal_flash_protect actually gets called 2026-05-06 19:03:12 +02:00
unit-update-flash.c Unit tests: check hal_flash_protect actually gets called 2026-05-06 19:03:12 +02:00
unit-update-ram-nofixed.c Unit tests: check hal_flash_protect actually gets called 2026-05-06 19:03:12 +02:00
unit-update-ram.c Unit tests: check hal_flash_protect actually gets called 2026-05-06 19:03:12 +02:00

README.md

Unit Test Tools

This uses the "check" unit test framework for C.

You may need to run "apt install check", "yum install check" or "brew install check".

Building

Use make to build.

Expected output

$ ./unit-parser
Running suite(s): wolfBoot
Explicit end of options reached
This field is too large (bigger than the space available in the current header)
This field is too large and would overflow the image header
Illegal address (too high)
Illegal address (too high)
100%: Checks: 2, Failures: 0, Errors: 0