Repository navigation
Release crypto callback hash contexts on free and trim two client code paths - #689
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The supplied review evidence identifies no active issues requiring resolution.
No open issues 🎉
What changed in this PR
This PR improves resource cleanup and bounds handling in wolfTPM’s client library, streamlines signature-limit queries and XOR mask handling, and corrects Nations SPDM status reporting.
Changes:
- Release hash and HMAC resources on free callbacks, with regression tests and build guidance.
- Combine signature-limit capability queries with a fallback, and limit XOR mask clearing to the bytes used.
- Correct Nations vendor-property reads and strengthen authorization-copy bounds and test-helper size checks.
| File | Description |
|---|---|
wolftpm/tpm2_wrap.h |
Documents free-callback requirements for hash cleanup. |
tests/unit_tests.c |
Adds free-without-final tests and signature-limit boundary checks. |
tests/fwtpm_unit_tests.c |
Adds and strengthens size assertions in test helpers. |
src/tpm2.c |
Bounds the PolicyPassword authorization copy. |
src/tpm2_wrap.c |
Combines signature-limit queries while retaining fallback reads. |
src/tpm2_param_enc.c |
Clears and wipes only the used XOR mask bytes. |
src/tpm2_cryptocb.c |
Handles free callbacks for TPM-backed hashes and HMACs. |
examples/spdm/spdm_ctrl.c |
Reads Nations status and diagnostic bytes from the vendor buffer. |
docs/tls-and-certificates.md |
Explains the free-callback build requirement for TLS hash cleanup. |
docs/build-options.md |
Adds free-callback guidance to symmetric-support build documentation. |
Review effort: Balanced
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #689
Scan targets checked: wolftpm-src, wolftpm-bugs
Not reviewed (no scan target covers them): docs/build-options.md, docs/tls-and-certificates.md
Coverage: 7 of 8 in-scope changed file(s) opened by the reviewer; not opened: wolftpm/tpm2_wrap.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
e039404 to
84ab149
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #689
Scan targets checked: wolftpm-src, wolftpm-bugs
Not reviewed (no scan target covers them): docs/build-options.md, docs/tls-and-certificates.md
Coverage: 1 of 2 in-scope changed file(s) opened by the reviewer; not opened: tests/unit_tests.c
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Review tier: Lite
Fenrir's latest completed scan found no issues; clearing the prior automated change request.
aidangarske
left a comment
There was a problem hiding this comment.
Skoll Code Review
Scan type: review
Overall recommendation: REQUEST_CHANGES
Findings: 2 total — 2 posted, 0 skipped
2 finding(s) posted as inline comments (see file-level comments below)
Posted findings
- [High] Freeing a source hash leaves its copies with a dangling device context —
src/tpm2_cryptocb.c:1238-1246 - [High] Freeing a copied HMAC destroys the context still referenced by its peer —
src/tpm2_cryptocb.c:1250-1257
Review generated by Skoll
84ab149 to
eb727a0
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #689
Scan targets checked: wolftpm-src, wolftpm-bugs
Not reviewed (no scan target covers them): docs/build-options.md, docs/tls-and-certificates.md
Coverage: 2 of 3 in-scope changed file(s) opened by the reviewer; not opened: wolftpm/tpm2_wrap.h
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Review tier: Lite
eb727a0 to
cc46226
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #689
Scan targets checked: wolftpm-src, wolftpm-bugs
Not reviewed (no scan target covers them): .github/workflows/sanitizer.yml, docs/build-options.md, docs/tls-and-certificates.md, tests/fwtpm_check.sh
Coverage: 6 of 8 in-scope changed file(s) opened by the reviewer; not opened: tests/fwtpm_unit_tests.c, wolftpm/tpm2_wrap.h
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Review tier: Lite
Four client library and example findings from the Fenrir review and two Coverity reports. One commit per item.
wolfTPM2_CryptoDevCbhandles the wolfCrypt copy and free callbacks. A hash or HMAC and its copies share one TPM sequence and cache, which are counted and released when the last of them is freed, with or without a Final and in any order. A hash that was updated and then freed without a Final used to keep its TPM sequence, cache and context. This takes effect when wolfSSL is built with bothWOLF_CRYPTO_CB_COPYandWOLF_CRYPTO_CB_FREE(--enable-cryptocbutils=copy,free) and wolfTPM withWOLFTPM_USE_SYMMETRIC; wolfSSL reports the copy and free of a hash from v5.8.4 and of an HMAC from v5.9.4. Without both macros the code is compiled out.TPM_PT_INPUT_BUFFERandTPM_PT_MAX_COMMAND_SIZEin oneTPM2_GetCapabilityinstead of two, and falls back to a second read when the TPM does not return both.spdm_ctrl --statusreads the Nations identity key flag from the vendor property value, after checking the capability in the response. It read a byte of the parsed buffer that does not hold the flag.Compatibility:
wc_HmacFreeruns a Final through the callback.Testing
Unit tests cover Init, Update and Free without a Final for SHA-1, SHA-256 and HMAC, a source and a copy freed in either order, a hash copy whose allocation fails, and a self copy, against the fwTPM. A new sanitizer entry builds wolfSSL with
--enable-cryptocbutils=copy,free --enable-smallstackcache, runs them under ASan with leak detection, and fails if one is skipped. The signature size check test covers the sizes on both sides of each limit against the fwTPM and the reference simulator, and counts theTPM2_GetCapabilityqueries against a scripted TPM. The Nations status read was run on an NS350 (firmware 30.30) without an identity key; the provisioned case could not be produced, because the part answers--identity-key-setwithTPM_RC_COMMAND_CODE.Resolves F-16212, F-16213, F-17984, F-18950