Skip to content

Rewrite the Secure Partition Manager core around constant generated tables - #97

Merged
dgarske merged 92 commits into
wolfSSL:mainfrom
aidangarske:spm-rewrite
Dec 1, 2026
Merged

dgarske merged 92 commits into
wolfSSL:mainfrom
aidangarske:spm-rewrite

Conversation

@aidangarske

@aidangarske aidangarske commented Nov 24, 2026 •

Copy link
Copy Markdown
Member
  • Replaces the FF-M runtime (ffm.c, ipc.c) with a new SPM core in src/spm/core.c: one slot per connection, one call lifecycle, generation-tagged handles and copied transfers
  • The manifest generator emits constant service, partition, interrupt and memory rows, so the default image no longer links or walks the descriptive manifest; WT_MANIFEST_RUNTIME_CHECK=1 still validates it at boot
  • Guests bind from constant generated rows, and the SP slot and coroutine tables are sized from the generated counts
  • The TPM 2.0 and PKCS#11 relays run on the new core
  • New WT_FFM_SP_DOORBELL, WT_FFM_SP_RHANDLE and WT_FFM_SP_SKIP Make flags build out SP calls no shipped service makes; a conformance build refuses them
  • The tiny profile now also sets WT_SP_RESTART=0 and WT_GUEST_RESTART=0; tinyattest sets WT_SP_RESTART=1 to keep its attestation restart check
  • Connect and close take no transfer, a departed client's handle stops resolving at detach, and a faulted server's staged output is discarded; all three are documented
  • The boot isolation proofs run only with WT_MANIFEST_RUNTIME_CHECK=1, a conformance build or the composition negative probe; the generator already rejects overlapping and SPM-RAM regions
  • The attestation service has one read and one write path, and the challenge-size check lives in the claim builder only
  • The guest measurement log points at the pinned records instead of copying them
  • The SP restore hook is passed to wt_spm_sched_add, so the separate setter is gone
  • Bumps lib/wolfCOSE to 1e9df17 and builds it with WOLFCOSE_NO_CBOR_ENCODE_UTF8_CHECK, since every claim text string is a Secure-flash constant
  • The STM32H563 Zephyr guest reads the GPDMA ownership registers with its probe MPU window open, since the SPM now restores each guest's MPU
  • The conformance judge drops a second guest's port-prefixed banner before reading the suite totals
  • CI holds each port's non-crypto and SPM flash under ceilings in its port.json, and builds each new flag on every port and engine
  • Footprint, Macros, Crypto Engines and the port.json ceilings carry the new sizes
  • Rebased on main with the tiny, small, default and extended profiles; crypto code is unchanged (45,085 B on the STM32H563 before and after)

SPM and non-crypto Secure code, non-LTO, bytes, against main:

Port SPM before SPM after Change Non-crypto before Non-crypto after Change
STM32H563 18,802 10,871 -7,931 (-42.2%) 53,099 43,771 -9,328 (-17.6%)
MIMXRT700 19,028 10,935 -8,093 (-42.5%) 52,771 43,407 -9,364 (-17.7%)
MCX N947 18,956 10,871 -8,085 (-42.7%) 51,339 42,007 -9,332 (-18.2%)
STM32L562 18,794 10,863 -7,931 (-42.2%) 52,096 42,918 -9,178 (-17.6%)

Whole Secure image, LTO, bytes, against main:

