Skip to content

Add Firmware TPM v1.84 Read-Only mode and seven more v1.84 commands - #669

Open
dgarske wants to merge 3 commits into
wolfSSL:masterfrom
dgarske:fwtpm_readonly
Open

dgarske wants to merge 3 commits into
wolfSSL:masterfrom
dgarske:fwtpm_readonly

Conversation

@dgarske

@dgarske dgarske commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Description

Adds TPM 2.0 v1.84 Read-Only Mode, which restricts the TPM to non-modifying operations under Platform authorization, plus seven other v1.84 commands.

What it adds

  • TPM2_ReadOnlyControl (0x01A0), with TPM_RC_READ_ONLY and the readOnly bit of TPMA_STARTUP_CLEAR; build it out with FWTPM_NO_READONLY
  • TPM2_SetCapability (0x019F) for TPM_CAP_CONFIGS, with the per-configuration lifetime lock
  • TPM2_NV_ReadPublic2 (0x019E), returning a TPM2B_NV_PUBLIC_2, and TPM2_NV_DefineSpace2 (0x019D)
  • TPM2_PolicyCapability (0x019B) and TPM2_PolicyParameters (0x019C)
  • TPM2_ECC_Encrypt (0x0199) and TPM2_ECC_Decrypt (0x019A), the construction given in Part 1 Annex C.2.4; build them out with FWTPM_NO_ECC_ENCRYPT
  • wolftpm/tpm2.h, src/tpm2.c - new codes, and TPM_CC_LAST corrected: it named SetCapability, no longer the highest code without SPDM or PQC

Design notes

  • Read-Only enforcement follows Part 3 Table 190 as a dispatch-table flag tested before authorization, so a refused command cannot consume dictionary-attack tries. It is deliberately not derived from TPMA_CC.nv, which disagrees with Table 190 in both directions.
  • NV_Write, NV_Extend, NV_SetBits, NV_WriteLock and NV_ReadLock are permitted only on an index carrying both TPMA_NV_ORDERLY and TPMA_NV_CLEAR_STCLEAR, so a write cannot outlive the power cycle that clears the mode. The index is resolved ahead of authorization as well, so a denied one returns TPM_RC_READ_ONLY without spending a try.
  • readOnly survives TPM Resume via the NV orderly-shutdown marker, which gains a fourth byte; older firmware rejects the longer record, as with the two earlier extensions to it.
  • TPM2_PolicyCapability builds operand A by running the existing TPM2_GetCapability handler, so the two cannot disagree on how a capability marshals. TPM_CAP_AUTH_POLICIES is refused, because it is not enumerated here and an empty count would let TPM_EO_NEQ assert against a policy that is in fact set.
  • Annex C defines only TPM_ALG_KDF2, which is X9.63 with an empty SharedInfo, so wc_X963_KDF supplies it and no new primitive is needed. C3 covers the plaintext rather than the ciphertext, so decryption verifies it before returning any of it.
  • Both ECC directions need the full shared point rather than only its x coordinate, so they reuse the RNG-blinded multiplication TPM2_ZGen_2Phase already depends on. That API is exported only when wolfSSL defines WOLFSSL_PUBLIC_ECC_ADD_DBL, so FWTPM_NO_ECC_ENCRYPT is set automatically without it and the operation can never fall back to an unblinded multiply. It is also set automatically when wolfSSL has no X9.63 KDF, since wc_X963_KDF is declared only under HAVE_X963_KDF. TPM2_NV_DefineSpace2 refuses TPM_HT_EXTERNAL_NV with TPM_RC_SELECTOR.

Also in this PR

  • examples/keygen/keyload.c, examples/run_examples.sh - the option scan walked down to the positional filename and warned about the argument it had just consumed, so every invocation printed an Unrecognized option line for its own blob; the two endorsement-hierarchy calls also passed -rsa and -ecc, which keyload does not define and does not need, since it reads the type from the blob.
  • tests/fwtpm_check.sh, src/fwtpm/README.md - the fwtpm_server log is now reported when a test stage fails partway through, not only when the server fails to start. A server stopped mid-suite makes every later example fail at wolfTPM2_Init, which reads as a failure of whichever example was running; the README documents running make check in its own network namespace so a machine-wide killall fwtpm_server cannot reach it.

Testing

