Skip to content

NV read/write with owner or platform hierarchy authorization - #442

Open
dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:writecustauth
Open

dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:writecustauth

Conversation

@dgarske

@dgarske dgarske commented Dec 4, 2025 •

Copy link
Copy Markdown
Member

Description

Adds owner/platform hierarchy authorization to the existing NV wrappers, plus an example for an NV index that is readable without a password while write and delete require the owner. No new API. ZD 20801.

Wrapper

  • wolfTPM2_NVWriteAuth, NVWriteAuthPolicy, NVExtend, NVReadAuth and NVReadAuthPolicy accept nv->handle.hndl = TPM_RH_OWNER or TPM_RH_PLATFORM (with nv->handle.auth = hierarchy auth) as the authHandle for OWNERWRITE/PPWRITE/OWNERREAD/PPREAD indexes. Previously the name refresh went through wolfTPM2_NVOpen(), which reset the authHandle to the NV index, so these indexes failed with TPM_RC_NV_AUTHORIZATION / TPM_RC_AUTH_UNAVAILABLE. The NV index Name is still refreshed for the cpHash when TPMA_NV_WRITTEN changes.
  • NVWriteAuthPolicy / NVReadAuthPolicy accept no PCRs (pcrArray NULL, pcrArraySz 0) for a policy session the caller has already satisfied (PolicySecret, PolicyCommandCode, ...). Such a policy covers one chunk, so larger data returns BUFFER_E.
  • wolfTPM2_NVOpen shares a static Name helper with the above.

Example examples/nvram/nvauth

  • TPMA_NV_AUTHREAD with an empty index auth for read, TPMA_NV_OWNERWRITE for write, owner auth for delete.
  • -policy: TPMA_NV_POLICYWRITE with PolicyCommandCode(NV_Write) + PolicySecret(owner).
  • -rotate=<pw>: changes the owner auth with TPM2_HierarchyChangeAuth (current owner auth only), shows the index still writes, then restores it.
  • Wired into automake, CMake, run_examples.sh and examples/README.md.

ZD 20801

Testing

New unit test for an OWNERREAD/OWNERWRITE index with multi-chunk writes under an AES-CFB parameter encryption session, the index-auth write rejection, and the no-PCR BUFFER_E path. unit.test and run_examples.sh pass on the fwTPM and ibmswtpm2. Not tested on hardware.

wolfTPM2_NVIncrement and wolfTPM2_NVWriteLock take no separate index argument and stay index-authorized. TPMA_NV_POLICY_DELETE needs platform auth (NV_UndefineSpaceSpecial) and is not covered.

@dgarske dgarske self-assigned this Dec 4, 2025
@aidangarske
aidangarske marked this pull request as draft October 21, 2026 21:57
@aidangarske

Copy link
Copy Markdown
Member

@dgarske when you get back do you want to try and wrap this one up?

@dgarske dgarske changed the title Support for setting custom auth on NV write NV read/write with owner or platform hierarchy authorization Oct 22, 2026
@dgarske
dgarske requested a review from aidangarske October 22, 2026 14:09
@dgarske
dgarske marked this pull request as ready for review October 22, 2026 14:10

@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: 5 total — 5 posted, 0 skipped
4 finding(s) posted as inline comments (see file-level comments below)
1 finding(s) not tied to a diff line (full detail below)

Posted findings

  • [High] Report owner-auth restoration failures even after an earlier error — examples/nvram/nvauth.c:341-346
  • [Medium] Reject mismatched PCR pointer and length pairs — src/tpm2_wrap.c:7903-7907,8051-8055
  • [Medium] Use guaranteed zeroization for copied hierarchy credentials — examples/nvram/nvauth.c:83,168,273-275,353
  • [Medium] Cover successful no-PCR policy reads — tests/unit_tests.c:2946-2959

Findings not tied to a diff line

Document hierarchy authorization for NV extend

File: wolftpm/tpm2_wrap.h:3332-3334
Function: wolfTPM2_NVExtend

The shared implementation now permits owner/platform authorization for wolfTPM2_NVExtend, but its public documentation omits the handle setup note added to the adjacent read and write wrappers. Callers cannot discover that they must retain the NV Name while replacing nv->handle.hndl and nv->handle.auth with the hierarchy credentials.

Recommendation: Add the same hierarchy-authorization usage note provided for the other affected NV wrappers.

Referenced code: wolftpm/tpm2_wrap.h:3332-3333 (2 lines)


Review generated by Skoll

Comment thread examples/nvram/nvauth.c
Comment thread src/tpm2_wrap.c
Comment thread examples/nvram/nvauth.c Outdated
Comment thread tests/unit_tests.c
Comment thread src/tpm2_wrap.c
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