Image Flash before Flash after Change RAM before RAM after Change
STM32H563 native default 94,511 86,091 -8,420 (-8.9%) 47,344 39,744 -7,600 (-16.1%)
STM32H563 native, WT_SECURE_PSA=0 70,948 62,560 -8,388 (-11.8%) 45,296 37,696 -7,600 (-16.8%)
STM32H563 hsm default 99,336 90,944 -8,392 (-8.4%) 83,968 72,316 -11,652 (-13.9%)
STM32H563 native tiny 75,895 66,647 -9,248 (-12.2%) 47,268 39,664 -7,604 (-16.1%)
STM32H563 native extended 116,028 109,680 -6,348 (-5.5%) 63,908 51,760 -12,148 (-19.0%)
STM32H563 hsm extended 109,188 102,840 -6,348 (-5.8%) 107,956 91,800 -16,156 (-15.0%)
MIMXRT700 native default 94,615 86,127 -8,488 (-9.0%) 51,740 44,140 -7,600 (-14.7%)
MCX N947 native default 93,119 84,663 -8,456 (-9.1%) 47,540 39,940 -7,600 (-16.0%)
STM32L562 native default 70,304 61,880 -8,424 (-12.0%) 45,280 37,680 -7,600 (-16.8%)

Testing:

  • Host suites 85/85
  • M33MU: STM32H563 native and wolfHSM positive, restart, crossdomain, spfaultneg, attestneg, confboot, devcrypto, devattest, periphneg, pkcs11, tpm, tinyattest; extended bothpsa, fwustage and wolfHSM periphneg; STM32L562 positive, restart, tinyattest; MCX N947 positive, tinyattest and wolfHSM extended confboot
  • Every port and engine builds with each new flag

Copilot AI balanced review requested due to automatic review settings December 1, 2026 17:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Changes to TrustZone isolation proofs, coroutine exception-frame layout, and Secure stack budgets require human security review and target validation of fault recovery and stack headroom.

No open issues 🎉

What changed in this PR

This PR reworks wolfTrust’s Secure Partition Manager around constant generated tables to reduce Secure flash and RAM usage. It adapts boot, service transports, scheduling, and host fixtures to the new core.

Changes:

  • Replaces runtime manifest binding with generated configuration and simplifies scheduler, measurement, and architecture interfaces.
  • Migrates host and fuzz harnesses, with additional restart-disabled and trimmed-API test configurations.
  • Adds footprint classification, per-port size ceilings, and supporting layout checks and documentation.