Capability-probed on an Infineon SLB9678 (FW 45.91) over SPI. It reports specification revision 185 but implements neither TPM2_ReadOnlyControl nor the ECC pair, so those have no silicon reference and were validated against the specification and the fwTPM suites only. The part does implement PolicyCapability and SetCapability, with TPMA_CC attributes matching the dispatch entries here.

The Annex C byte ordering is pinned by a known-answer vector rather than by agreement between the two directions: an externally generated key and ciphertext that TPM2_ECC_Decrypt must reproduce, which a round trip on its own cannot catch.

@dgarske dgarske self-assigned this Nov 6, 2026
Copilot AI balanced review requested due to automatic review settings November 6, 2026 18:24

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

Unresolved authorization flaws allow PolicyParameters restrictions to be bypassed and PolicyCapability comparisons to succeed incorrectly, undermining policy enforcement.

4 open issues
What changed in this PR

This PR extends wolfTPM’s firmware TPM with v1.84 Read-Only Mode and four additional commands, integrating them with command dispatch, policy authorization, and NV persistence.

Changes:

  • Adds Platform-authorized Read-Only control, command restrictions, and conditional NV checks.
  • Implements SetCapability, NV_ReadPublic2, PolicyCapability, and PolicyParameters, with supporting state and persistence.
  • Adds unit tests and updates English and Japanese feature documentation.
File Description
wolftpm/​tpm2.h Adds command codes, Read-Only constants, and updates TPM_CC_LAST.
wolftpm/​fwtpm/​fwtpm.h Adds configuration, Read-Only, and policy-parameter state.
wolftpm/​fwtpm/​fwtpm_nv.h Declares configuration persistence support.
tests/​fwtpm_unit_tests.c Adds tests for Read-Only restrictions and the new commands.
src/​tpm2.c Adds the Read-Only return-code description.
src/​fwtpm/​README.md Documents command coverage, restrictions, and configuration semantics.
src/​fwtpm/​fwtpm_nv.c Persists configurations and the Read-Only shutdown state.
src/​fwtpm/​fwtpm_command.c Implements handlers, dispatch restrictions, and policy checks.
docs/​ja/​fwtpm/​overview.md Updates Japanese coverage and feature documentation.
docs/​ja/​fwtpm/​building.md Documents the Read-Only build option in Japanese.
docs/​fwtpm/​overview.md Updates English coverage and feature documentation.
docs/​fwtpm/​building.md Documents the Read-Only build option and minimal-build example.

Review effort: Balanced

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

@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 #669

Scan targets checked: wolftpm-src, wolftpm-bugs
Not reviewed (no scan target covers them): docs/fwtpm/building.md, docs/fwtpm/overview.md, docs/ja/fwtpm/building.md, docs/ja/fwtpm/overview.md, src/fwtpm/README.md
Coverage: 5 of 7 in-scope changed file(s) opened by the reviewer; not opened: src/tpm2.c, wolftpm/fwtpm/fwtpm_nv.h

Findings: 3
3 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Review tier: Max

Comment thread src/fwtpm/fwtpm_command.c Resolved
Comment thread tests/fwtpm_unit_tests.c Resolved
Comment thread tests/fwtpm_unit_tests.c Resolved
@dgarske dgarske changed the title Add Firmware TPM v1.84 Read-Only mode and four more v1.84 commands Add Firmware TPM v1.84 Read-Only mode and seven more v1.84 commands Nov 6, 2026
@dgarske
dgarske force-pushed the fwtpm_readonly branch 3 times, most recently from ff52486 to 124cad9 Compare November 11, 2026 23:22

@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 #669

Scan targets checked: wolftpm-src, wolftpm-bugs
Not reviewed (no scan target covers them): docs/fwtpm/building.md, docs/fwtpm/overview.md, docs/ja/fwtpm/building.md, docs/ja/fwtpm/overview.md, examples/run_examples.sh, src/fwtpm/README.md, tests/fwtpm_check.sh
Coverage: 3 of 7 in-scope changed file(s) opened by the reviewer; not opened: tests/fwtpm_unit_tests.c, wolftpm/fwtpm/fwtpm.h, wolftpm/fwtpm/fwtpm_crypto.h, wolftpm/tpm2.h

Findings: 2
2 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Review tier: Lite

Comment thread src/fwtpm/fwtpm_command.c Resolved
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 #669

