Repository navigation
Add OP-TEE trusted application support for the fwTPM - #659
Conversation
b49458f to
1d8729f
Compare
mattia-moffa
left a comment
There was a problem hiding this comment.
Running this:
./autogen.sh
./configure --enable-optee --disable-swtpm
make
fails with:
In file included from tests/fwtpm_hal_unit_tests.c:90:
tests/../hal/tpm_io_fwtpm.c:322:5: error: no previous prototype for ‘TPM2_IoCb_FwTPM’ [-Werror=missing-prototypes]
322 | int TPM2_IoCb_FwTPM(TPM2_CTX* ctx, int isRead, word32 addr,
| ^~~~~~~~~~~~~~~
This is fixed by adding "$enable_optee" to the list at configure.ac:259.
There was a problem hiding this comment.
🟡 Changes recommended
A transient NV read failure can erase existing TPM state, while sensitive buffers remain uncleared and the OP-TEE transport lacks required CMake selection and linkage.
4 open issues
What changed in this PR
Adds OP-TEE support so wolfTPM’s firmware TPM can process commands in the secure world, with a normal-world client using libteec.
Changes:
- Adds trusted-application entry points, secure-storage NV support, and a whole-command client transport.
- Tracks transient-state ownership so closing one client releases its resources without flushing other clients.
- Updates transport gates, platform mappings, build integration, documentation, and unit tests.
| File | Description |
|---|---|
wolftpm/tpm2_types.h |
Adds OP-TEE transport gates, heap mappings, and timing support. |
wolftpm/tpm2_optee.h |
Declares client transport and cleanup functions. |
wolftpm/include.am |
Installs the new OP-TEE headers. |
wolftpm/fwtpm/fwtpm.h |
Adds client ownership fields and clarifies the integrity-key callback contract. |
wolftpm/fwtpm/fwtpm_optee.h |
Defines the shared UUID, command IDs, and secure-world interfaces. |
wolftpm/fwtpm/fwtpm_nv.h |
Corrects NV HAL lifetime documentation. |
wolftpm/fwtpm/fwtpm_command.h |
Declares per-client ownership and cleanup APIs. |
tests/fwtpm_unit_tests.c |
Tests selective cleanup and loaded-session ownership. |
src/tpm2.c |
Integrates OP-TEE command dispatch and cleanup. |
src/tpm2_wrap.c |
Updates initialization, locality, and firmware transport gates. |
src/tpm2_spdm.c |
Excludes OP-TEE from TIS-specific SPDM paths. |
src/tpm2_optee.c |
Implements the libteec client transport. |
src/include.am |
Adds conditional compilation of the client transport. |
src/fwtpm/README.md |
Updates the documented build-option list. |
src/fwtpm/ports/optee/README.md |
Documents architecture, storage, sessions, and port requirements. |
src/fwtpm/ports/optee/fwtpm_optee_ta.c |
Implements trusted-application lifecycle and command handling. |
src/fwtpm/ports/optee/fwtpm_optee_nv.c |
Implements secure-storage NV, integrity-key handling, and the clock HAL. |
src/fwtpm/include.am |
Includes OP-TEE port sources and documentation in distributions. |
src/fwtpm/fwtpm_nv.c |
Uses TA-compatible output for NV version warnings. |
src/fwtpm/fwtpm_command.c |
Records client ownership and selectively flushes transient state. |
hal/tpm_io.h |
Makes the OP-TEE I/O callback unnecessary. |
hal/tpm_io.c |
Excludes OP-TEE from bus callback implementation. |
configure.ac |
Adds --enable-optee and checks client dependencies. |
CMakeLists.txt |
Adds the OP-TEE client source to the source list. |
Review effort: Balanced
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #659
Scan targets checked: wolftpm-src, wolftpm-bugs
Not reviewed (no scan target covers them): CMakeLists.txt, configure.ac, hal/tpm_io.h, src/fwtpm/README.md, src/fwtpm/include.am, src/fwtpm/ports/optee/README.md, src/include.am, wolftpm/include.am
Coverage: 13 of 16 in-scope changed file(s) opened by the reviewer; not opened: wolftpm/fwtpm/fwtpm_command.h, wolftpm/fwtpm/fwtpm_nv.h, wolftpm/tpm2_optee.h
Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
Review tier: Max


Description
The fwTPM as an OP-TEE trusted application: TPM 2.0 command processing in the secure world, client in the normal world. Needs only the TEE Internal Core API and OP-TEE secure storage, so nothing in it is specific to an SoC.
Builds on two wolfSSL changes: wolfSSL/wolfssl#11919 added the
WOLFSSL_OPTEEbuild environment, and wolfSSL/wolfssl#11927 maps the wolfCrypt heap, RNG and time onto the TEE. That is why this port carries no platform shims of its own.FWTPM_ProcessCommandhas the shape ofTA_InvokeCommandEntryPoint, so one invocation carries one whole TPM command and no IO HAL or TIS layer is involved. Both server loops block, which a trusted application cannot do, sofwtpm_io.c,fwtpm_tis.c,fwtpm_tis_shm.candfwtpm_main.care left out of a TA build.Adds
src/fwtpm/ports/optee/- theTA_*EntryPointfunctions and an NV journal on OP-TEE secure storage, keyed from the hardware unique key through the system PTAwolftpm/fwtpm/fwtpm_optee.h- the trusted application's UUID and the command IDs the client sharessrc/tpm2_optee.c,wolftpm/tpm2_optee.h- theWOLFTPM_OPTEElibteec client transport, following theWOLFTPM_SWTPMwhole-command pattern rather than emulating TIS registers--enable-optee, andWOLFTPM_INTERFACE=OPTEEin CMake, which finds and linkslibteecTouches shared code
src/tpm2.c,hal/tpm_io.c,hal/tpm_io.h,wolftpm/tpm2_types.h,src/tpm2_wrap.c,src/tpm2_spdm.c- addWOLFTPM_OPTEEto the existing "no bus, so no TIS" gates besideWOLFTPM_LINUX_DEVandWOLFTPM_SWTPMsrc/fwtpm/fwtpm_command.c,wolftpm/fwtpm/fwtpm.h,wolftpm/fwtpm/fwtpm_command.h-FWTPM_SetCommandClientandFWTPM_FlushCommandClient. Transient objects, sessions, sequences and saved session contexts record the client that created them, so a closing TEE session flushes only its own while others stay open. Ownership does not restrict access between clients. Other transports stay on client 0 and keepFWTPM_ResetCommandClientwolftpm/tpm2_types.h- aWOLFSSL_OPTEEarm forXTPM_GET_TIMEMSonTEE_GetSystemTime. A trusted application has noCLOCK_MONOTONIC, so the POSIX branch leftWOLFTPM_HAVE_MONOTONIC_MSunset and command timeouts fell back to a counter. NotTEE_GetREETime, because the normal world owns that clock and can move it backwards. Applies with or without wolfCryptwolftpm/tpm2_types.h- and where wolfCrypt is not compiled in, map that path's ownXMALLOCandXFREEontoTEE_MallocandTEE_Free.WOLFTPM2_NO_HEAPstill wins and leaves both undefinedsrc/fwtpm/fwtpm_nv.c- a storage read error while loading the journal now failsFWTPM_NV_Initinstead of regenerating, so a transient fault cannot replace the seeds. Only invalid content still regenerates. The default file backend reports a missing file, and the region past its end, as erased NV, which first boot relies onsrc/fwtpm/fwtpm_nv.c- print the NV version mismatch withprintfunderWOLFSSL_OPTEEonly, since a trusted application cannot linkfprintf. Every other build keepsstderrsrc/fwtpm/ports/optee/fwtpm_optee_ta.c- acceptTEE_PARAM_TYPE_MEMREF_INOUTfor the response buffer as well asMEMREF_OUTPUT. Linux'stpm_ftpm_teecarries both memrefs in one registered shared memory and so passes the response as INOUT; without this it getsTEE_ERROR_NOT_SUPPORTED. Nothing is read out of that buffer either way, and it is what lets an in-kernel TPM driver bind to this trusted application and present a/dev/tpmdeviceTesting
Validated on an NVIDIA Jetson Orin Nano (L4T R36.4.4): unmodified
caps,getrandom,native_test,wrap_testand the fourpqc/examples pass against the trusted application, and NV persists across separate client processes. The same examples pass with atpm_ftpm_tee-derived driver bound, holding its own session alongside the libteec clients.Multi-config build sweep green with
WOLFTPM_OPTEEundefined, including the--enable-st33and--enable-advioTIS paths the gate changes affect,--disable-wrapper,--enable-devtpm,--enable-autodetectand--enable-fwtpm --enable-v185.make checkgreen against both the fwTPM server and ibmswtpm2.