Skip to content

Add a fwTPM port for an EL2 monitor with a sealed NV image and a Linux HVC driver - #692

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

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

Conversation

@dgarske

@dgarske dgarske commented Dec 3, 2026

Copy link
Copy Markdown
Member

Description

Adds src/fwtpm/ports/hvc, the platform-independent pieces of a fwTPM hosted in a bare-metal Arm hypervisor (EL2) monitor that runs an unmodified Linux at EL1 behind stage 2. Linux reaches the TPM by SMCCC hypervisor call, and the TPM's NV leaves the monitor only as an AES-256-GCM sealed image that Linux stores and the boot firmware hands back at the next boot. The reference port using it is RaspberryPi/fwtpm-el2 in wolftpm-examples (CM5 and CM4).

  • wolftpm/fwtpm/fwtpm_hvc.h - the hypervisor call interface (function IDs, status codes, NV flags) and the sealed NV API and image layout
  • src/fwtpm/ports/hvc/fwtpm_hvc_nv.c - the NV journal in monitor RAM as an FWTPM_NV_HAL; keys derived by HKDF from a port-supplied root and domain; lineage and seed check so a new TPM never silently replaces a stored one; finding an image by its tail behind other data (an initramfs)
  • src/fwtpm/ports/hvc/linux/ - tpm_fwtpm_hvc driver (/dev/tpm0, /dev/tpmrm0, a raw 8192-byte /dev/fwtpm for ML-DSA-87, /dev/fwtpm-nv), with preempted commands resumed after the interrupt; fwtpm-nvd daemon that stores each change and an orderly-shutdown image; systemd unit and udev rule
  • tests/hvc/fwtpm_hvc_nv_tests.c - host test of the sealed image (round trip, tampering, wrong key source, truncation, lineage), built under --enable-fwtpm
  • src/fwtpm/ports/hvc/README.md, and the Raspberry Pi port in the ports table

Testing

  • make check with the new test in the default, v1.85, UBSan, ASan, ASan v1.85 and WOLFTPM_USE_SYMMETRIC configurations; g++, no-wolfCrypt, --disable-wrapper, --disable-examples, --enable-st33 and --enable-advio builds with -Werror; ibmswtpm2 unit tests and examples; codespell.
  • On hardware, with the wolftpm-examples RaspberryPi/fwtpm-el2 monitor built against this branch, on a CM5 and a CM4: each board loaded the NV image its earlier build had stored, the boot self-test passed, the wolfTPM examples and tpm2-tools ran from Linux through the driver, the TPM clock read safe after a clean reboot, and fwtpm-nvd stored each change and stopped cleanly. NV was exercised with the public test key; the boards' OTP keys are not programmed.
  • The driver and daemon are not built in CI (they need kernel headers for the target).

@dgarske dgarske self-assigned this Dec 3, 2026
Copilot AI balanced review requested due to automatic review settings December 3, 2026 00:55

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 issues leave credentials and discarded responses in memory and allow NV storage to report success despite durability failures, risking stale or missing state after reboot.

3 open issues
What changed in this PR

Adds reusable components for hosting wolfTPM’s firmware TPM in an Arm EL2 monitor, with Linux access and encrypted NV persistence.

Changes:

  • Defines the HVC interface and sealed NV storage with lineage checks.
  • Adds a Linux driver, persistence daemon, and service integration.
  • Adds host tests, port documentation, and distribution entries.
File Description
wolftpm/​include.am Installs the HVC header.
wolftpm/​fwtpm/​fwtpm_hvc.h Defines HVC calls and sealed NV APIs.
tests/​include.am Registers the sealed NV host test.
tests/​hvc/​fwtpm_hvc_nv_tests.c Tests sealing, tampering, keys, and lineage.
src/​fwtpm/​ports/​README.md Lists the Raspberry Pi reference port.
src/​fwtpm/​ports/​hvc/​README.md Documents integration, setup, and security limits.
src/​fwtpm/​ports/​hvc/​linux/​tpm_fwtpm_hvc.c Implements Linux TPM, raw-command, and NV devices.
src/​fwtpm/​ports/​hvc/​linux/​Makefile Builds and installs Linux components.
src/​fwtpm/​ports/​hvc/​linux/​fwtpm-nvd.service Configures the persistence service.
src/​fwtpm/​ports/​hvc/​linux/​fwtpm-nvd.c Saves sealed NV images and lineage backups.
src/​fwtpm/​ports/​hvc/​linux/​60-fwtpm.rules Grants the tss group raw-device access.
src/​fwtpm/​ports/​hvc/​fwtpm_hvc_nv.c Implements the RAM journal and authenticated sealing.
src/​fwtpm/​include.am Packages HVC port files.
.gitignore Tracks the port Makefile and ignores test outputs.

Review effort: Balanced

Comment on lines +207 to +212
dfd = open(dirname(dirBuf), O_RDONLY | O_DIRECTORY);
if (dfd >= 0) {
(void)fsync(dfd);
close(dfd);
}
return 0;
Comment on lines +214 to +215
if (len > count)
return -EMSGSIZE;
Comment on lines +294 to +295
}
mutex_unlock(&rf->lock);
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.

2 participants