Deep dive
wolfTrust
wolfTrust is an alternative to TF-M for Cortex-M33 TrustZone, with faster crypto, session handling, crash protection, PKCS#11 and TPM 2.0 interfaces, and a path to FIPS and DO-178 crypto. A colleague wrote the first STM32H563 experiment; I built it out from there.
TrustZone gives you two worlds, not a security model
Armv8-M TrustZone splits a Cortex-M33 into a Secure and a Non-secure world, but the hardware only draws the line. Something on the Secure side has to decide which partition owns which memory, peripheral and interrupt, serve crypto, key storage and attestation to an untrusted application over a narrow API, and keep running when one of those pieces faults. wolfTrust is that Secure Partition Manager (SPM), booted by wolfBoot and built on wolfCrypt and wolfCOSE. A colleague wrote the first STM32H563 experiment. I took it from there as lead developer, with more than 50 merged pull requests covering the SPM core, the services, the ports and CI.
Make the board configuration and the policy constant
The first version mixed Armv8-M register work, board setup and SPM policy in the same files, so every new chip meant another copy. I moved the architecture mechanics into an arch layer #5 and then put all the Cortex-M33 ports on shared code runners with a port registry #86. Adding a target is now a registry entry and a driver, not a fork of the SPM.
The same idea drove the SPM rewrite #97. The old core read a descriptive manifest at boot and walked it at run time. The new one is generated: services, partitions, interrupts and memory regions are constant tables in flash, with one slot per connection and generation-tagged handles. On the STM32H563 the SPM went from 18,802 to 10,871 bytes (42% smaller) with crypto unchanged. The cost is less run-time flexibility, so the full manifest check still exists behind WT_MANIFEST_RUNTIME_CHECK=1 and conformance builds turn it on. The smallest profiles drop partition and guest restart to save space, but nothing ever turns off guest verification.
Link-time optimization was the same tradeoff in miniature #18. LTO saved 9,032 bytes (10%) on the native wolfCrypt build, but it moves code, and isolation depends on certain objects staying exactly where the memory map says. I kept assembly, CMSE veneers and isolation-band objects out of LTO and added a post-link check that rejects any image whose Secure layout moved.
Main changes
- Served PSA Crypto from the Secure image on native wolfCrypt by default, with wolfHSM optional.#87 #17
- Rewrote the SPM core around generated constant tables: 42% smaller on the STM32H563.#97
- Added PKCS#11 and TPM 2.0 as alternative application APIs, routed through the Secure world.#76 #92 #96
- Crash protection: Secure stack limits, a real fault handler, and partition and guest restart or quarantine.#58 #22 #78
- Closed hardware paths around the boundary: GPDMA channels locked at boot, Secure registers cleared before the first guest jump, engineering-sample silicon refused.#99 #94 #48
- Ported to the STM32H563, STM32L562, i.MX RT700 and MCXN947 on one port registry.#84 #79 #72 #86
- RFC 9783 PSA/EAT attestation tokens through wolfCOSE.#4
Secure values left in the registers
Compilers protect most crossings into the Non-secure world for you. With -mcmse, every compiler-generated call into Non-secure code clears the registers first, so nothing Secure leaks across. wolfTrust's very first launch of a guest does not go through one of those calls. wt_jump_to_ns is hand-written assembly that ends in bxns r4, and the compiler adds nothing to hand-written code.
So the guest started with r0-r3, r5-r12, lr and the APSR flags still holding whatever the Secure boot path left there. wolfTrust treats every guest as untrusted, and that guest could read Secure working values with its first instruction. Nothing in the build flagged it, because the toolchain only checks code it generates.
The jump now zeroes r0-r3, r5-r12 and lr and clears every APSR flag, including GE, with msr apsr_nzcvqg right before bxns. r4 holds only the guest's own entry address, so it stays. A fix in assembly is easy to undo later, so I added a post-link checker, tools/check_ns_entry_scrub.py, that runs on every Secure image build. It disassembles the image and fails the build unless each hand-written bxns ends an unbroken scrub with no later overwrite and no branch landing inside it. It also requires that exactly one hand-written bxns exists, so a second entry path cannot skip the check.
| At the first jump to a guest | Before the fix | After the fix |
|---|---|---|
| r0-r3, r5-r12, lr | Secure boot values | zero |
| APSR flags (N, Z, C, V, Q, GE) | left from Secure code | cleared |
| r4 | guest entry address | guest entry address |
A new hand-written bxns added later | nothing notices | build fails |
Fixed in #94.
How it was checked
| PR | Evidence |
|---|---|
| #16 | The full M33MU emulator matrix boots wolfBoot, then wolfTrust, then the guest on every pull request |
| #94 | check_ns_entry_scrub.py runs on every Secure build; 16 disassembly and 5 source self-test cases |
| #58 | STM32H563 silicon: a partition BusFault (CFSR 0x8200) restarts only that partition; a guest BusFault restarts it 3 times, then quarantines it while the other guest keeps running |
| #99 | Both guests probe all 16 GPDMA channels from the Non-secure side and require them to read back Secure, privileged and locked |
| #27 | i.MX RT700 brought to STM32H563 test parity, including Arm PSA conformance runs |
| #97 | CI holds each port's SPM and non-crypto flash under ceilings in its port.json; crypto stays 45,085 bytes before and after |
| #51 | Coverity Scan and CodeQL in CI |
What is not done yet
The SPM is 10,871 bytes on the STM32H563 and my target is about 7,200, so the core still has work left. M33MU never delivers a data BusFault, so the BusFault tests run only on silicon. Guests on the STM32H563 get no DMA at all; no current guest needs it, but one that wants Ethernet or SD will need a mediated driver. FIPS 140-3 and DO-178C are design goals the crypto path is built for, not certifications wolfTrust has today.
All my merged pull requests 56 in wolfSSL/wolfTrust
- #93Shrink the Secure PSA profiles with direct P-256 and one AEAD option
- #100List each port with a link to its guide in the README
- #99Secure and lock every STM32H563 GPDMA channel at boot
- #95Fix security review findings across storage, attestation, wolfHSM and the SPM
- #96Route the TPM client through the wolfTPM user transport
- #92Add TPM 2.0 and PKCS#11 as alternative application APIs
- #94Scrub Secure registers before the first jump to a Non-secure guest
- #87Serve PSA Crypto from the Secure image by default
- #84Port wolfTrust to the STM32L562E-DK
- #85Shrink the level 3 default image and add opt in build profiles
- #86Consolidate the Cortex-M33 ports onto shared code runners and a port registry
- #83Fix security review findings in FF-M IPC, guest scheduling, storage, FWU, and VNET
- #79Add the NXP FDRM-MCXN947 port
- #82Run MIMXRT700 M33MU scenarios on pull requests only when labelled
- #81Reduce TPM2 and PKCS11 size and cover both crypto engines
- #76Add SPM-mediated PKCS#11 and TPM 2.0 interfaces
- #64Add manual per state production lock for Cortex-M device ports
- #72Share isolation level 3 across Armv8-M ports and bring MIMXRT700 to parity
- #78Keep guest recovery running without a runnable peer
- #71Fix M33MU console marker failures in CI
- #77Fix vnet restart recovery, vnet frame pool expiry, and large ITS and PS reads
- #63Fix Coverity
- #62Exclude dependencies from wolfTrust Coverity scans
- #61Give the vault, crypto, and attestation partitions private data bands
- #58Harden the SPM against stack overflow and faults
- #57Use the existing CI container for static analysis
- #56Enforce Secure ownership of partition peripherals and interrupts
- #52Disable Secure floating point and seal the Secure stacks
- #53Restore upstream wolfHSM pin and release updates
- #54Validate runner scenario names against the scenario matrix
- #55Pin M33MU to upstream master with deterministic USART timing
- #22Harden wolfTrust service isolation and recovery
- #51Add Coverity Scan and CodeQL
- #49Keep the privileged wolfHSM tasklet off memory partitions can write
- #47Make the manifest's privilege and isolation level declarations match what the SPM enforces
- #50Resolve keystore flash geometry from immutable config
- #48Refuse to boot on STM32H563 engineering sample silicon
- #27Bring the MIMXRT700 port to STM32H563 test parity with FWU staging and Arm conformance
- #26Share the target scenario table and run the H5 scenario set on the MIMXRT700 emulator
- #28Stop rerunning the fuzz smoke when a pull request leaves draft
- #30Add bug, feature, and tracked follow-up issue forms
- #24Fix the Cortex-M33 cross compilation on main
- #18Enable LTO without weakening secure isolation
- #19Enforce C99 and wolfSSL coding standards
- #23Run the CI jobs in prebuilt containers and speed up submodule clones
- #17Make native wolfCrypt the default crypto engine and wolfHSM optional
- #14Fix guest restarts sealed storage and IPC message lifetime
- #15Update wolfHSM pin for STM32H5 flash support
- #16Serialize the wolfBoot build and run the full M33MU matrix on every PR
- #9Lower the coroutine tasklet stack to a measured 10K floor
- #8Reduce secure-image static RAM by right-sizing the IPC and stack pools
- #10Point wolfPSA submodule at upstream
- #5Move the Armv8-M mechanics out of the core into the arch layer
- #6Update the wolfCOSE pin to the 2.0.0 release
- #3wolfTrust - wolfTrust-dev to main
- #4Adopt the wolfCOSE RFC 9783 PSA/EAT API for attestation tokens