Repository navigation
Conversation
There was a problem hiding this comment.
🟡 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_HANDLESbefore 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
| 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 on lines
+9477
to
+9480
| for (i = 0; i < handles->count; i++) { | ||
| handle.hndl = handles->handle[i]; | ||
| (void)wolfTPM2_UnloadHandle(dev, &handle); | ||
| } |
Comment on lines
+1882
to
+1883
| rc = wolfTPM2_CreateSRK(&dev, &srk, TPM_ALG_ECC, NULL, 0); | ||
| AssertIntEQ(rc, 0); |
dgarske
force-pushed
the
unload_transient
branch
from
November 4, 2026 00:38
16237eb to
caa7cda
Compare
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.

wolfTPM2_UnloadHandles_AllTransient()flushed0x80000000to0x80000002blindly. With nothing loaded each flush returnsTPM_RC_HANDLE, whichDEBUG_WOLFTPMprints at the start ofwrap_teston real hardware as if the transport had failed. It also never reached past three handles.The wrapper now queries
TPM_CAP_HANDLESfromTRANSIENT_FIRSTand 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 checkagainst the fwTPM and ibmswtpm2 simulators.