Skip to content

soc: apple: sep: read the LocalPolicy nonce digest from the enclave - #1734

Merged
RyanTheTide merged 4 commits into
integration/aurorafrom
sependpts/pnon-digest
Nov 13, 2026
Merged

RyanTheTide merged 4 commits into
integration/aurorafrom
sependpts/pnon-digest

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Adds a client for the SEP boot-policy endpoint (pnon) that reads one value: the SHA-384 digest of the nonce the blessed LocalPolicy of this boot is bound to. The nonce stays in the enclave and only changes when the policy is replaced, so the digest is the enclave's own record of which LocalPolicy admitted the boot. No earlier boot stage can write it.

  • One read after the bring-up and nothing else. No request that changes policy or nonce state is ever sent. Nothing is reachable from userspace except the digest itself.
  • Wire format comes from our own J616s macOS 27 trace: tag 2, data = request length, a 32-byte request (hcPB, operation 0x0e, zero padding), and an 80-byte reply (hrPB, result 0, zero padding, 48-byte digest).
  • Only the M4 Pro layout (5 to 7 pages each way) is used. Buffers are registered as macOS registers them: 7 send pages, 5 receive pages. M1 Pro, M2 and A18 Pro advertise 2 to 4 pages. On the A18 Pro the recorded request gets a 1-byte reply with nothing written, so those SEPs are left alone and show absent.
  • diag/pnon reports pending, read, absent or failed. diag/local_policy_digest is hex and root-only (0400). The digest never goes to the kernel log. A reply that does not check out is logged with its word and header only.
  • aurora-sep status lists pnon as served.

Tests

  • KUnit sep.kunitconfig: 594 run, 592 pass, 2 skip. The apple_sep_pnon suite covers the recorded words and bytes, both layouts, refusals (including a refusal that is only a header), malformed replies and late replies.
  • tools/aurora-sep status and diag host tests: 18/18.
  • J616s (M4 Pro), one-shot test kernels with the dead-man armed. pnon reads read, and the digest matches the one macOS reads on the same Mac; this was checked on the Mac without printing it. stac online, 12 endpoints, 0 unhandled, Touch ID ready, key store open, Enforcing, 0 AVC, no new SEP log lines. s2idle 3/3. Run on the final head and the commit before it.
  • Neo (A18 Pro), one-shot on the aura b12 trial: pnon absent with no log line, Touch ID ready, key store open, stac online across s2r, 0 AVC. s2idle 1/1. The s2r cycle woke cleanly, but the row recorded a USB device-list change after wake; that path doesn't touch USB and earlier rows with the same code passed s2r 4/4.

🤖 Generated with Claude Code

The SEP's boot-policy endpoint (pnon) keeps the LocalPolicy anti-replay
state. The nonce that the blessed LocalPolicy of the running OS is bound
to never leaves the enclave, but the service returns its SHA-384 digest.
The digest changes only when the policy is replaced, so it tells which
LocalPolicy admitted this boot, and no earlier boot stage can write it.
Linux has no client for the endpoint.

Recorded on a J616s under macOS 27, a digest read is one mailbox word
whose data field is the request length (32), tag 2, and a 32-byte
request in the send buffer: the header "hcPB", operation 0x0e and 24
zero bytes. The enclave answers with tag 2, status 0 in the type field
and the reply length (80) in the data field. The receive buffer then
holds the header "hrPB", a zero result, 24 zero bytes and the digest.

Send that read once after the bring-up and nothing else. Nothing that
changes policy or nonce state is sent. The buffers are sized from the
endpoint's discovery layout, as macOS sizes them: the largest send
buffer and the smallest receive buffer it allows (seven and five pages
on M4 Pro, four and two on M1 Pro, M2 and A18 Pro). The endpoint is used
only when discovery names it pnon with one of those two layouts. The
reply is checked against the recorded one, a late reply cannot complete
a later exchange, and a message nobody asked for is counted as
unhandled.

diag/pnon shows the outcome. diag/local_policy_digest holds the digest
as hex and is readable by root only. The digest is not logged.
aurora-sep status lists pnon as served when the kernel has the client.

KUnit (apple_sep_pnon) checks the request word and bytes and the reply
word against the recording, the discovery words of both layouts, the
layout byte order against the sizes registered for sks, refusals,
malformed replies and late replies.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
The diag shim's host tests build diag_shim.c against small stand-in
headers that have atomic_t, smp_rmb() and smp_wmb() but not
smp_load_acquire(), smp_store_release() or ENODATA. Keep the pnon state
in an atomic_t, publish the digest with smp_wmb() before the state and
read it after smp_rmb(), and keep the digest outside the state struct.
Before a digest is read, local_policy_digest reads "unavailable".

The host-test stand-in for device.h gains DEVICE_ATTR_ADMIN_RO.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
On the A18 Pro the digest read came back as a reply the driver did not
accept, and the log said only "Malformed". Log the reply word, the
reply header (signature and result, never the digest) and the first
offset in the receive buffer that the enclave wrote.

Check the reply header before its length, so a refusal that comes back
as a header alone is reported with its result instead of as malformed.
A failed read is a warning, not an error: nothing else depends on it.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
On an A18 Pro, whose pnon endpoint advertises the two-to-four-page
layout that M1 Pro and M2 also use, the recorded digest request is
answered with status 0 and a one-byte reply, and nothing is written
to the receive buffer. That SEP speaks a different version of the
boot-policy service, and we have no recording of it. Talk to the
endpoint only when it advertises the M4 Pro layout (five to seven
pages each way), where the request and reply match the recording and
the digest equals the one macOS reads. On the other layouts diag/pnon
reads "absent", and the left-alone note is a debug line.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide
RyanTheTide marked this pull request as ready for review November 13, 2026 01:20
@RyanTheTide
RyanTheTide merged commit abd6d4a into integration/aurora Nov 13, 2026
7 checks passed
@RyanTheTide
RyanTheTide deleted the sependpts/pnon-digest branch November 13, 2026 01:20
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.

1 participant