Scan targets checked: wolftpm-src, wolftpm-bugs
Not reviewed (no scan target covers them): docs/fwtpm/building.md, docs/fwtpm/overview.md, docs/ja/fwtpm/building.md, docs/ja/fwtpm/overview.md, examples/run_examples.sh, src/fwtpm/README.md, tests/fwtpm_check.sh
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: Lite

@wolfSSL-Fenrir-bot
wolfSSL-Fenrir-bot dismissed stale reviews from themself November 12, 2026 16:41

Fenrir's latest completed scan found no issues; clearing the prior automated change request.

@dgarske dgarske self-assigned this Nov 12, 2026
@dgarske
dgarske requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot November 12, 2026 21:33

@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 #669

Scan targets checked: none
Unchanged since last review (not re-run): wolftpm-src, wolftpm-bugs
Not reviewed (no scan target covers them): docs/fwtpm/building.md, docs/fwtpm/overview.md, docs/ja/fwtpm/building.md, docs/ja/fwtpm/overview.md, examples/run_examples.sh, src/fwtpm/README.md, tests/fwtpm_check.sh

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: Lite

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.

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

@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 #669

Scan targets checked: wolftpm-src, wolftpm-bugs
Not reviewed (no scan target covers them): docs/fwtpm/building.md, docs/fwtpm/overview.md, docs/ja/fwtpm/building.md, docs/ja/fwtpm/overview.md, examples/run_examples.sh, src/fwtpm/README.md, tests/fwtpm_check.sh
Coverage: 2 of 2 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: Lite

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 README incorrectly presents unshare -rn as protection against same-user killall fwtpm_server, even though network isolation does not prevent the documented mid-suite termination.

1 open issue
5 resolved since last review

Review effort: Balanced

Comment thread src/fwtpm/README.md Resolved
@dgarske dgarske removed their assignment Nov 12, 2026

@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 Multi-Scan Review

Modes: review + review-security

Overall recommendation: REQUEST_CHANGES
Findings: 12 total — 12 posted, 0 skipped
12 finding(s) not tied to a diff line (full detail below)

Findings not tied to a diff line

ECC_Encrypt incorrectly rejects restricted keys

File: src/fwtpm/fwtpm_command.c:12510-12518
Function: FwCmd_ECC_Encrypt
Modes: review+review-security
Severity: High
Category: Logic
Confidence: High

The new handler returns TPM_RC_ATTRIBUTES whenever TPMA_OBJECT_restricted is set. TPM 2.0 Part 3 §14.8.1 says ECC_Encrypt does not verify objectAttributes. That validation belongs to TPM2_ECC_Decrypt. Valid externally loaded public ECC keys are therefore rejected, and the new test_fwtpm_ecc_encrypt_restricted() test codifies the wrong behavior. Severity views: the review mode rated this High/BLOCK, and the security mode rated it Low (interoperability only, no security boundary crossed). The stricter rating is kept.

Recommendation: Remove the restricted rejection from FwCmd_ECC_Encrypt and keep the specified attribute checks in FwCmd_ECC_Decrypt. Change the restricted-key test to expect success.

Referenced code: src/fwtpm/fwtpm_command.c:12510-12518 (6 lines)


ECC public-key import is initialized twice, leaking memory and risking a double free on failure

File: src/fwtpm/fwtpm_command.c:12549-12558
Function: FwCmd_ECC_Encrypt
Modes: review+review-security
Severity: High
Category: Resource Leak
Confidence: High

FwCmd_ECC_Encrypt calls wc_ecc_init(pubKey) before FwImportEccPubFromPublic. That helper calls wc_ecc_init itself (src/fwtpm/fwtpm_crypto.c:3664) and frees the key when import fails. In dynamic-multiprecision builds the second init orphans the first set of allocations, which is a leak (CWE-401). Because ECC_Encrypt needs no authorization, a command client can repeat valid requests to exhaust memory. The caller also sets pubInit before the helper call, so its cleanup frees the key again after an import failure. Severity views: the review mode rated this High/BLOCK, and the security mode rated it Medium (resource leak, service disruption). The stricter rating is kept.

Recommendation: Remove the caller-side wc_ecc_init() and let FwImportEccPubFromPublic initialize the key. Set pubInit only after the import succeeds. Add an invalid-public-key test that exercises the import-failure cleanup path.