File Description
tools/​secure_owners.txt Updates object ownership for the core and privileged operations.
tools/​l3_layout_args.py Supplies SPM-private memory ranges to validation.
tools/​footprint/​wolftrust.rules Adds wolfTrust footprint categories.
tools/​footprint/​tfm.rules Adds matching TF-M footprint categories.
tools/​check-core-port-split.sh Restricts dependencies of the architecture-neutral SPM.
tests/​host/​wolfhsm_relay/​Makefile Links the shared SPM host fixture.
tests/​host/​wolfhsm_relay/​main.c Migrates relay tests to the SPM fixture.
tests/​host/​vnet_relay/​Makefile Links the shared SPM host fixture.
tests/​host/​vnet_relay/​main.c Updates VNET calls, memory checks, and restart handling.
tests/​host/​vault_service/​Makefile Links the shared SPM host fixture.
tests/​host/​tpm_relay/​Makefile Builds relay tests against the new core.
tests/​host/​tpm_relay/​main.c Migrates TPM transactions to the SPM fixture.
tests/​host/​support/​spm_tables.h Declares host table-derivation support.
tests/​host/​support/​spm_tables.c Derives SPM rows from test manifests.
tests/​host/​support/​spm_host.mk Centralizes core and host-fixture build rules.
tests/​host/​support/​spm_host.h Declares host client and service helpers.
tests/​host/​support/​secure_domain_resolve.h Declares manifest-based reference domain helpers.
tests/​host/​support/​secure_domain_resolve.c Moves reference domain composition into test support.
tests/​host/​storage_service/​Makefile Links the shared SPM host fixture.
tests/​host/​spm/​Makefile Updates production-manifest test sources.
tests/​host/​spm/​main.c Retains validation checks after removing generated binding.
tests/​host/​spm_start/​Makefile Adds a restart-disabled test variant.
tests/​host/​spm_gate/​trims_main.c Checks rejection of trimmed partition APIs.
tests/​host/​spm_gate/​Makefile Builds and runs the trimmed-API variant.
tests/​host/​spm_core/​Makefile Adds core restart and guest-count variants.
tests/​host/​psa_storage_client/​Makefile Links the shared SPM host fixture.
tests/​host/​psa_storage_client/​main.c Migrates storage client integration calls.
tests/​host/​psa_ffm_client/​Makefile Replaces legacy runtime test sources.
tests/​host/​psa_ffm_client/​main.c Updates client fixtures and memory-check controls.
tests/​host/​psa_ff_upstream/​README.md Updates state names and test-suite references.
tests/​host/​psa_ff_upstream/​psa_binding.h Defines host PSA identity bindings.
tests/​host/​psa_ff_upstream/​psa_binding.c Implements PSA bindings over the SPM fixture.
tests/​host/​psa_ff_upstream/​Makefile Builds upstream tests with the new bindings.
tests/​host/​ps_service/​Makefile Links the shared SPM host fixture.
tests/​host/​port_flash/​Makefile Migrates flash tests to the SPM fixture.
tests/​host/​port_binding/​main.c Adapts fixtures to pointer-based memory windows.
tests/​host/​pkcs11_relay/​Makefile Links the shared SPM host fixture.
tests/​host/​pkcs11_relay/​main.c Migrates PKCS#11 relay transactions.
tests/​host/​negatives/​Makefile Links negative tests against the new core.
tests/​host/​negatives/​main.c Renames the key-isolation test secret.
tests/​host/​monitor/​Makefile Adds a guest-restart-disabled variant.
tests/​host/​monitor/​main.c Updates monitor stubs and quarantine coverage.
tests/​host/​manifest_ports/​run.sh Uses table derivation in port-manifest checks.
tests/​host/​manifest_ports/​main.c Checks constant guest rows and derived SPM tables.
tests/​host/​Makefile Registers core and footprint suites; removes legacy suites.
tests/​host/​layout_config/​test_layout_config.py Checks per-guest sizing in manifest templates.
tests/​host/​keystore_isolation/​main.c Removes comparative wording from a comment.
tests/​host/​keystore_ipc/​Makefile Links the shared SPM host fixture.
tests/​host/​irq_claim/​main.c Replaces callback fixtures with architecture stubs.
tests/​host/​ipc/​Makefile Removes the retired IPC suite build.
tests/​host/​ipc/​main.c Removes tests for the retired IPC implementation.
tests/​host/​guest_verify/​main.c Adapts measurement tests to pointer-backed records.
tests/​host/​fwu_service/​Makefile Links the shared SPM host fixture.
tests/​host/​fwu_restore/​main.c Captures restore hooks during scheduler registration.
tests/​host/​footprint_classify/​Makefile Adds the footprint-classifier suite entry point.
tests/​host/​ffm_veneer/​Makefile Builds veneer tests with the SPM fixture.
tests/​host/​ffm_domain/​Makefile Links reference domain-resolution helpers.
tests/​host/​ffm_domain/​main.c Uses host-only domain helpers and updated structures.
tests/​host/​boot_seed/​main.c Replaces runtime accessor stubs with core state.
tests/​host/​attestation_service/​Makefile Links the shared SPM host fixture.
tests/​host/​attestation_service/​main.c Migrates attestation routing tests.
tests/​host/​attestation_iak/​main.c Simplifies the key-isolation description comment.
tests/​host/​attestation_golden/​Makefile Disables wolfCOSE text-encoding validation.
tests/​host/​attest_restore/​main.c Updates restore-hook and measurement stubs.
tests/​fuzz/​Makefile Fuzzes the new core through host and gateway support.
src/​sync/​mutex.c Reuses queued acquisition and rejects recursive locking.
src/​spm.c Removes the generated-manifest binding initializer.
src/​spm_partitions.c Supplies restore hooks during scheduler registration.
src/​services/​vnet/​vnet_relay_service.c Uses the build-specific default transport.
src/​services/​vault_service.c Uses the build-specific default transport.
src/​services/​storage_service.c Uses the new core’s transfer-budget constant.
src/​services/​native/​keyvault.c Removes a comparative security claim from a comment.
src/​services/​msg_relay.c Restores the build-specific default transport.
src/​services/​initial_attestation.c Centralizes challenge checks and restricts direct target access.
src/​services/​hsm_relay_service.c Uses the build-specific default transport.
src/​services/​boot_handoff.c Consolidates handoff copying, validation, and clearing.
src/​partition.c Updates the port-binding validation comment.
src/​monitor.c Uses generated configuration and conditional validation/restart paths.
src/​irq_claim.c Calls linked architecture operations directly.
src/​guest_verify.c Stores pointers to pinned measurement records.
src/​ffm_domain.c Removes manifest-derived domain construction from production code.
src/​ffm_api.c Removes the legacy direct PSA binding implementation.
src/​client/​psa_storage_client.c Updates the transfer-budget comment.
src/​boot.c Writes lifecycle information directly into core state.
src/​arch/​common/​spm_sp_api.c Conditionally compiles optional partition APIs.
src/​arch/​common/​measure_ops.c Separates privileged measurement retrieval.
src/​arch/​common/​keystore_ops.c Separates privileged flash and entropy operations.
src/​arch/​common/​fwu_ops.c Separates privileged firmware-update operations.
src/​arch/​armv8m/​start_armv8m.c Makes image initialization and stack clearing table-driven.
src/​arch/​armv8m/​sp_fault_armv8m.c Gates optional forensics and uses shared coroutine offsets.
src/​arch/​armv8m/​irq_armv8m.c Exposes directly linked interrupt-controller operations.
src/​arch/​armv8m/​ffm_nsc.c Uses consolidated guest-buffer checks.
src/​arch/​armv8m/​coroutine_armv8m.c Replaces assembly offset literals with shared definitions.
src/​arch/​armv8m/​cmse.c Consolidates guest-window and hardware access checks.
port/​stm32l562/​port.json Adds non-crypto and SPM flash ceilings.
port/​stm32h563/​port.json Adds non-crypto and SPM flash ceilings.
port/​mimxrt700/​port.json Adds non-crypto and SPM flash ceilings.
port/​mcxn947/​port.json Adds non-crypto and SPM flash ceilings.
port/​common/​armv8m/​platform_armv8m.c Removes obsolete gateway installation.
port/​common/​armv8m/​l3_layout.h Reduces the default wolfHSM crypto stack allocation.
mk/​layout.mk Applies assembly crypto stack sizing to both engines.
Makefile Replaces legacy IPC/FF-M targets with SPM-core targets.
include/​wolftrust/​vnet/​vnet_abi.h Updates the transfer-budget comment.
include/​wolftrust/​spm.h Removes the generated-binding declaration.
include/​wolftrust/​spm_sp_mem.h Defines generated partition memory rows.
include/​wolftrust/​spm_sched.h Integrates restore hooks and gates boot validation.
include/​wolftrust/​spm_ops.h Declares privileged service-operation handlers.
include/​wolftrust/​spm_gate.h Defines default transports and the shared run entry point.
include/​wolftrust/​services/​msg_relay.h Updates relay initialization and transport documentation.
include/​wolftrust/​sched/​tasklet.h Removes the obsolete scheduler-run wrapper.
include/​wolftrust/​sched/​coroutine.h Removes runqueue APIs and updates scheduling contracts.
include/​wolftrust/​sched/​coroutine_internal.h Sizes coroutine storage from generated counts.
include/​wolftrust/​partition.h Uses constant memory arrays and manifest comparison.
include/​wolftrust/​manifest.h Defines when boot isolation validation is enabled.
include/​wolftrust/​irq_claim.h Replaces callback tables with architecture declarations.
include/​wolftrust/​ipc.h Removes the retired IPC interface.
include/​wolftrust/​guest_verify.h Documents pointer-backed measurement lifetimes.
include/​wolftrust/​ffm_gateway.h Removes the gateway-install declaration.
include/​wolftrust/​ffm_domain.h Removes runtime domain-construction interfaces and stack fields.
include/​wolftrust/​ffm_boot.h Simplifies boot initialization and removes runtime accessors.
include/​wolftrust/​arch/​armv8m/​cmse.h Declares the consolidated guest-buffer check.
docs/​Security-Model.md Updates documented main-stack size and measured usage.
docs/​Project-Structure.md Documents the SPM core and footprint tools.
docs/​Porting.md Documents per-port flash ceilings.
.gitignore Removes the redundant retired IPC build entry.
.github/​workflows/​cross-compile.yml Adds flash ceilings and expands feature-flag build coverage.

