Repository navigation
soc: apple: sep: one Touch ID match = one key operation; SEP reply-wait, SCRD and ioctl hardening - #1541
Merged
Conversation
The SKS, SCRD, SBIO and control reply waits slept with wait_interruptible_timeout() and, on a signal, carried on with the time that was left. With a signal pending an interruptible sleep returns at once without consuming any of that time, so the loop spun on the CPU until the reply came, and forever if it never did. Since /dev/sep-key runs its enclave requests in the caller's own thread, a Ctrl-C or a kill during a SIGN or UNSEAL reached these loops: the caller could neither be stopped nor complete while the SEP was slow. The same held for /dev/hwrng readers and the sep-bio delete path. Reply waits are bounded (2-30 s) and must not abandon a request the SEP is still processing, so sleep uninterruptibly for them. Waits that end on a signal by design (trusted-key readiness, the RNG hold, worker exit) are unchanged. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
The SCRD endpoint has one pair of shared buffers, and scrd_transact() tells replies apart only by request type. It took no lock, so two callers in flight together (a touch-gated /dev/sep-key call, the password re-arm on /dev/sep-bio-rearm, a key self-test) could overwrite each other's payload or take each other's reply, including the handle of a newly created credential context. Serialise SCRD exchanges as SKS exchanges already are. sks_next_seq() also read and stored the counter in two steps; callers build requests outside the exchange lock, so two requests could carry the same sequence and defeat the late-reply bookkeeping of an abandoned one. Use one fetch_add. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
/dev/sep-key calls run concurrently and serialise their identity-bag load, operation and unload on key_bag_lock (with_identity_bag). The trusted-key unseal, the machine ref-key setup and the sep-bio attestation loaded and unloaded the same bag without it, so one of them could unload the bag while a /dev/sep-key signature or unseal was using its handle. Take the lock on those paths too. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
The ECIES helpers wiped the shared secret and the KDF output only on their success paths. A failed allocation or a failed AES-GCM call left the ECDH shared X, KDF blocks and digests, or the plaintext being sealed, in freed memory, and growing vectors left copies behind when they reallocated. Size the buffers up front and wipe them on every return. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
The enclave does not bound what a matched credential context authorises: one match lets any number of key operations through until the context is deleted (self-test 20 measured a second signature; self-test 21 a signature and an unseal). One touch per operation is therefore kernel discipline, and this makes it structural: - KeyGrant: the one operation a touch-gated SIGN or UNSEAL may run. It is made once per call and KeyGrant::run() takes it by value; any result that may have let the enclave act consumes it. Only an outright refusal (EKEYREJECTED: nothing performed) returns it, once, for the retry the verify makes after completing the evaluation. A transport error no longer leads to a second attempt. - OwnedContext: the credential context a /dev/sep-key verify opens is deleted when it drops, on every path out of run_verify(); the key self-tests use it too, so an early return no longer leaks a context (self-test 10 could leak one holding a user password credential). - A signal to the caller, or its death, ends a touch wait with EINTR at once (the capture checks it); before, the wait ran on for up to a minute and could still sign for a caller that was gone. - Self-test modes 20 and 21, which run a second operation in an open matched context, are built only with the new research option CONFIG_APPLE_SEP_KEY_RESEARCH (default n) and return EOPNOTSUPP otherwise; production kernels contain no code that can do it. Requests are now copied in and checked by read_request() before anything acts: straight into kernel memory (no stack copy of a secret), with SEAL/UNSEAL/self-test buffers wiped on drop, and a malformed record or sealed blob is refused before a touch is asked for instead of after the match. The REARM password is read the same way. KUnit: apple_sep_key_one_op (one success leaves nothing to run, one retry after a refusal only, other failures consume the grant, the context is deleted exactly once on each exit path, research modes absent), apple_sep_key_fuzz (lengths at and past their bounds, every flag value, mutated and random records and requests), and the C suite apple_sep_ioctl, which drives every /dev/sep-key request, the /dev/sep-bio session ioctls and REARM from real user memory (kunit_vm_mmap): unaligned, truncated, faulting and random buffers. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
sep-ioctl-fuzz.py runs on a Mac as root and needs no finger. It sends malformed, truncated, unaligned and faulting requests, random bytes and unknown commands to /dev/sep-key, hammers it from eight threads, cancels and signals touch-gated calls, and sends /dev/sep-bio only read-only calls and starts that are always refused (never a valid enrol, verify or delete). It passes when every refusal is a clean errno, nothing hangs, and the kernel log gains no oops, warning, KASAN or kmemleak report. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
RyanTheTide
marked this pull request as ready for review
November 11, 2026 11:50
This was referenced Nov 11, 2026
Merged
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.
SEP driver hardening for
/dev/sep-keyand the shared SEP paths.One Touch ID match runs exactly one key operation. The enclave lets a matched credential context authorise any number of operations until it is deleted (self-test 20/21 measured a second signature, and a signature followed by an unseal). The kernel now enforces the bound in its types:
KeyGrantholds the one operation of a touch-gatedSIGN/UNSEAL.run()takes it by value, so once an operation has run, or has failed in a way that may have let the enclave act, nothing is left to run another. Only an outright enclave refusal (EKEYREJECTED) returns it, once, for the existing retry after the evaluation completes. A transport error no longer triggers a second attempt.OwnedContextdeletes the credential context on drop, so every way out of the key-mode verify and the key self-tests deletes it.EINTR. That includes the caller dying.CONFIG_APPLE_SEP_KEY_RESEARCH(default n). Without it they returnEOPNOTSUPP.read_request()copies every request straight into kernel memory and checks it before anything acts. SEAL/UNSEAL/self-test buffers are wiped on drop. A malformed record or sealed blob is refused before the caller is asked to touch the sensor, not after the match.Shared SEP paths
key_bag_lock, like/dev/sep-key. Before, an unload on one path could end the handle another was using.refkey_sealwipes the shared secret, KDF output and plaintext on every error path and never reallocates them.Tests
apple_sep_key_one_op,apple_sep_key_fuzz, and the C suiteapple_sep_ioctl. The C suite drives every/dev/sep-keyrequest, the/dev/sep-biosession ioctls andREARMfrom real user memory (kunit_vm_mmap): unaligned, truncated, faulting, out-of-range and random input.tools/testing/selftests/drivers/apple/sep-ioctl-fuzz.py: root, no finger. It covers malformed, faulting and concurrent requests, cancel, SIGINT/SIGKILL during a touch wait, and checks the kernel log stays clean.