Skip to content

wrap: flush only the transient handles the TPM reports as loaded - #666

Open
dgarske wants to merge 2 commits into
wolfSSL:masterfrom
dgarske:unload_transient
Open

dgarske wants to merge 2 commits 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 and flushes exactly the handles reported, falling back to the fixed range if the query fails.

  • 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.

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 Outdated
XMEMSET(&handle, 0, sizeof(handle));
wolfTPM2_CopyAuth(&handle.auth, &dev->session[0].auth);
for (i = 0; i < handles->count; i++) {
handle.hndl = handles->handle[i];
Comment thread src/tpm2_wrap.c Outdated
Comment on lines +9477 to +9480
for (i = 0; i < handles->count; i++) {
handle.hndl = handles->handle[i];
(void)wolfTPM2_UnloadHandle(dev, &handle);
}
Comment thread tests/unit_tests.c Outdated
Comment on lines +1882 to +1883
rc = wolfTPM2_CreateSRK(&dev, &srk, TPM_ALG_ECC, NULL, 0);
AssertIntEQ(rc, 0);
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.

2 participants