Harden wolfTPM examples fwTPM and SPDM error handling and secret zeroization - #604
Merged
Merged
Conversation
aidangarske
commented
Sep 10, 2026
Member
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Pull request overview
Hardens wolfTPM / fwTPM / SPDM code paths by tightening input validation, improving protocol/state handling, and ensuring sensitive buffers are reliably wiped and released on error.
Changes:
- Add secret zeroization and safer cleanup across TPM, fwTPM NV/crypto/command, and HAL paths.
- Strengthen SPDM framing/length validation and adjust sequence-number handling.
- Improve example robustness by propagating failures and avoiding partial/ambiguous states.
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/tpm2_wrap.c | Zeroizes temporary auth/session material on early failure paths. |
| src/spdm/spdm_tcg.c | Adds vendor-defined payload validation (NULL/size and 16-bit length overflow guard). |
| src/spdm/spdm_secured.c | Adds req sequence bounds check and changes when rsp sequence advances. |
| src/spdm/spdm_responder.c | Makes PSK provisioning atomic-ish and validates PSK exchange request field lengths. |
| src/spdm/spdm_nuvoton.c | Returns framing error on unexpected status response shape. |
| src/spdm/spdm_nations.c | Returns framing error on unexpected status response shape. |
| src/spdm/spdm_msg.c | Tightens KeyExchange build-size requirements per platform config. |
| src/spdm/spdm_context.c | Clarifies disconnect behavior regarding which keys are wiped. |
| src/fwtpm/fwtpm_tis.c | Adds compile-time check to prevent FIFO size mismatches. |
| src/fwtpm/fwtpm_nv.c | Zeroizes NV temp buffers before resize/free and on exit. |
| src/fwtpm/fwtpm_crypto.c | Avoids freeing uninitialized HMAC and gates RNG block generation on prior success. |
| src/fwtpm/fwtpm_command.c | Adds request validation, constant-time compares, auth-area skipping, and broad cmdAuths zeroization. |
| src/fwtpm/fwtpm.c | Cleans up wolfCrypt only when successfully initialized. |
| hal/tpm_io_espressif.c | Zeroizes temporary hex log buffer after printing. |
| hal/tpm_io.c | Adds argument validation before building SPI frame and copying buffers. |
| examples/wrap/hash.c | Unloads TPM handle before device cleanup. |
| examples/wrap/getrandom.c | Rejects negative length argument. |
| examples/wrap/caps.c | Normalizes return code after printing handle count. |
| examples/pkcs7/pkcs7.c | Prevents PKCS7 resource leaks/double-free on error paths. |
| examples/pcr/policy_sign.c | Avoids exporting signature components when signing fails. |
| examples/pcr/policy.c | Fixes string prefix check and returns proper error codes on bad args. |
| examples/management/flush.c | Propagates FlushContext return code. |
| examples/gpio/gpio_config.c | Returns error on vendor mismatch instead of silently continuing. |
| examples/firmware/ifx_fw_update.c | Returns BAD_FUNC_ARG when required file args are missing. |
| examples/bench/bench.c | Adjusts TPM RC masking for “hash not supported” handling. |
| examples/attestation/make_credential.c | Treats AK name file open/read failures as errors and exits cleanly. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Copilot stopped reviewing on behalf of
aidangarske due to an error
September 10, 2026 21:44
dgarske
approved these changes
Sep 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.