Skip to content

soc: apple: sep: Take SBIO reply headers only once they have landed - #352

Merged
RyanTheTide merged 3 commits into
aurora-wipfrom
fix/sep-sbio-header-landing-20261017
Oct 17, 2026
Merged

RyanTheTide merged 3 commits into
aurora-wipfrom
fix/sep-sbio-header-landing-20261017

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

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: NotAnswered when a reply had arrived, Malformed on a valid continuation, or err 0 hiding the enclave's real error. An M1 Pro logged exactly this for INIT_SBIO_COMMUNICATION, about 3 ms after sensor power-on, in roughly 1 boot in 16.

Fix (3 commits, host-side only)

  1. Take an SBIO reply header only once it has landed. Wait until every header word the receive path reads has left the fill, within the existing 200 × 1 ms poll budget. A grant or notification reads no header, so it is no longer held up by the buffer. Before this, a grant before the first reply of a boot waited 200 ms and then ended the exchange it was granting. A header that never fully lands is reported as Malformed. A header that stays entirely poison is still BufferNeverWritten.
  2. Poison an SBIO reply header again once it is read. The fill only marks "not yet landed" until the first reply of a boot, because each later header lands on top of the one before it. The header is re-poisoned as soon as it has been read, before any continuation is sent and before the requester can wake.
  3. Poison the SBIO reply header before each host send. A grant from the enclave may itself leave a header in the outbound buffer. The header is refilled just before each chunk of a request is sent, the first and every later one, through 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_transfer adds cases for:

  • a torn header, a late one, one that never lands, one partly written, and poison in flags;
  • an error report, a grant, and a reply failing its checks;
  • the next exchange's reply and a continuation chunk;
  • the refill coming before the send.

The grant-then-reply cases fail with the refill taken out.

Testing

  • Review: independent, PASS (0 BLOCKER/MAJOR). Its MINOR-1, the refill before every send, is commit 3. Open follow-ups: dma_wmb() before the mailbox doorbell, and one wording nit.
  • Merged tree = tested tree. This branch merged into aurora-wip a6d2a12a gives tree 22069460856d. That is byte-identical to the SEP integration kernel (integ/sep-20261017 598fa89b2906) that both machines below ran.
  • MacBook Neo, attended, on that kernel:
    • lid close/reopen plus lock-screen fingerprint unlock: PASS;
    • sudo with a fingerprint: PASS;
    • a wrong finger: a clean verify-no-match;
    • a 4th enrol was refused by the enclave's 3-slot cap, and its duplicate-check capture was clean;
    • across the boot: 0 Malformed, 0 BufferNeverWritten, 0 status-NONE lines, 0 bring-up retries; Touch ID registered on the first attempt.
  • M1 Pro, on the same tree (Fedora config, APPLE_SEP=m):
    • 5 of 5 cold boots: SBIO init accepted 0.2–3.0 ms after power-on, with 0 refused, Malformed, BufferNeverWritten or no-message lines;
    • attended: a full left-index enrol (the multi-chunk capture relay plus the template save) completed, then verify-match with that finger and verify-no-match with another;
    • 0 Malformed, BufferNeverWritten, status-NONE or WARNING lines in that window; every xART write the enclave asked for returned status 0;
    • xART ledger: the enrol rewrote only the two records Linux had already written on this machine, plus the two shared roots. The other 12 records are unchanged.
  • Build: the published config builds with 0 warnings. KUnit r passes 142/144 (2 deliberate skips).

🤖 Generated with Claude Code

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
RyanTheTide merged commit 0daed2d into aurora-wip Oct 17, 2026
@RyanTheTide
RyanTheTide deleted the fix/sep-sbio-header-landing-20261017 branch October 17, 2026 10:48
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]>
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