Review effort: Balanced

@aidangarske
aidangarske marked this pull request as ready for review December 1, 2026 19:17
@aidangarske
aidangarske requested a review from dgarske December 1, 2026 19:18
@dgarske

dgarske commented Dec 1, 2026

Copy link
Copy Markdown
Member

Reviewed and tested at 60c92d7. Host suites pass, the SPM fuzzer ran 23M executions clean under ASan, and the STM32H563 native smoke tier plus restart, spfaultneg and attestneg pass under M33MU in the v1.15 container. The size numbers reproduce here (gcc 13.2.1): -8,260 B flash native, -9,120 B tiny, -8,200 B wolfHSM, and Secure RAM 47,344 -> 39,744. Nice work.

One thing I would like settled before merge:

  • Stack headroom. WT_SPM_STACK_SIZE goes 4 KiB -> 3 KiB while the documented peak rose 1.9 -> 2.3 KiB, and the wolfHSM WT_SP_CRYPTO_STACK_SIZE goes 10 KiB -> 6 KiB against 4,856 B measured. Both are about 20% headroom from M33MU on one toolchain, and I do not see a high-water check in CI. Have these been confirmed on silicon, and with the wolfHSM algorithms beyond P-256? I would prefer either a stack high-water ceiling in port.json checked by one scenario per engine (like the flash ceilings), or keeping the old sizes until that exists.

