Add caller-supplied policy authorization for firmware upgrade - #560
Open
dgarske wants to merge 1 commit into
Open
Add caller-supplied policy authorization for firmware upgrade#560dgarske wants to merge 1 commit into
dgarske wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends wolfTPM’s firmware-upgrade wrappers to support caller-supplied authorization sessions (e.g., policy sessions) for the vendor “firmware start” command, enabling platforms that gate upgrade behind custom platform hierarchy policies.
Changes:
- Added a
wolfTPM2_PolicyOR()wrapper to satisfy policy sessions viaTPM2_PolicyOR. - Added
wolfTPM2_FirmwareUpgradeHash_ex(..., startSession)and routed the legacywolfTPM2_FirmwareUpgradeHash()through it (preserving existing behavior whenstartSession == NULL). - Updated the ST33 firmware update example and documentation to demonstrate/describe policy-based authorization and a safe self-test flow.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| wolftpm/tpm2_wrap.h | Declares new wolfTPM2_PolicyOR wrapper and wolfTPM2_FirmwareUpgradeHash_ex API with caller-supplied session support. |
| src/tpm2_wrap.c | Implements wolfTPM2_PolicyOR and adds the _ex firmware upgrade routing + vendor start-session plumbing. |
| examples/firmware/st33_fw_update.c | Adds --policytest self-test to validate policy-session + PolicyOR behavior without performing an upgrade. |
| examples/firmware/README.md | Documents advanced policy-based firmware start authorization and the new _ex API usage. |
dgarske
force-pushed
the
firmware_upgrade_policy_auth
branch
from
August 3, 2026 20:53
e738710 to
0b72b95
Compare
dgarske
force-pushed
the
firmware_upgrade_policy_auth
branch
from
August 3, 2026 21:17
0b72b95 to
bda21be
Compare
dgarske
marked this pull request as ready for review
August 3, 2026 21:25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a supported way for callers to authorize the firmware-upgrade "start" command with their own platform-hierarchy policy, instead of the fixed library-managed authorization (Infineon: an internal
PolicyCommandCode; ST33: password/TPM_RS_PW). This lets deployments gate firmware upgrade behind a custom platformauthPolicy, including multi-branchPolicyORand SHA-2 384/512 policy digests for post-quantum use.Features
_exAPIs that accept a caller-satisfied authorization session:wolfTPM2_FirmwareUpgradeHash_ex(),wolfTPM2_FirmwareUpgrade_ex(), andwolfTPM2_FirmwareUpgradeRecover_ex(). The existingwolfTPM2_FirmwareUpgrade[Hash|Recover]()entry points now forward to the_exform with a NULL session, so current behavior is unchanged.wolfTPM2_PolicyOR()wrapper overTPM2_PolicyOR(hash-agnostic; supports SHA-256 through SHA-512 branches, up to theTPML_DIGESTcapacity).TPM_RS_PW.ifx_fw_update,st33_fw_update): a non-destructive--policytestself-test and--policy/--policyorend-to-end upgrade modes with a selectable policy hash (--sha256|--sha384|--sha512). The shared helpers live in one file (examples/firmware/firmware_policy.c) used by both tools. README documents the flow.Fixes
wolfTPM2_PolicyOR()validates the branch count and each branch'sdigests[i].sizeagainst the digest buffer before marshaling, preventing an out-of-bounds read on a caller-supplied oversized size (CWE-125).wolfTPM2_FirmwareUpgradeHash_ex()explicitly initializesrcon the caller-session path so it cannot use a stale value.TPM2_PrintBin.TPM_CAP_ALGS) instead of issuing a session that fails withTPM_RC_SIZE.FlushContextand a leaked session.authPolicyit provisioned on a failure path so a later default-auth run is not locked out.Testing coverage
tests/unit_tests.c):test_wolfTPM2_PolicyORcovers the argument-validation branches (NULL args, count 0, count over capacity, per-branch size overflow) host-side with no TPM; the firmware test adds NULL-dev cases for the three_exfunctions and assertsstartSession == NULLmatches the legacy call._exwith a NULL session; existing example flows are unchanged.--policy --sha256).--policyand--policyor(confirms Infineon accepts aPolicyORplatform policy for the start command).--policytestpasses for SHA-256, SHA-384, and SHA-512.--policytestacross parts: SHA-256 and SHA-384 pass on ST33 and SLB9672; SHA-512 passes on SHA-512-capable firmware and is cleanly skipped elsewhere.--policytestself-test cross-checks the TPM's running policy digest (PolicyCommandCode + PolicyOR) against an offline computation and is non-destructive.