Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ jobs:
ci-gate:
name: CI Gate
runs-on: ubuntu-22.04
needs: [test, build-arm, static-analysis]
needs: [test, build-arm, fuzz-build, static-analysis]
if: always()
steps:
- uses: actions/checkout@v4
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/eosim-sanity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ jobs:
install-validate:
name: Install & Validate (${{ matrix.os }}, Python ${{ matrix.python-version }})
runs-on: ${{ matrix.os }}
# Every step here is written in bash: `$(...)`, `|| { ... }`, a heredoc,
# and /tmp. Without this the Windows legs ran them under PowerShell, where
# `SITE_PACKAGES=$(...)` is an unknown command and the job went red, while
# the `|| { exit 1 }` guard in "Verify installation" parsed as an unexecuted
# script block and could never fail.
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: ossf/scorecard-action@v2.4.0
- uses: ossf/scorecard-action@v2.4.3
with:
results_file: results.sarif
results_format: sarif
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
- **`image_verify.c`:** `eos_image_verify_integrity` rejects a zero `image_size`, and an `addr + hdr_size` that wraps `uint32_t`, instead of computing a payload address that is not the payload.

### Fixed
- **Stage-0 refuses a stage-1 image it could not read.** The stage-1 hash loop in `stage0/jump_stage1.c` discarded `eos_hal_flash_read()`'s result, so a failed read hashed the previous chunk (or the stack) as if it were stage-1; the mismatch that followed reached recovery with the wrong reason (`0xBAD1`, hash mismatch), and only by luck. A failed read now enters recovery with its own reason (`EBLDR_FAIL_STAGE1_READ`, `0xBAD2`) and never falls through to the jump, matching what `eos_crypto_verify_image()` in `core/` already does. The hash-mismatch path (`EBLDR_FAIL_STAGE1_HASH`, `0xBAD1`) and the recovery-trigger path had the same fall-through -- `eos_recovery_enter()` with nothing after it, so a failed verification reached the `IMAGE_VALID` record and the jump, held back only by recovery never returning -- and both now return. The two detail codes are named in `include/eos_types.h` beside the `EOS_LOG_*` events. `tests/unit/test_stage0_hal_results.py` is a source-level guard that every HAL read or write in `stage0/` has its result tested (not merely assigned; preprocessor lines are ignored), and that every entry into recovery in `ebldr_stage0_main()` is followed by a return.
- **The stage-1 image was empty, and stage-0 verified it anyway.** On every board build with a stage-1 linker script, `eboot_firmware.bin` was 0 bytes: `stage1/` exported `eboot_main()` only, the script had no `ENTRY()` and kept no section, and with `-nostartfiles` and `--gc-sections` the linker had nothing to anchor. `tools/embed_stage1_hash.py` took the size verbatim and emitted `stage1_expected_size = 0u` with the SHA-256 of the empty string; `stage0/jump_stage1.c` ran its hash loop zero times, matched nothing against nothing, recorded `IMAGE_VALID` and jumped. Three independent fixes: `stage1/reset_entry.c` now owns the vector table and the reset handler (stack pointer, `Reset_Handler` into `eboot_main()`, faults and the system exceptions through SysTick) and `boards/stm32f4/stm32f4_stage1.ld` has `ENTRY(Reset_Handler)` and keeps `.isr_vector`, so the stm32f4 stage-1 links to 13,416 bytes and the embedded digest is that image's; the embed tool refuses an empty image outright and one below a 4096-byte floor (`--min-size`); and stage-0 refuses `stage1_expected_size == 0` before the loop (`EBLDR_FAIL_STAGE1_NO_IMAGE`, `0xBAD3`), because a bootloader does not trust its own build. Stage-0's own vector table stopped at UsageFault while `board_early_init()` enables the SysTick interrupt, so the first tick fetched a handler address from the code after the table; both tables now run through SysTick. `cortex_r5` is left as it was: both of its linker scripts keep `.vectors`, which nothing in the tree emits, so both of its images link to zero bytes and the embed tool now stops that board's build at the empty stage-1 instead of describing it; the port needs an entry shape of its own (#137), and the guard names it as a strict expected failure until then. The guard also checks that every section a stage script keeps is one some source file emits, which is the mismatch that produced both empty images. `tests/unit/test_stage1_image_is_verified.py` pins all of it.
- **The tree did not configure, compile or link after the 09-07 batch merge.** `tests/CMakeLists.txt` registered `eboot_test_fdt_loader` twice; `core/sha512.c` had been replaced by a version predating the `bitlen[2]`/`buffer_len` context; `core/boot_log.c`, `core/secure_boot.c` and `core/fdt_loader.c` had been dropped from `eboot_core`; `scalarbase()` and `k_low_order[]` were defined twice; and the `eos_boot_log_get_head()` declaration was lost. All restored.
- **Install-path verification order settled: signature before anti-rollback.** `eos_fw_update_finalize()` verifies the Ed25519 signature over the signed header prefix first and reads the TLV security counter only after the prefix that binds it is authenticated (see `docs/adr/ADR-020`). The `fw_update` and `fw_transport` suites now stream genuinely signed images; `tools/gen_fw_update_test_sigs.py` emits their signatures as `tests/vectors/fw_update_test_sigs.h`, and `tests/unit/test_fw_update_test_sigs.py` pins the committed header to the generator's output.
- **`tests/CMakeLists.txt`:** the Valgrind list is derived from the registered suites again; a hand-written copy had replaced it, eleven registered suites were missing from `EBLDR_UNIT_TESTS`, and seven of those (`test_eos_sign_boot_path`, `test_fdt_loader`, `test_fw_decrypt`, `test_fw_update_sig`, `test_jump_app_bounds`, `test_qemu_arm64_timer`, `test_secure_boot_policy`) had no Valgrind run at all; the other four were only in the hand-written list. All eleven are appended.
- **`.github/workflows/ci.yml`:** `fuzz-build` is in the CI gate. It was added after the gate job and the gate never waited for it.
- **Unit suites count `tests_run`** as each test executes instead of assigning it a literal that the summary line then trusted.
- **`.github/workflows/eosim-sanity.yml`:** the install-validate job's steps are bash and now run under `shell: bash` on the Windows legs, where PowerShell rejected `SITE_PACKAGES=$(...)` and parsed `|| { exit 1 }` as an unexecuted script block.
- **`.github/workflows/scorecard.yml`:** `ossf/scorecard-action` moved to v2.4.3, the release hosted on ghcr.io; v2.4.0 pulls from gcr.io, which now requires GCP billing.
- **The tree did not compile.** `include/eos_image.h` declared `eos_crc32()` as `int eos_crc32(uint32_t, size_t, uint32_t *)` while `core/image_verify.c` defined it as `uint32_t eos_crc32(uint32_t, size_t)` -- a conflicting-types error that stopped the build at the first core source file. The declaration now matches the definition and the documented behaviour.
- **`ed25519_verify.c`:** `eos_ed25519_verify()` never performed the verification. Two merged copies of the challenge-hash step had been left in the function, the second referring to identifiers that do not exist (`sha512_ctx_t`, `sc_reduce`), and RFC 8032 step 4 -- the `[S]B == R + [k]A` check -- was absent entirely, leaving the function returning an undeclared `diff`. The duplicate is removed and the group-equation check restored; the function now passes the RFC 8032 test vectors and rejects tampered messages, every single-bit signature flip, wrong keys and malleated signatures.
- **`recovery.c`:** `recovery_handle_write()` declared `slot_size` twice, which does not compile. The bounds check now calls `eos_recovery_write_in_range()` -- the helper the unit tests already exercise -- so the wire-input rule has one definition, and an unmapped slot (`base == 0`) is rejected too.
Expand Down
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ target_include_directories(eboot_hal PUBLIC ${EBLDR_INCLUDE_DIR})
# ---- Core boot logic ----
add_library(eboot_core STATIC
core/bootctl.c
core/boot_log.c
core/image_verify.c
core/slot_manager.c
core/boot_policy.c
Expand All @@ -106,8 +107,10 @@ add_library(eboot_core STATIC
core/os_adapter.c
core/ed25519_verify.c
core/sha512.c
core/keystore.c
core/secure_boot.c
core/fdt_loader.c
core/rollback.c
core/keystore.c
core/debug_lock.c
core/fw_decrypt.c
core/image_tlv.c
Expand Down Expand Up @@ -381,7 +384,10 @@ if(NOT EBLDR_BOARD STREQUAL "none")
endif()

if(EXISTS "${_LD_STAGE1}")
add_executable(eboot_firmware stage1/main.c)
# stage1/reset_entry.c owns the vector table the linker script keeps;
# without it (and the script's ENTRY) the link had nothing to anchor
# and the image was empty. See tools/embed_stage1_hash.py.
add_executable(eboot_firmware stage1/main.c stage1/reset_entry.c)
target_include_directories(eboot_firmware PRIVATE
${EBLDR_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/boards/${EBLDR_BOARD}
Expand Down
13 changes: 13 additions & 0 deletions boards/stm32f4/stm32f4_stage1.ld
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,21 @@ MEMORY

_estack = ORIGIN(RAM) + LENGTH(RAM);

/* Stage-0 loads SP from the first word of this image and branches to the
* second, so the vector table has to be the first thing in FLASH and the
* link has to be anchored on it: with -nostartfiles and --gc-sections and
* neither of these lines, nothing was reachable and the image was empty. */
ENTRY(Reset_Handler)

SECTIONS
{
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector))
. = ALIGN(4);
} > FLASH

.text :
{
. = ALIGN(4);
Expand Down
10 changes: 0 additions & 10 deletions core/ed25519_verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,16 +300,6 @@ static int point_is_identity(gf p[4])
return diff == 0;
}

static void scalarbase(gf r[4], const uint8_t *s)
{
gf q[4];
fe_copy16(q[0], BX);
fe_copy16(q[1], BY);
fe_copy16(q[2], gf1);
fe_mul(q[3], BX, BY);
scalarmult(r, q, s);
}

/* Reject a public key outside the prime-order subgroup.
*
* Decoding a point is not enough. Ed25519 has eight points of low order, and
Expand Down
Loading
Loading