Skip to content

Add Transparent TPM_RC_RETRY auto-resubmit#537

Open
aidangarske wants to merge 5 commits into
wolfSSL:masterfrom
aidangarske:tpm-rc-retry-handling
Open

Add Transparent TPM_RC_RETRY auto-resubmit#537
aidangarske wants to merge 5 commits into
wolfSSL:masterfrom
aidangarske:tpm-rc-retry-handling

Conversation

@aidangarske

@aidangarske aidangarske commented Jun 23, 2026

Copy link
Copy Markdown
Member

Description

The TPM returns TPM_RC_RETRY when momentarily busy — e.g. the core
dictionary-attack logic persisting the daUsed flag to NV on the first auth
use of a non-noDA key (an externally provisioned AIK/SUDI key). wolfTPM
passed this raw code back to the caller, unlike the TCG ESYS stack which
auto-resubmits. A customer hit it on wolfTPM2_SignSequenceComplete.

This adds optional, bounded auto-resubmit at the command chokepoint
(TPM2_SendCommand / TPM2_SendCommandAuth), covering all transports. A
TPM_RC_RETRY response is header-only, so the saved 10-byte header is restored
and the identical command resent — no re-marshalling.

Opt-in / disabled by default. wolfTPM's own key templates all set noDA,
so wolfTPM-created keys never trigger it; defaulting on would change behavior
for everyone to serve a case none of our keys reach. Existing callers keep the
raw TPM_RC_RETRY unless they opt in.

  • TPM2_SetCommandRetries(&dev.ctx, N) — enable at runtime (0 = off)
  • -DWOLFTPM_MAX_RETRIES=N — change the compile-time default (default 0)
  • WOLFTPM_NO_RETRY — compile the handling out entirely (~528 B)

Note: TPM_RC_RETRY is original TPM 2.0 (Part 2 rev 00.99, 2014) core-TPM DA
behavior — unrelated to SPDM, transport, or SPI wait states.

Tests cover the resubmit bookkeeping and the config API; ChangeLog and README
updated

ZD 22030

@aidangarske aidangarske self-assigned this Jun 23, 2026
@aidangarske aidangarske marked this pull request as ready for review June 23, 2026 22:34
Comment thread src/tpm2.c Outdated
Comment thread src/tpm2_packet.c
Comment thread wolftpm/tpm2.h
Comment thread wolftpm/tpm2.h
Comment thread wolftpm/tpm2_wrap.h Outdated
dgarske
dgarske previously approved these changes Jun 23, 2026
Comment thread src/tpm2.c
@dgarske dgarske assigned wolfSSL-Bot and unassigned dgarske Jun 25, 2026
@aidangarske aidangarske requested a review from dgarske June 25, 2026 21:33
Comment thread src/tpm2.c Outdated
packet->pos = cmdSz;

#ifdef WOLFTPM_SPDM
rc = TPM2_SPDM_SendCommand(ctx, packet);

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.

Could / should we actually map INTERNAL_SEND_COMMAND -> TPM2_SPDM_SendCommand to cleanup this section and the duplicated one below?
I suppose not since it is used to check for SPDM active. Do we need to do a better job making sure that someone can't just get SPDM to fail and have it fall back to plain text cmd/rsp?

@aidangarske aidangarske force-pushed the tpm-rc-retry-handling branch from 02fcc54 to ddddacd Compare June 25, 2026 22:19
@aidangarske aidangarske requested a review from dgarske June 25, 2026 22:20
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.

3 participants