Skip to content

Keep the key revocation mask and security version floor in TPM NV - #1027

Open
dgarske wants to merge 2 commits into
wolfSSL:masterfrom
dgarske:tpm_policy_nv
Open

dgarske wants to merge 2 commits into
wolfSSL:masterfrom
dgarske:tpm_policy_nv

Conversation

@dgarske

@dgarske dgarske commented Dec 3, 2026

Copy link
Copy Markdown
Member

Description

Depends on #1011: this branch is stacked on it, and only the last commit is new.

Adds a TPM NV backend for KEY_REVOCATION and SECURITY_VERSION on any WOLFTPM=1 target (WOLFBOOT_TPM_POLICY_NV=1):

  • Both values in TPM_NT_BITS indices written only with TPM2_NV_SetBits, so the TPM itself keeps them from going back.
  • Indices created under the platform hierarchy on first use; one wolfBoot did not create, or cannot read, revokes every key and rejects every image.
  • Platform hierarchy disabled before handoff on the RAM and disk boot paths; a lock failure halts.
  • The x86 stage 1 loader does not apply the policy to stage 2.
  • tools/tpm/policy_nv reads, clears or replaces the indices for testing.

Testing

  • The simulator scripts run against ibmswtpm2 in a tpm-nv CI job, adding a foreign-index case and the 64-level limit.

Validated on an NAI 68INT6 (Tiger Lake, Infineon SLB9670 TPM, disk boot): security version and revocation committed for a confirmed image, images below the floor or signed by the revoked key refused, an index not created by wolfBoot refused, and undefine or NV_SetBits from Linux after handoff rejected by the TPM.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The flash policy hook directly dereferences an external-flash offset, risking faults or incorrect reads, and disk-policy failure paths can panic before clearing sensitive encryption buffers.

2 open issues
What changed in this PR

Adds TPM NV storage for wolfBoot’s key-revocation mask and security-version floor, building on #1011.

Changes:

  • Stores monotonic policy values in TPM NV and locks the platform hierarchy before handoff.
  • Applies policy from confirmed images while excluding x86 stage 1.
  • Adds tooling, tests, and documentation, alongside stacked ZynqMP and FIPS changes.
File Description
tools/​unit-tests/​unit-zynqmp-sec-bl33.c Tests PMU security-state reads.
tools/​unit-tests/​unit-zynqmp-efuse-counter.c Tests eFuse counter encoding.
tools/​unit-tests/​unit-update-ram.c Tests RAM policy-call ordering.
tools/​unit-tests/​unit-update-disk-confirm.c Tests disk policy commits.
tools/​unit-tests/​Makefile Registers new unit tests.
tools/​tpm/​policy_nv.c Adds policy inspection/reset tool.
tools/​tpm/​Makefile Builds the policy tool.
tools/​scripts/​sim-security-version.sh Tests security-version enforcement.
tools/​scripts/​sim-key-revocation.sh Tests signing-key revocation.
tools/​scripts/​sim-common.sh Shares simulator policy helpers.
tools/​config.mk Preserves new configuration options.
stage1/​Makefile Disables policy for stage 2 verification.
src/​update_ram.c Integrates policy commits and TPM teardown.
src/​update_flash.c Commits confirmed-image policy.
src/​update_disk.c Integrates policy commits and TPM teardown.
src/​tpm.c Locks policy storage before cleanup.
src/​tpm_policy_nv.c Implements TPM NV policy storage.
src/​image.c Enforces and commits signed policy.
src/​boot_state.c Makes policy-lock failures fatal.
options.mk Adds policy guards and FIPS configuration.
include/​wolfboot/​wolfboot.h Defines policy headers and failure cause.
include/​user_settings.h Updates FIPS crypto settings.
include/​tpm.h Declares policy indices and locking API.
include/​image.h Declares confirmed-image policy hooks.
include/​hal.h Defines policy storage interfaces.
hal/​zynq.h Exposes security-state APIs for BL33.
hal/​zynq.c Adds eFuse policy and FIPS support.
hal/​sim.c Adds file-backed policy storage.
docs/​TPM.md Documents TPM policy configuration.
docs/​Targets.md Documents ZynqMP security policy.
docs/​keystore.md Explains revocation and TPM storage.
docs/​firmware_update.md Explains security-version enforcement.
docs/​FIPS.md Documents AArch64 assembly and encryption.
docs/​compile.md Documents production build guards.
docs/​API.md Documents policy failure reporting.
config/​examples/​nai_68int6.config Adds commented TPM policy options.
arch.mk Configures ZynqMP eFuse policy.
.gitignore Ignores new generated artifacts.
.github/​workflows/​test-units.yml Extends unit-test timeout.
.github/​workflows/​test-key-revocation-simulator.yml Adds simulator and TPM policy coverage.
.github/​workflows/​test-configs.yml Adds ZynqMP FIPS/AES build coverage.

Review effort: Balanced

Comment thread src/image.c Resolved
Comment thread src/update_disk.c Resolved
@dgarske
dgarske requested review from danielinux and rizlik and a balanced review from Copilot December 3, 2026 22:23
@dgarske dgarske assigned wolfSSL-Bot and unassigned dgarske Dec 3, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The NV read error handling can convert negative wolfTPM errors into apparent success, potentially printing svn 0 and exiting with status 0.

2 open issues
2 resolved since last review

Review effort: Balanced

Comment thread tools/tpm/policy_nv.c Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The secure-mode flash handoff skips the TPM hierarchy lock, leaving empty platform authorization enabled and allowing code with TPM access to delete policy indices and reset their values.

1 open issue
2 resolved since last review

Review effort: Balanced

Comment thread src/tpm.c Resolved
@dgarske
dgarske force-pushed the tpm_policy_nv branch 7 times, most recently from f5729d8 to 875255a Compare December 4, 2026 19:47
@dgarske
dgarske requested a balanced review from Copilot December 4, 2026 19:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Changes are needed because hierarchy locking lacks direct test coverage and the encrypted-disk path erases header metadata before the boot hook can use it.

2 open issues
1 resolved since last review

Review effort: Balanced

Comment thread src/tpm_policy_nv.c Resolved
Comment thread src/update_disk.c Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Irreversible policy writes, TPM boot handoffs, and FIPS boundary changes require hardware/security-owner review, with validation gaps in production locking and eFuse burning.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

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