Skip to content

Unload every transient handle reported by TPM_CAP_HANDLES - #666

Merged
embhorn merged 1 commit into
wolfSSL:masterfrom
dgarske:unload_transient
Nov 5, 2026
Merged

embhorn merged 1 commit into
wolfSSL:masterfrom
dgarske:unload_transient

Conversation

@dgarske

@dgarske dgarske commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

wolfTPM2_UnloadHandles_AllTransient() flushed 0x80000000 to 0x80000002 blindly. With nothing loaded each flush returns TPM_RC_HANDLE, which DEBUG_WOLFTPM prints at the start of wrap_test on real hardware as if the transport had failed. It also never reached past three handles.

The wrapper now queries TPM_CAP_HANDLES from TRANSIENT_FIRST, following continuation pages, and flushes exactly the handles reported. If the first query fails it still tries the fixed range. A failed query or flush is now returned to the caller, where this API previously always returned success.

  • src/tpm2_wrap.c, wolftpm/tpm2_wrap.h: the change and its doc note.
  • examples/pqc/pqc_ctrl.c: use the wrapper instead of a local copy of the same query.
  • tests/unit_tests.c: load a transient SRK, flush, confirm none remain.
  • tests/transient_unload_tests.c: scripted TPM_CAP_HANDLES pages for continuation and the failure paths, which a simulator cannot produce on demand.

Tested with make check against the fwTPM and ibmswtpm2 simulators.

Copilot AI balanced review requested due to automatic review settings November 3, 2026 20:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Handle cleanup stops after the first capability page and accepts non-transient handles that can clear session configuration, while its test fails on RSA-only TPMs.

3 open issues
What changed in this PR

This PR changes wolfTPM’s transient-handle cleanup to query loaded handles instead of blindly flushing three fixed slots, reducing misleading debug errors when no objects are loaded.

Changes:

  • Query TPM_CAP_HANDLES before flushing, retaining the fixed-range fallback if the query fails.
  • Replace the PQC example’s local cleanup helper with the shared wrapper.
  • Document the behavior and add a unit test covering transient-object cleanup.
File Description
wolftpm/​tpm2_wrap.h Documents capability-based cleanup and fallback behavior.
tests/​unit_tests.c Adds a test that creates an SRK and verifies transient handles are unloaded.
src/​tpm2_wrap.c Implements capability-based transient-handle cleanup.
examples/​pqc/​pqc_ctrl.c Reuses the wrapper instead of a local cleanup implementation.

Review effort: Balanced

Comment thread src/tpm2_wrap.c Resolved
Comment thread src/tpm2_wrap.c Resolved
Comment thread tests/unit_tests.c Resolved
@dgarske dgarske self-assigned this Nov 4, 2026
@dgarske dgarske changed the title wrap: flush only the transient handles the TPM reports as loaded Unload every transient handle reported by TPM_CAP_HANDLES Nov 4, 2026
@dgarske dgarske assigned wolfSSL-Bot and embhorn and unassigned dgarske Nov 4, 2026
@dgarske
dgarske requested a review from embhorn November 4, 2026 23:35

@embhorn embhorn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skoll Code Review

Scan type: review

Overall recommendation: REQUEST_CHANGES
Findings: 3 total — 3 posted, 0 skipped
3 finding(s) posted as inline comments (see file-level comments below)

Posted findings

  • [High] Advance the cursor from the reported handle — src/tpm2_wrap.c:9488
  • [High] Preserve failure reporting for the flush command — examples/pqc/pqc_ctrl.c:690
  • [Medium] Exercise continuation in the new test — tests/unit_tests.c:1889-1891

Review generated by Skoll

Comment thread src/tpm2_wrap.c Resolved
Comment thread examples/pqc/pqc_ctrl.c Resolved
Comment thread tests/unit_tests.c Resolved
@dgarske dgarske assigned dgarske and unassigned embhorn Nov 5, 2026
@dgarske
dgarske requested a review from embhorn November 5, 2026 22:09
@dgarske dgarske assigned embhorn and unassigned dgarske Nov 5, 2026

@embhorn embhorn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skoll Code Review

Scan type: review

Overall recommendation: APPROVE
Findings: 0 total — 0 posted, 0 skipped

No issues found.

Review generated by Skoll

@embhorn
embhorn merged commit 0811c6d into wolfSSL:master Nov 5, 2026
248 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants