Repository navigation
soc: apple: sep: read the LocalPolicy nonce digest from the enclave - #1734
Merged
Merged
Conversation
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]>
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.
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.hcPB, operation 0x0e, zero padding), and an 80-byte reply (hrPB, result 0, zero padding, 48-byte digest).absent.diag/pnonreports pending, read, absent or failed.diag/local_policy_digestis 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 statuslists pnon as served.Tests
sep.kunitconfig: 594 run, 592 pass, 2 skip. Theapple_sep_pnonsuite covers the recorded words and bytes, both layouts, refusals (including a refusal that is only a header), malformed replies and late replies.tools/aurora-sepstatus and diag host tests: 18/18.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.absentwith 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