Skip to content

Commit 88c40e5

Browse files
committed
examples/native: flush unused EK before CreateLoaded
native_test creates an EK primary and an SRK primary, then calls TPM2_CreateLoaded under the SRK. The EK is unused between creation and the common cleanup path, so it just sits in TPM object memory. On TPMs with tight transient-object limits (Nations NS350 at RSA-4096 only holds two transient objects), the third object made by CreateLoaded returns TPM_RC_OBJECT_MEMORY. Flush the EK right after the SRK is created. No behavior change on TPMs with spare object memory; fixes the OOM on constrained parts.
1 parent ebb98f1 commit 88c40e5

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

examples/native/native_test.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,16 @@ int TPM2_Native_TestArgs(void* userCtx, int argc, char *argv[])
10551055
printf("TPM2_CreatePrimary: Storage 0x%x (%d bytes)\n",
10561056
(word32)storage.handle, storage.pub.size);
10571057

1058+
/* Flush EK now to free a transient slot. Smaller-memory TPMs (e.g.
1059+
* Nations NS350 at RSA-4096) can only hold 2 transient objects, so
1060+
* keeping EK loaded would OOM on the next CreateLoaded. EK isn't used
1061+
* again until the common cleanup path, so drop it here. */
1062+
if (endorse.handle != TPM_RH_NULL) {
1063+
cmdIn.flushCtx.flushHandle = endorse.handle;
1064+
TPM2_FlushContext(&cmdIn.flushCtx);
1065+
endorse.handle = TPM_RH_NULL;
1066+
}
1067+
10581068
#if 0
10591069
/* Move new primary key into NV to persist */
10601070
cmdIn.evict.auth = endorse.handle;

0 commit comments

Comments
 (0)