Referenced code: src/fwtpm/fwtpm_command.c:12549-12558 (9 lines)


A non-null input KDF accepts a null hash algorithm

File: src/fwtpm/fwtpm_command.c:12329-12341
Function: FwEccEncScheme
Modes: review+review-security
Severity: High
Category: Logic
Confidence: High

The conflict check ignores inHash == TPM_ALG_NULL. An input TPMT_KDF_SCHEME containing the key's KDF with a NULL hash therefore succeeds and silently substitutes the key's hash. TPMS_SCHEME_HASH.hashAlg is a non-nullable TPMI_ALG_HASH, so the malformed structure must be rejected. The TCG reference CryptEccSelectScheme() requires exact hash equality. Both ECC_Encrypt and ECC_Decrypt use this validator. Severity views: the review mode rated this High/BLOCK, and the security mode rated it Low. The stricter rating is kept.

Recommendation: For any supplied non-null scheme, require both the scheme and the hash to match the key's defaults exactly, and reject TPM_ALG_NULL as the hash. Add a key-default test with KDF2/TPM_ALG_NULL input.

Referenced code: src/fwtpm/fwtpm_command.c:12329-12341 (10 lines)


Small-stack hash allocation failure dereferences a null pointer

File: src/fwtpm/fwtpm_command.c:12441-12448
Function: FwEccEncC3
Modes: review
Severity: High
Category: Null Dereference
Confidence: High

FWTPM_ALLOC_VAR can set rc = TPM_RC_MEMORY and leave hash null under WOLFTPM_SMALL_STACK. FwEccEncC3 ignores that result and passes hash straight to wc_HashInit. An allocation failure becomes a null dereference instead of a TPM memory error.

Recommendation: Check the allocation macro's rc before using hash. Cover the small-stack allocation-failure path with a fault-injection test.

Suggested replacement:

FWTPM_ALLOC_VAR(hash, wc_HashAlg);

if (rc == 0) {
    if (wc_HashInit(hash, wcHash) != 0) {
        rc = TPM_RC_FAILURE;
    }
    else {
        hashInit = 1;
    }
}

Referenced code: src/fwtpm/fwtpm_command.c:12441-12448 (8 lines)


ECC commands use the NV-data limit for TPM2B_MAX_BUFFER

File: src/fwtpm/fwtpm_command.c:12382-12726
Function: FwEccEncXorMask, FwCmd_ECC_Encrypt, FwCmd_ECC_Decrypt
Modes: review
Severity: High
Category: Logic
Confidence: High

The new ECC handlers allocate, validate, and clear plaintext/C2 using FWTPM_MAX_NV_DATA (default 2048). These command fields are TPM2B_MAX_BUFFER, whose public type and normal command-data limit are 1024 bytes (MAX_DIGEST_BUFFER/FWTPM_MAX_DATA_BUF). The fwTPM can therefore accept and emit values that wolfTPM's public command structures cannot represent. Changing the unrelated NV-index limit also changes this command's wire behavior.

Recommendation: Use FWTPM_MAX_DATA_BUF consistently for the plaintext, C2, mask, validation, and zeroization sizes. Add boundary tests for exactly the maximum TPM2B_MAX_BUFFER size and one byte beyond it.

Referenced code: src/fwtpm/fwtpm_command.c:12382-12726 (7 lines)


NV_DefineSpace2 ignores its outer public-area size

File: src/fwtpm/fwtpm_command.c:16641-16664
Function: FwNvDefineSpaceEx
Modes: review
Severity: High
Category: Input Validation
Confidence: High

For the newly exposed TPM2_NV_DefineSpace2 path, publicInfo.size is parsed but never checked against the bytes consumed by handleType and the selected public structure. A request can claim a zero, undersized, or oversized TPM2B_NV_PUBLIC_2 and still define an index from bytes outside the declared TPM2B.

Recommendation: Record the position right after the size field. Require publicInfo.size to equal the exact number of bytes unmarshaled for TPMT_NV_PUBLIC_2, returning TPM_RC_SIZE otherwise. Add zero, smaller, and larger declared-size tests.

Referenced code: src/fwtpm/fwtpm_command.c:16641-16664 (7 lines)


PolicyCapability accepts invalid operations in trial sessions