Follow-ups, fine as separate PRs:

  • tiny now defaults to WT_SP_RESTART=0 WT_GUEST_RESTART=0. It is documented, but it changes fault policy for existing tiny builds; worth a line in the release notes.
  • With the boot isolation proofs off by default, a port's wt_platform_sp_shared_regions is no longer checked in the default image. Porting.md could require one boot with WT_MANIFEST_RUNTIME_CHECK=1.
  • wt_spm_pending rescans all 16 slots for every blocked partition on every drain pass; a per-partition queued-signal word would make it O(1).
  • wt_xfer_free zeroizes the full 1,089-byte transfer after every call; zeroing only the bytes used would be cheaper, given the byte-loop memcpy/wt_forceZero.
  • wt_spm_xfer_t.buf starts at offset 65; moving used after it word-aligns the payload for free.
  • wt_spm_dispatch_call and wt_spm_gate both snapshot the call block, so it is copied four times per SP gate op on target.
  • g_wt_spm_services rows are positional while g_wt_spm_sp_mems rows are designated; designated everywhere would survive a field reorder.
  • g_co_table[WT_CO_MAX - 1u] is zero-length if a native manifest ever has no partitions; spm_gate_core.c already guards that case.
  • With WT_FFM_FORENSICS=1, wt_spm_sched_note(4U, NULL, 0) passes NULL to wt_co_state.

Unrelated to this PR, found while testing: tests/target/ports/stm32h563/m33mu.sh hard-codes CROSS_COMPILE=/usr/local/bin/arm-none-eabi-, and tests/fuzz/Makefile's CC ?= clang never applies because make predefines CC.

@dgarske
dgarske merged commit 0316dbf into wolfSSL:main Dec 1, 2026
435 checks passed
@aidangarske
aidangarske deleted the spm-rewrite branch December 1, 2026 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:all Run every M33MU scenario of every port on the PR (core change)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants