Add stm32H5 TrustZone wolfHSM Port#348
Conversation
4a42e8f to
e14742d
Compare
bigbrett
left a comment
There was a problem hiding this comment.
@aidangarske thanks for this! I'm little unclear whether any of this stm32H5 specific or is just a generic TZ-M compatible transport? In the docs you say
The transport itself is target-agnostic; the STM32H5-specific glue (NSC veneer,
whFlashCbflash adapter, secure-side server init, NS test exerciser) lives in the wolfBoot port.
If this is the case then I don't think you need any mention of STM32H5 in any of this? Unless I'm misunderstanding. If this is meant to be a generic trustzone M transport then I think having under port/tzm or something like that is better, with no mentions of STM32H5 at all.
LMK if I'm misunderstanding
e14742d to
16cfc43
Compare
|
@aidangarske reverting to draft after our conversation yesterday |
92edc94 to
c8bce36
Compare
c8bce36 to
e878a2b
Compare
| # the STM32H5 TZ demo under m33mu. Informational until m33mu's | ||
| # data-dependent ECDH issue is fixed upstream; NUCLEO-H563ZI hardware | ||
| # is the authoritative validation (log in PR description). |
There was a problem hiding this comment.
I assume the data-dependent ECDH issue is fixed upstream? Either way, pls refine this comment to be less ai-ish
| - 'port/armv8m-tz/**' | ||
| - 'wolfhsm/wh_transport*.h' | ||
| - 'wolfhsm/wh_client*.h' | ||
| - 'src/wh_client*.c' | ||
| - 'src/wh_server*.c' | ||
| - 'test/wh_test.c' | ||
| - '.github/workflows/wolfboot-tz-integration.yml' |
There was a problem hiding this comment.
at this point I'd either remove the paths and have it run on every PR or only scope it to port/armv8m-tz
| @@ -0,0 +1,27 @@ | |||
| # STM32H5 TrustZone port — lives in wolfBoot | |||
|
|
|||
| This directory is a pointer, not an implementation. | |||
| /* A fresh INIT after a prior CLOSE must put the channel back into | ||
| * the connected state so the subsequent request loop accepts non- | ||
| * COMM groups again. */ | ||
| wh_Server_SetConnected(server, WH_COMM_CONNECTED); |
There was a problem hiding this comment.
This is not correct and should not be set here. Exactly where this is set is on a per-transport basis. In the SHM transport this must be set via an out-of-band signal after the client has zeroed out the shared memory.
| if ( (server->connected == WH_COMM_DISCONNECTED) || | ||
| (data == NULL) ) { | ||
| /* Valid data pointer? */ | ||
| if (data == NULL) { |
There was a problem hiding this comment.
why did we remove the connected guard?
| /* When disconnected, only allow COMM-group messages through so the | ||
| * client can re-establish (INIT), interrogate (INFO/ECHO) or repeat | ||
| * a CLOSE on the channel. Any other request is rejected with | ||
| * NOTREADY until a fresh INIT brings the channel back up. */ |
There was a problem hiding this comment.
unfortunately this is not the flow. Connected is a bit of a misnomer. It is more a signal that the transport is ready for use.
| /* Last-resort fallback: every slot is occupied by an uncommitted | ||
| * key (typical when many ephemeral keys are cached in succession | ||
| * with no intervening commit). Reclaim the first non-erased slot | ||
| * so the cache cannot saturate on transient state alone. Drops | ||
| * the slot's in-flight contents; the caller's request gets the | ||
| * slot fresh. */ |
There was a problem hiding this comment.
I don't think this is correct behavior. It is perfectly fine to fail if the client is trying to cache more keys than the server can handle without committing. It should be up to the client to evict manually in this case. At least that is how it was intended to work. Same issue below with the big cache.
| #ifdef WOLFHSM_CFG_PORT_ARMV8M_TZ_NSC | ||
| #include "wh_transport_nsc.h" | ||
| whTransportNscClientContext whTransportNscClientContext_test; | ||
| whTransportNscServerContext whTransportNscServerContext_test; | ||
| #endif /* WOLFHSM_CFG_PORT_ARMV8M_TZ_NSC */ |
There was a problem hiding this comment.
why did we add these to the padding check? This should only hold "wire structures"
| * time in microseconds as a uint64_t. Must be defined in wolfhsm_cfg.h for | ||
| * the active port UNLESS WOLFHSM_CFG_NO_SYS_TIME is defined | ||
| * | ||
| * WOLFHSM_CFG_PORT_ARMV8M_TZ_NSC - If defined, build the ARMv8-M TrustZone |
There was a problem hiding this comment.
I dont think we want a separate compilation guard for port-specific stuff. Core library features, yes, but that is because the library code should support being wildcard compiled. Port stuff needs to be explicitly opted in and compiled manually so there is no sense in requiring a new core library config macro for it
| - Single-call NSC transport (no polling, no shared-memory ring): client `Send` invokes the host-supplied veneer inline and caches the response; client `Recv` consumes the cached response on the first call (subsequent calls return `WH_ERROR_NOTREADY` until the next `Send`). | ||
| - Server-side callbacks that consume the request the host's veneer parked in a static context and write the response back to the non-secure caller's buffer. | ||
|
|
||
| The transport is target-agnostic. Bringing it up on a new ARMv8-M part is a porting exercise on the host side only: provide the `cmse_nonsecure_entry` veneer that fronts `wcs_wolfhsm_transmit`, plus whatever flash/NVM adapter and server init the deployment needs. |
There was a problem hiding this comment.
This line doesnt make sense. "Host side only"? Is that meant to indicate non-secure world only? But flash/NVM should live in secure world. This doc could use a human touch...
Description
port/stmicro/stm32-tz/wh_transport_nsc.{c,h}: a portablesynchronous TrustZone non-secure-callable bridge transport for
ARMv8-M Cortex-M targets. Client
Sendinvokes a host-suppliedveneer (
wcs_wolfhsm_transmit) inline and caches the response;client
Recvconsumes the cached response on the first call.Server-side callbacks consume the request the host's veneer parked
in a static context and write the response back into the non-secure
caller's buffer.
adapter, secure-side server init, NS test exerciser) lives in the
matching wolfBoot PR.
STM32_TZ_NSC=1build flag intest/Makefilecompiles thetransport into the host test build and pulls in a new unit test
test/wh_test_transport_nsc.ccovering BADARGS, NOTREADY, happy-path round trip, and the
request_pending/rsp_sizestatemachine for both callback tables.
.github/workflows/build-and-test.yml:STM32_TZ_NSC=1 ASAN=1build + run.docs/src/chapter08.md.Notes
WOLFCRYPT_TZ_WOLFHSM=1for STM32H5,which is the first consumer of this transport. here
Test plan
STM32_TZ_NSC=1 ASAN=1build +make run(CI)