File: src/fwtpm/fwtpm_command.c:15968-16018
Function: FwCmd_PolicyCapability
Modes: review
Severity: High
Category: Input Validation
Confidence: High

The operation field is validated only when a real policy session reaches FwPolicyEoCompare with an existing property. A trial session accepts an unknown TPM_EO value and folds it into the digest. An absent property takes the special absent-property path instead of returning a type-validation error. Trial mode skips the policy assertion, not parameter validation.

Recommendation: Validate operation right after unmarshaling (reject values above TPM_EO_BITCLEAR with TPM_RC_VALUE), independent of session type and property existence. Add invalid-operation tests for trial sessions and absent properties.

Referenced code: src/fwtpm/fwtpm_command.c:15968-16018 (7 lines)


PolicyCapability unconditionally rejects an allowed capability

File: src/fwtpm/fwtpm_command.c:15978-15986
Function: FwCmd_PolicyCapability
Modes: review
Severity: High
Category: Logic
Confidence: High

The command returns TPM_RC_VALUE for every TPM_CAP_AUTH_POLICIES request even though its own comment and test list that capability as permitted. Rejecting the whole capability makes a specified PolicyCapability use case unavailable. The test locks in this incomplete behavior instead of exercising present and absent authorization-policy properties.

Recommendation: Implement exact TPM_CAP_AUTH_POLICIES property lookup, preserving the distinction between an absent property and an empty result. Add matching, nonmatching, and absent-policy tests.

Referenced code: src/fwtpm/fwtpm_command.c:15978-15986 (4 lines)


A newer legacy shutdown marker can restore stale Read-Only state

File: src/fwtpm/fwtpm_nv.c:1647-1679
Function: FwNvProcessEntry
Modes: review
Severity: High
Category: State Management
Confidence: High

A four-byte shutdown marker sets ctx->readOnly, but the accepted one-, two-, and three-byte legacy marker branches do not clear it. In the append-only journal, a Read-Only-capable build can read an old four-byte marker with readOnly=1, then a newer three-byte marker written by a FWTPM_NO_READONLY build, and keep the stale bit. A later Startup(STATE) then restores Read-Only mode although the newest marker intentionally omitted it.

Recommendation: When processing any accepted legacy shutdown marker in a Read-Only-capable build, explicitly set ctx->readOnly = 0 so the newest journal entry supersedes older state. Add a replay test with a four-byte marker followed by a newer three-byte marker.

Referenced code: src/fwtpm/fwtpm_nv.c:1647-1679 (7 lines)


SetCapability locks disappear in FWTPM_NO_NV builds

File: src/fwtpm/fwtpm_nv.c:3069-3076
Function: FWTPM_NV_SaveConfigs
Modes: review-security
Severity: Low
Category: Logic
Confidence: High

The SetCapability command is present in every build, but FWTPM_NV_SaveConfigs() is a successful no-op when FWTPM_NO_NV is defined. FwCmd_SetCapability() therefore acknowledges an enable or lock update that exists only in FWTPM_CTX. After cleanup and re-initialization the arrays return to zero, so a supposedly lifetime-locked configuration can be changed. This contradicts docs/fwtpm/overview.md:247-249 and 365-367.

Recommendation: Choose and document one supported behavior for FWTPM_NO_NV. Either keep persistent storage for configuration records, or remove or reject SetCapability and TPM_CAP_CONFIGS rather than acknowledging non-persistent locks.

Referenced code: src/fwtpm/fwtpm_nv.c:3069-3076 (6 lines)


Core-command total remains stale in the overview

File: docs/fwtpm/overview.md:275
Modes: review
Action: NIT
Category: Documentation
Confidence: High

The command list and heading were updated from 36 to 37 core commands after adding SetCapability, but the later feature-gate summary still says 36. The Japanese overview has the same stale count.

Recommendation: Change the remaining core-command count to 37 in both the English and Japanese overview files.


Read-Only documentation omits NV_DefineSpace2 from the denied set

File: docs/fwtpm/overview.md:347
Modes: review
Action: NIT
Category: Documentation
Confidence: High

The dispatcher marks both NV_DefineSpace and the new NV_DefineSpace2 with FW_CMD_RO_DENY, but the documented denied-command lists mention only the older command. The omission appears in the English overview, the Japanese overview, and src/fwtpm/README.md.

Recommendation: Add NV_DefineSpace2 to each Read-Only denied-command list.


