Skip to content

fwTPM command-code masking + vendor-bit return-code fix#556

Merged
aidangarske merged 1 commit into
wolfSSL:masterfrom
dgarske:fwtpm_cc_enforcement
Jul 22, 2026
Merged

fwTPM command-code masking + vendor-bit return-code fix#556
aidangarske merged 1 commit into
wolfSSL:masterfrom
dgarske:fwtpm_cc_enforcement

Conversation

@dgarske

@dgarske dgarske commented Jul 21, 2026

Copy link
Copy Markdown
Member

Fixes

  • Reject fwTPM command codes with reserved bits set (only the 16-bit index plus the CC_VEND vendor bit are valid) so none can alias a command.
  • TPM2_GetCapability(TPM_CAP_COMMANDS) now returns well-formed TPMA_CC values (index + handle attributes + vendor V bit) instead of a bare index.
  • WOLFTPM_IS_COMMAND_UNAVAILABLE masks vendor bits from the return code, so a vendor-decorated TPM_RC_COMMAND_CODE (e.g. Nations NS350 0x000b0143) is recognized; fixes bench/wrap/native aborting instead of skipping unsupported commands.

Features

  • New WOLFTPM_FWTPM_TCG_TEST build flag gates the optional Vendor_TCG_Test echo command (off by default).

Tests

  • fwTPM unit tests for reserved-bit rejection and TPMA_CC reporting; a hardware-free unit test for the vendor-decorated return code.

Fixes #553

@dgarske dgarske self-assigned this Jul 21, 2026
Copilot AI review requested due to automatic review settings July 21, 2026 16:59

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.

Pull request overview

This PR hardens fwTPM command-code handling and improves compatibility with TPMs that return vendor-decorated error codes, aligning capability reporting and dispatch behavior more closely with the TPM 2.0 expectations.

Changes:

  • Enforce fwTPM command-code validity by rejecting any wire command code with reserved bits set (allowing only the 16-bit index plus CC_VEND).
  • Make TPM2_GetCapability(TPM_CAP_COMMANDS) emit TPMA_CC entries (including handle attributes and vendor V bit) and update fwTPM tests accordingly.
  • Update WOLFTPM_IS_COMMAND_UNAVAILABLE to recognize vendor-decorated TPM_RC_COMMAND_CODE and add unit test coverage; gate the optional vendor echo command behind WOLFTPM_FWTPM_TCG_TEST.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
wolftpm/tpm2.h Mask base return-code bits in WOLFTPM_IS_COMMAND_UNAVAILABLE to recognize vendor-decorated TPM_RC_COMMAND_CODE.
src/fwtpm/fwtpm_command.c Reject reserved-bit command codes, emit TPMA_CC for TPM_CAP_COMMANDS, and gate vendor test command behind WOLFTPM_FWTPM_TCG_TEST.
tests/unit_tests.c Add unit test ensuring vendor-decorated TPM_RC_COMMAND_CODE is treated as “command unavailable”.
tests/fwtpm_unit_tests.c Add fwTPM tests for reserved-bit rejection and TPM_CAP_COMMANDS TPMA_CC reporting/paging behavior.
src/fwtpm/README.md Document reserved-bit enforcement, TPMA_CC reporting, and the optional vendor test command flag.
docs/FWTPM.md Document WOLFTPM_FWTPM_TCG_TEST and the command-code enforcement / capability behavior.
ChangeLog.md Add release-note entry describing the fwTPM hardening and vendor-decorated RC handling.

@dgarske dgarske assigned wolfSSL-Bot and aidangarske and unassigned dgarske Jul 21, 2026
@dgarske
dgarske requested a review from aidangarske July 21, 2026 20:48

@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 + bugsOverall 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] [review+review-security+bugs] Unavailable-command macro aliases negative wolfCrypt errorswolftpm/tpm2.h:2157-2159
  • [High] [review] TPMA_CC rHandle bit is missing for response-handle commandssrc/fwtpm/fwtpm_command.c:16057

Review generated by Skoll

Comment thread wolftpm/tpm2.h Outdated
Comment thread src/fwtpm/fwtpm_command.c
@dgarske
dgarske force-pushed the fwtpm_cc_enforcement branch from b6e88c1 to 1245e28 Compare July 22, 2026 16:29
@dgarske
dgarske requested a review from aidangarske July 22, 2026 16:41
aidangarske
aidangarske previously approved these changes Jul 22, 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.

looks good

Comment thread ChangeLog.md Outdated
…TPMA_CC reporting; mask vendor bits in WOLFTPM_IS_COMMAND_UNAVAILABLE
@aidangarske
aidangarske merged commit b32571a into wolfSSL:master Jul 22, 2026
199 checks passed
@aidangarske
aidangarske deleted the fwtpm_cc_enforcement branch July 22, 2026 18:28
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.

4 participants