Skip to content

Fix fwTPM session-tagged StartAuthSession, the clock safe flag and more reference response codes - #688

Merged
aidangarske merged 14 commits into
wolfSSL:masterfrom
dgarske:fwtpm_refmatch3
Dec 1, 2026
Merged

aidangarske merged 14 commits into
wolfSSL:masterfrom
dgarske:fwtpm_refmatch3

Conversation

@dgarske

@dgarske dgarske commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

A third and fourth pass over fwTPM behavior that differed from the TPM 2.0 reference implementation, after #686, plus four findings from the Fenrir review. One commit per item or mechanism. Response codes were checked against the reference simulator.

Findings:

  • TPM2_StartAuthSession sent with TPM_ST_SESSIONS (an audit or encrypt session present) is answered with a sessions response: parameter size and a response authorization area. It was answered in the no-sessions form.
  • TPMS_CLOCK_INFO.safe is reported NO when no clock HAL is registered, in TPM2_ReadClock, the attestation commands and TPM2_PolicyCounterTimer. TPM2_ClockSet is unchanged.
  • TPM2_LoadExternal and TPM2_Import refuse x509sign on an object that is not an asymmetric signing key, in a v1.85 build, as object creation already does.
  • A journal integrity key length from the NV HAL that is larger than the key buffer is refused.

Response codes:

  • TPM2_HierarchyControl and TPM2_PCR_SetAuthPolicy report the parameter number, and TPM2_PCR_SetAuthPolicy checks the policy size and hash algorithm.
  • TPM2_PolicyCpHash, TPM2_PolicyNameHash and TPM2_PolicyTemplate report the parameter number for a digest of the wrong size.
  • The attestation commands and TPM2_Sign report the handle number for a key that cannot sign.
  • The NV access commands return TPM_RC_VALUE with the handle number for a handle of the wrong type, and keep TPM_RC_NV_AUTHORIZATION for a valid handle the index does not permit.
  • A build without v1.85 refuses the firmware-limited and SVN-limited object attributes at creation.
  • The dispatcher checks the handle area before the authorization area: a handle of the wrong type returns TPM_RC_VALUE, a missing persistent object or NV index TPM_RC_HANDLE, and an unloaded object or session TPM_RC_REFERENCE_H0, each with the handle number.
  • A key of the wrong kind is reported with the handle number in TPM2_Unseal, the HMAC, RSA and ECDH commands, TPM2_MakeCredential, TPM2_Import, the sequence commands and TPM2_VerifySignature.
  • A refused parameter carries its parameter number across the session, PCR, policy, hierarchy, NV, context, creation and ticket commands.
  • An unknown hash algorithm is refused in TPM2_PCR_Read, TPM2_SetPrimaryPolicy and TPM2_CreatePrimary, where it succeeded or returned TPM_RC_FAILURE.

Compatibility:

  • A client that parsed the no-sessions response of a session-tagged TPM2_StartAuthSession sees the sessions layout.
  • An integration with no clock HAL reports safe NO, so a TPM2_PolicyCounterTimer policy on safe YES fails there.
  • TPM2_PCR_SetAuthPolicy refuses an empty policy with a hash algorithm set and an unsupported hash algorithm; both were accepted.
  • A bad handle is reported ahead of a bad or missing authorization.
  • TPM2_Create, TPM2_Load, TPM2_CreateLoaded and TPM2_Import refuse a parent that is not a restricted decryption key, and TPM2_VerifySignature refuses a key without sign.
  • TPM2_Sign refuses a ticket that is not a hash check ticket, including a null ticket on an unrestricted key.
  • Creation refuses a restricted decryption key with no symmetric algorithm and an ECC signing key with a KDF.
  • Callers that match the bare codes above must mask the handle or parameter bits.

Resolves F-16133, F-16240, F-16839, F-18946

Copilot AI balanced review requested due to automatic review settings December 1, 2026 00:50
@dgarske dgarske self-assigned this Dec 1, 2026

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

The response-failure path leaks newly allocated StartAuthSession sessions, allowing repeated failures to exhaust the session table; cleanup and a fault-injection regression test are needed.

1 open issue
What changed in this PR

This PR continues fwTPM’s alignment with the TPM 2.0 reference implementation, correcting response framing, clock safety reporting, validation, and error codes.

Changes:

  • Adds session-formatted StartAuthSession responses and reports clock safety as NO without a clock HAL.
  • Tightens object-attribute, PCR-policy, NV-handle, and journal-key-length validation; adds handle and parameter numbers to affected error codes.
  • Adds regression tests and documents clock behavior.
File Description
tests/​fwtpm_unit_tests.c Adds regression coverage and updates expected response codes.
src/​fwtpm/​fwtpm_nv.c Rejects integrity-key lengths exceeding the key buffer.
src/​fwtpm/​fwtpm_command.c Corrects session responses, clock safety, validation, and error codes.
docs/​fwtpm/​hal-and-porting.md Documents clock safety reporting without a clock HAL.

Review effort: Balanced

Comment thread src/fwtpm/fwtpm_command.c Resolved

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot 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.

Fenrir Automated Review — PR #688

Scan targets checked: wolftpm-src, wolftpm-bugs
Not reviewed (no scan target covers them): docs/fwtpm/hal-and-porting.md
Coverage: 3 of 3 in-scope changed file(s) opened by the reviewer

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Max

@aidangarske aidangarske 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: 2 total — 2 posted, 0 skipped
2 finding(s) posted as inline comments (see file-level comments below)

Posted findings

  • [High] SequenceUpdate reports a handle error as parameter 1 — src/fwtpm/fwtpm_command.c:12456-12460
  • [High] Unknown nameAlg errors lose parameter 2 in three commands — src/fwtpm/fwtpm_command.c:3170-3172

Review generated by Skoll

Comment thread src/fwtpm/fwtpm_command.c Resolved
Comment thread src/fwtpm/fwtpm_command.c Resolved
Comment thread src/fwtpm/fwtpm_command.c Resolved
Comment thread src/fwtpm/fwtpm_command.c Resolved
Comment thread src/fwtpm/fwtpm_command.c Resolved
Comment thread src/fwtpm/fwtpm_nv.c Resolved
@dgarske
dgarske requested a review from aidangarske December 1, 2026 23:35
@dgarske dgarske self-assigned this Dec 1, 2026
@aidangarske
aidangarske merged commit 2e9472c into wolfSSL:master Dec 1, 2026
263 checks passed
@aidangarske
aidangarske deleted the fwtpm_refmatch3 branch December 1, 2026 23:40
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.

5 participants