Review generated by Skoll

@dgarske dgarske self-assigned this Nov 13, 2026
@dgarske
dgarske requested a review from aidangarske November 13, 2026 18:59
@dgarske dgarske removed their assignment Nov 13, 2026

@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: 6 total — 6 posted, 0 skipped
6 finding(s) not tied to a diff line (full detail below)

Findings not tied to a diff line

PolicyCapability rejects supported authorization-policy properties

File: src/fwtpm/fwtpm_command.c:15981-15989
Function: FwCmd_PolicyCapability
Severity: High
Confidence: High

The new handler unconditionally returns TPM_RC_VALUE for TPM_CAP_AUTH_POLICIES. That capability is explicitly supported by TPM2_PolicyCapability: for a permanent-handle property, operand A is the marshaled TPMS_TAGGED_POLICY. Consequently, a caller cannot construct a valid policy asserting the owner, platform, endorsement, or lockout authorization policy, even though fwTPM stores those policies.

Recommendation: Implement exact-property retrieval for TPM_CAP_AUTH_POLICIES, validating that property is a permanent handle and marshaling its TPMS_TAGGED_POLICY; add set, unset, EQ, and NEQ tests.

Referenced code: src/fwtpm/fwtpm_command.c:15981-15989 (5 lines)


Trial PolicyCapability sessions still evaluate the assertion

File: src/fwtpm/fwtpm_command.c:15981-16020
Function: FwCmd_PolicyCapability
Severity: High
Confidence: High

Capability rejection, property fetching, and the offset/operand range check execute before or outside the TPM_SE_POLICY branch. A trial session must update its digest without evaluating the capability assertion. The current behavior prevents trial-policy construction for absent properties, TPM_CAP_PCRS, authorization policies, and values intended for a future TPM state.

Recommendation: After unmarshaling and validating encoded parameter types, perform capability retrieval, property existence checks, range checks, and comparison only for TPM_SE_POLICY; let trial sessions proceed directly to the digest update. Add trial tests for absent properties, PCRS, and out-of-range offsets.

Referenced code: src/fwtpm/fwtpm_command.c:15981-16020 (9 lines)


PolicyCapability returns the wrong errors for invalid ranges

File: src/fwtpm/fwtpm_command.c:16001-16009
Function: FwCmd_PolicyCapability
Severity: Medium
Confidence: High

The combined offset + operandBSz check returns TPM_RC_RANGE for two distinct protocol errors. An offset beyond the property must return TPM_RC_VALUE, while an operand that does not fit after a valid offset must return TPM_RC_SIZE. TPM_RC_RANGE is not the specified result for either case.

Recommendation: Split the check: return TPM_RC_VALUE when offset > operandASz, then return TPM_RC_SIZE when operandBSz > operandASz - offset; add a test for each boundary.

Referenced code: src/fwtpm/fwtpm_command.c:16001-16009 (3 lines)


SetCapability persistence and lifetime lock are not tested

File: tests/fwtpm_unit_tests.c:23493-23601
Function: test_fwtpm_set_capability
Severity: Medium
Confidence: High

The test validates configuration and locking only inside one live FWTPM_CTX. It never reloads the new FWTPM_NV_TAG_CONFIGS record or executes TPM2_Clear, so the two main persistence promises—survival across reinitialization and survival across Clear—remain unverified.

Recommendation: Add a persistence test that sets and locks a configuration, destroys and reinitializes the context from the same NV journal, verifies the value and lock, executes TPM2_Clear, and verifies both again.

Referenced code: tests/fwtpm_unit_tests.c:23493-23601 (2 lines)


ECC encryption gate documentation omits the X9.63 dependency

File: docs/fwtpm/building.md:193
Severity: Low
Confidence: High

The documentation says FWTPM_NO_ECC_ENCRYPT is set automatically only when WOLFSSL_PUBLIC_ECC_ADD_DBL is absent. The implementation also sets it when HAVE_X963_KDF is absent. The same incomplete wording appears in the overview, Japanese documentation, and fwTPM README.

Recommendation: Update every feature-gate description to state that both WOLFSSL_PUBLIC_ECC_ADD_DBL and HAVE_X963_KDF are required.


README omits NV_DefineSpace2 from the read-only denied set

File: src/fwtpm/README.md:399
Severity: Low
Confidence: High

