Repository navigation
soc: apple: sep: hold hwrng requests across system sleep and recover a timed-out entropy exchange - #351
Merged
Conversation
Every GET_ENTROPY request carries the same reserved tag, and the exchange ends as soon as its waiter gives up. A reply that comes after its request timed out is then taken as the answer to the next request, and from there on every answer is one request late. Nothing stops the hwrng fill thread from asking again either. Each retry is one more message the enclave is not reading, in the inbox it shares with the key store, Touch ID and the xART service, and once that is full every send to the enclave waits 500 ms for room and fails. Count the requests that the mailbox took and the enclave has not answered. The enclave answers in order, so only the reply that settles the newest one is its answer, and earlier replies are dropped. After a request goes unanswered, or the mailbox has no room for it, hold further requests back with EAGAIN for 1 s, doubling with each failure up to 60 s, and resume as soon as a late reply shows that the enclave is answering again. A request made once the wait is over counts what is still owed as lost, so a reply that never comes cannot stop the channel for good. A held-back hwrng read returns -EAGAIN and is not logged as a failure; the core tries again 10 s later. A held-back survey attempt is not counted against the five the survey gets. KUnit tests (apple_sep_control) cover a reply in time, a late reply, a reply that comes after the retry, a lost reply, a full mailbox, a failed send, the back-off and a request abandoned for removal. Fixes: bac0846 ("soc: apple: add Apple SEP driver (Touch ID and key sealing)") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
The hwrng fill thread is not frozen for system sleep, and nothing in the driver held it back, so it could ask the enclave for entropy while devices were suspended. On an M1 Pro (T6000) one such request, sent during the 5 s pm_test=platform hold, was never answered. After the resume the enclave sent nothing more and did not read its mailbox again: every send timed out waiting for room, so /dev/hwrng stayed dead until reboot, and no other enclave service could be reached either. With the hwrng source deselected over three suspend cycles the enclave kept working, so it survives the sleep itself; it does not survive a request in that window. Hold entropy requests from the start of a suspend or hibernation until its end is reported, on the PM notifier that already holds Touch ID captures. Its window contains the whole of device suspend. A request already sent is first given time to be answered, which the enclave can still do then. A read in the window returns -EAGAIN, which the core treats as a source with nothing to give, and it tries again after the resume. KUnit tests cover a read while the system sleeps and a request in flight when the sleep begins. Fixes: bac0846 ("soc: apple: add Apple SEP driver (Touch ID and key sealing)") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
RyanTheTide
added a commit
that referenced
this pull request
Oct 17, 2026
Bring the 7.2.10 assembly to the tree of the canonical top-up #6 assembly, stacked on top-up #5 f34b5ae so that it is a fast-forward of the published branch. The second parent is that canonical assembly; the tree is identical to it. Ported from aurora-wip, each with cherry-pick -x and its original author: - #347 KUNIT_ALL_TESTS=m modpost (3): the xHCI platform tests call the interrupt handler through the HC driver (170-usb), and module descriptions for the CD321x PM tests (170-usb) and the drm/apple KUnit test modules (200-dcp). - #349 the CD321x IRQ test waits for the resume read before checking its retry (170-usb). - #350 trusted keys keep a source that registers before init_trusted() (100-sep). Its test commit is already carried as 76d70cc and is not duplicated. - #351 SEP hwrng: recover the entropy exchange after a request times out, and hold entropy requests while the system sleeps (100-sep). - #352 SEP SBIO: take a reply header only once it has landed, and poison it again once read and before each host send (100-sep). Adaptations, each with a [ryan: ...] note in its commit: - trusted-type.h: context only, the declaration goes above the 7.2.10 CONFIG_TRUSTED_KEYS_DEBUG block; - the CD321x IRQ test takes its data from tipd_hw_variants[], and its retry loop replaces the 7.2.10-only fix of the same race in 11e0ce6. The Co-Authored-By lines of the three #347 commits are dropped. 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.
After a suspend that overlapped an SEP entropy request,
/dev/hwrngstopped working and the SEP mailbox stopped answering until reboot. That mailbox is the same inbox the key store, Touch ID and xART use. It was seen on the M1 Pro duringpm_test=platform.Causes (from code and the M1 Pro trace)
GET_ENTROPYwhile devices were suspended. On the M1 Pro, the request timed out exactly inside the platform hold.Fix (2 commits)
-EAGAIN, starting at 1 s and doubling up to 60 s. A late reply lifts the hold at once.apple_sep_controlcovers it, 9 cases.Testing
-EAGAINduring backoff;pm_test=platformwith the SEP feeding the kernel RNG: afterwards/dev/hwrnggives 64 B in 27 ms and the SEP mailbox answers. Before the fix, every read timed out in 0.5 s and the mailbox was silent./dev/hwrngand the mailbox stay healthy./dev/hwrngreader ran through 3 × 60 s s2idle and 3 ×pm_test=platform: 97/97 reads returned 32 B;545d7e45+ this + the trusted-key init-order fix + the SBIO header-landing fix).rpasses 142/144 (2 deliberate skips), and apple-dcprun.pypasses 55/55.🤖 Generated with Claude Code