Repository navigation
soc: apple: sep: Take SBIO reply headers only once they have landed - #352
Merged
Merged
Conversation
The receive work waits for an SBIO reply header to leave the poison fill, but takes it as soon as any one byte has changed. The mailbox notification is not ordered against the enclave's DMA, so the header can be only partly visible. With chunk still poison, the payload read fails its bounds check; with version still poison, the reassembly rejects the reply. Both end the exchange with the NotAnswered sentinel, so the log says that no message arrived at all when one did. An M1 Pro logged exactly that for INIT_SBIO_COMMUNICATION about 3 ms after powering the sensor. That is when its reply normally arrives, and far short of the 5 s SBIO timeout, which returns ETIMEDOUT instead. Wait until every header word that taking the message reads has left the fill, within the existing 200 x 1 ms poll budget: all but flags for a data chunk, and err for an error report. No valid reply holds the fill in those words. A grant or a notification reads no header, so it is no longer held up by the buffer. Before the first reply of a boot, a grant used to wait 200 ms and then end the exchange that it was granting. An error report has no payload, so none is read. Report a reply whose header never fully lands, or fails a check, as Malformed. A header that stays entirely poison is still reported as BufferNeverWritten, and NotAnswered is kept for host-side failures. This is host-side only. No message to the enclave is added, removed or reordered, and no xART path is touched. KUnit tests (apple_sep_transfer) cover a torn header, a header that lands late, one that never lands, one left partly written, poison in flags, an error report, a grant and a reply failing its checks. Fixes: bac0846 ("soc: apple: add Apple SEP driver (Touch ID and key sealing)") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Waiting for the reply header to leave the poison fill only works while the header region holds the fill, and it does so only until the first reply of a boot. Every later header lands on top of the one before it. If its notification overtakes the DMA, the receive work finds the previous header complete and takes it for the new one. A reply to the same opcode then completes the exchange with the previous answer, and a continuation chunk fails its offset check. Fill the header with the poison again as soon as it has been looked at, before the message is processed. That is before any continuation is sent, and before the requester wakes to send its next request. The receive work is the only reader of the header, so this cannot race a read. A grant or a notification does not read the header and leaves it alone. This is host-side only. Nothing sent to the enclave changes. KUnit tests (apple_sep_transfer) cover the next exchange's reply, a continuation chunk and the refill itself. Fixes: bac0846 ("soc: apple: add Apple SEP driver (Touch ID and key sealing)") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
A grant leaves the outbound header alone, because the reply may already be landing behind it. The enclave's grant may itself have written a header there, as the host's own grant writes a request-next header in the inbound buffer, and nothing reads or refills it. After a multi-chunk send, such as a Touch ID capture relay, the reply could take that header once its own has not landed yet: a data reply would fail its offset check as malformed, and an error report would read err 0 and hide the enclave's status. Poison the header again just before each chunk of a request is sent, the first and every later one, through a new send_for_reply(). The enclave is waiting for the host there, so no header can be landing. A continuation is sent straight after its chunk's header was taken and refilled, so it needs no change. A grant still leaves the buffer alone. Add KUnit cases for a grant's header followed by a data reply and by an error report, and for the refill coming before the send. The first two fail with the refill taken out of send_for_reply(). 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.
The SEP's SBIO channel carries the Touch ID traffic: sensor bring-up, the capture relay used by enrol and verify, and template saves. The receive work decided that a reply had arrived as soon as any byte of the reply header left the poison fill. The mailbox notification isn't ordered against the enclave's DMA, so a header could be read half-landed, or the previous exchange's header could be read again. Both ended the exchange with a misleading status:
NotAnsweredwhen a reply had arrived,Malformedon a valid continuation, orerr 0hiding the enclave's real error. An M1 Pro logged exactly this forINIT_SBIO_COMMUNICATION, about 3 ms after sensor power-on, in roughly 1 boot in 16.Fix (3 commits, host-side only)
Malformed. A header that stays entirely poison is stillBufferNeverWritten.send_for_reply(). A multi-chunk relay such as a Touch ID capture can then never take a stale header.No message to the enclave is added, removed or reordered, and no xART path is touched. KUnit
apple_sep_transferadds cases for:The grant-then-reply cases fail with the refill taken out.
Testing
dma_wmb()before the mailbox doorbell, and one wording nit.a6d2a12agives tree22069460856d. That is byte-identical to the SEP integration kernel (integ/sep-20261017598fa89b2906) that both machines below ran.sudowith a fingerprint: PASS;verify-no-match;Malformed, 0BufferNeverWritten, 0 status-NONE lines, 0 bring-up retries; Touch ID registered on the first attempt.APPLE_SEP=m):Malformed,BufferNeverWrittenor no-message lines;verify-matchwith that finger andverify-no-matchwith another;Malformed,BufferNeverWritten, status-NONE or WARNING lines in that window; every xART write the enclave asked for returned status 0;rpasses 142/144 (2 deliberate skips).🤖 Generated with Claude Code