Skip to content

Align fwTPM command behavior and return codes with the TPM 2.0 reference - #677

Merged
aidangarske merged 124 commits into
wolfSSL:masterfrom
dgarske:fenrir_fwtpm
Nov 25, 2026
Merged

aidangarske merged 124 commits into
wolfSSL:masterfrom
dgarske:fenrir_fwtpm

Conversation

@dgarske

@dgarske dgarske commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

This PR brings the firmware TPM (fwTPM) in line with the TPM 2.0 Library specification code and with the behavior of discrete TPMs. One commit per finding. Key changes:

  • Session handling in the dispatcher: TPMA_SESSION attribute rules, parameter encryption flags per command, password sessions only on authorization handles, policy sessions refused on entities with no authPolicy and on public-only objects.
  • Policy commands: PolicyPassword, PolicyOR, PolicyNV, PolicyAuthorizeNV, PolicyNameHash, PolicyCounterTimer, PolicySigned and PolicySecret checks, digests and response codes, including trial-session behavior.
  • NV: DefineSpace attribute and size checks, read, write, extend and certify bounds, owner access to platform indexes, global write lock, unwritten bits and extend indexes.
  • PCR and hierarchy: allocation and unallocated banks, PCR authValue reset, ChangeEPS and ChangePPS, Clear, ClearControl, HierarchyControl, dictionary attack recovery.
  • Objects and keys: creationData, Qualified Names (kept across ContextSave and EvictControl), ECC and KEYEDHASH validation in LoadExternal and Import, key usage and scheme checks, ReadPublic on sequences.
  • seedValue: KEYEDHASH, SYMCIPHER and storage key objects carry a seedValue through creation, loading, import, duplication, context save and persistence, and unique of a KEYEDHASH or SYMCIPHER object is computed from it, so the reference can import fwTPM duplicates.
  • Duplication: Duplicate, Import and Rewrap use the specification inner and outer wrap format, through one shared outer wrap.
  • Signing and attestation: inScheme checked against the key scheme, ECDSA-only ECC signing, Quote digest hash, TPM_RH_NULL as signHandle, GetCapability properties.
  • Hardening: sensitive data, authValue and caller-supplied key sizes are bounded, a failed HMAC on a bound session counts toward lockout, the NV journal is not used when the HAL integrity key callback fails, command buffers and TIS FIFOs are wiped after use, and allocation failures are kept on small-stack builds.

Compatibility:

  • Persistent object NV records gain trailing Qualified Name, seedValue and public-only fields, and NV_GlobalWriteLock is stored as one new journal record. Images written by older builds still load and keep a global write lock that was set. A persistent object from an older build reports its Name as its Qualified Name, so ObjectChangeAuth on it fails the parent check, until it is evicted and persisted again. Duplication blobs with an inner wrap from older builds are not importable.
  • The Name of a KEYEDHASH or SYMCIPHER primary changes because its unique now includes the seedValue. Key material, children and persistent copies are unaffected.
  • Sealed data larger than MAX_SYM_DATA and caller-supplied KEYEDHASH keys larger than the hash block size are refused, and a get_integrity_key callback that fails now fails FWTPM_Init().
  • An HMAC session that sends an empty HMAC is accepted only when the session key and the authValue are both empty, and a session bound to a DA protected entity receives TPM_RC_LOCKOUT during lockout.
  • Raw commands that relied on the previous lenient session, scheme or attribute handling now receive the reference response code, and session attribute and authorization errors carry the session number.
  • Saved contexts do not carry across a fwTPM restart, as before: the context protection key is generated at start-up.

Testing: unit tests were added for each behavior change and for existing untested paths. Session, policy and trial-session behavior was confirmed on Infineon SLB9670 and SLB9678 TPMs. Duplication in both directions, Qualified Name and null-signer attestation were cross-checked against the reference simulator with tpm2-tools, and private blobs, persistent objects and duplicates written by the previous build were confirmed to load.

Scope: fwTPM private blobs keep the fwTPM wrap format rather than the reference's seedValue-keyed protection, so Duplicate and Import remain the only cross-TPM path.