The dispatcher marks TPM_CC_NV_DefineSpace2 with FW_CMD_RO_DENY, and both overview documents list it, but the fwTPM README's supposedly complete denied-command list omits it.

Recommendation: Add NV_DefineSpace2 to this denied-command list.

Suggested replacement:

ClockRateAdjust, SetCapability, NV\_DefineSpace, NV\_DefineSpace2, NV\_UndefineSpace,

Review generated by Skoll

@dgarske dgarske self-assigned this Nov 13, 2026
@dgarske
dgarske requested a review from aidangarske November 13, 2026 22:16
@dgarske dgarske assigned dgarske and unassigned dgarske Nov 13, 2026

@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: 4 total — 4 posted, 0 skipped
4 finding(s) not tied to a diff line (full detail below)

Findings not tied to a diff line

PolicyCapability rejects valid full-sized operands

File: src/fwtpm/fwtpm_command.c:15969-16005
Function: FwCmd_PolicyCapability
Severity: High
Confidence: High

The new handler limits operandB to 32 bytes even though this implementation supports digests up to 64 bytes and defines TPM2B_OPERAND as TPM2B_DIGEST. A valid policy comparing a complete SHA-384 or SHA-512 authorization policy, such as the digest portion of TPM_CAP_AUTH_POLICIES at offset 6, is rejected with TPM_RC_SIZE before comparison. The PR's SHA-256-only tests do not cover this.

Recommendation: Size operandB for the largest supported digest and add SHA-384/SHA-512 PolicyCapability comparison tests.

Suggested replacement:

byte operandB[TPM_MAX_DIGEST_SIZE];

PolicyCapability conflates valid and invalid handles with absent properties

File: src/fwtpm/fwtpm_command.c:16024-16043
Function: FwCmd_PolicyCapability
Severity: High
Confidence: High

The PR implements exact capability lookup by paging through the existing GetCapability handler and maps an empty result to an absent property. That is not equivalent for TPM_CAP_HANDLES: FwSelectCapabilityHandle does not enumerate PCR or permanent handles, so a valid assertion about TPM_RH_OWNER or an implemented PCR incorrectly returns TPM_RC_POLICY. An unsupported handle range is likewise treated as absent, allowing TPM_EO_NEQ to succeed instead of returning TPM_RC_HANDLE. The special TPM_CAP_AUTH_POLICIES path has the same invalid-versus-absent problem for non-permanent properties.

Recommendation: Implement capability-specific property validation and exact-one lookup before applying the absent-property TPM_EO_NEQ rule, then test permanent handles, PCR handles, unsupported handle prefixes, and non-permanent AUTH_POLICIES properties.

Referenced code: src/fwtpm/fwtpm_command.c:16024-16043 (7 lines)


FWTPM_NO_NV acknowledges lifetime locks without persisting them

File: src/fwtpm/fwtpm_nv.c:3080-3087
Function: FWTPM_NV_SaveConfigs
Severity: High
Confidence: High

When FWTPM_NO_NV is defined, the new persistence function returns success without saving anything. FwCmd_SetCapability therefore reports that a configuration was successfully locked, but FWTPM_Cleanup followed by FWTPM_Init clears both arrays and makes the supposedly irreversible configuration writable again. The command remains advertised in this build, and the persistence test is compiled out under FWTPM_NO_NV.

Recommendation: Do not accept a lifetime lock without durable storage: either remove or reject the locking operation in FWTPM_NO_NV builds, or provide a persistence backend, and add a reinitialization test for that configuration.

Referenced code: src/fwtpm/fwtpm_nv.c:3080-3087 (5 lines)


Exercise the new Read-Only compile gate in CI

File: docs/fwtpm/building.md:194
Function: FWTPM_NO_READONLY
Severity: Medium
Confidence: High

The PR adds FWTPM_NO_READONLY, which changes FWTPM_CTX, the NV shutdown-record format, dispatch flags, handlers, and unit-test compilation. However, the existing fwtpm-gated-runtime all-gates configurations do not define it, so CI only exercises the feature-enabled layout despite the new minimal-build example advertising the disabled configuration.

Recommendation: Add FWTPM_NO_READONLY to the all-gates CI configurations or create a dedicated gated build that compiles, runs, and verifies that ReadOnlyControl is not advertised.


Review generated by Skoll

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