Resolves F-15792, F-16097, F-16102, F-16103, F-16105, F-16108, F-16124, F-16125, F-16126, F-16130, F-16131, F-16132, F-16134, F-16135, F-16136, F-16137, F-16182, F-16183, F-16184, F-16185, F-16186, F-16187, F-16188, F-16200, F-16201, F-16202, F-16203, F-16204, F-16205, F-16206, F-16207, F-16209, F-16210, F-16211, F-16219, F-16222, F-16224, F-16225, F-16226, F-16227, F-16228, F-16229, F-16230, F-16231, F-16233, F-16235, F-16236, F-16239, F-16241, F-16816, F-16834, F-16835, F-16836, F-16837, F-16838, F-16840, F-16846, F-17126, F-17150, F-17151, F-17152, F-17155, F-17156, F-17157, F-18002, F-18062, F-18066, F-18067, F-18068, F-18069, F-18070, F-18071, F-18072, F-18073, F-18075, F-18076, F-18077

@dgarske dgarske self-assigned this Nov 23, 2026
Copilot AI balanced review requested due to automatic review settings November 23, 2026 17:09

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

A key-lookup failure after journal writes can invalidate persisted state and lose seeds and NV data on restart, while ECC Import also incorrectly converts allocation failures from TPM_RC_MEMORY to TPM_RC_FAILURE.

2 open issues
What changed in this PR

This PR aligns wolfTPM’s firmware TPM behavior with the TPM 2.0 reference, improving interoperability, persistence, and sensitive-data handling.

Changes:

  • Updates cryptographic validation, signing checks, and duplication formats, including seedValue and Qualified Name preservation.
  • Hardens NV integrity-key failure handling and clears command and TIS buffers after use.
  • Adds TIS regression tests and clarifies HAL security and compatibility documentation.
File Description
wolftpm/​fwtpm/​fwtpm.h Extends object state, sensitive-buffer capacity, and allocation-failure hooks.
wolftpm/​fwtpm/​fwtpm_tis.h Corrects FIFO sizing and register-layout comments.
wolftpm/​fwtpm/​fwtpm_nv.h Clarifies NV buffer, clock, and error documentation.
wolftpm/​fwtpm/​fwtpm_crypto.h Updates interfaces for seed handling and cryptographic validation.
tests/​fwtpm_hal_unit_tests.c Tests FIFO wiping and locality isolation.
src/​fwtpm/​ports/​optee/​README.md Documents storage requirements for rollback protection.
src/​fwtpm/​fwtpm_tis.c Wipes command and response FIFOs during lifecycle transitions.
src/​fwtpm/​fwtpm_tis_shm.c Clears shared-memory FIFOs during cleanup.
src/​fwtpm/​fwtpm_nv.c Persists additional object fields and hardens journal handling.
src/​fwtpm/​fwtpm_io.c Clears command buffers after dispatch and receive failures.
src/​fwtpm/​fwtpm_crypto.c Implements seed-aware wrapping, ECC validation, and signing checks.
docs/​fwtpm/​hal-and-porting.md Documents failure behavior for integrity-key callbacks.

Review effort: Balanced

Comment thread src/fwtpm/fwtpm_nv.c Resolved
Comment thread src/fwtpm/fwtpm_crypto.c Resolved

@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] Global write lock can partially commit when a later NV save fails — src/fwtpm/fwtpm_command.c:18703-18716
  • [High] Zero-length KEYEDHASH sensitive data is mistaken for a public-only object — src/fwtpm/fwtpm_command.c:24254-24263

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_nv.c Resolved
Comment thread src/fwtpm/fwtpm_command.c Resolved
Comment thread wolftpm/fwtpm/fwtpm.h Resolved
Comment thread src/fwtpm/fwtpm_command.c Resolved
Comment thread src/fwtpm/fwtpm_command.c Resolved
@aidangarske
aidangarske merged commit ea765a4 into wolfSSL:master Nov 25, 2026
252 checks passed
@aidangarske
aidangarske deleted the fenrir_fwtpm branch November 25, 2026 19:06
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