Skip to content

soc: apple: sep: let a sep-bio capture end a sep-key touch wait - #2903

Merged
RyanTheTide merged 2 commits into
mainfrom
sec/sep-key-touch-preempt
Nov 26, 2026
Merged

RyanTheTide merged 2 commits into
mainfrom
sec/sep-key-touch-preempt

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A touch-gated /dev/sep-key call (SIGN/UNSEAL with a biometric key) holds the sensor lock (catacomb_writer) while it waits up to a minute for a finger. A Touch ID verify or enrolment that /dev/sep-bio starts in that time (fprintd for a login, sudo or lock-screen prompt) queues its work item behind that lock, so the prompt gets no sensor until the key call ends. In addition, capture_live() returned true while either owner had a live capture, so with a /dev/sep-bio capture queued, SEP_KEY_CANCEL and a signal to the caller did not end the key call's wait either.

Change

  • One pure decision function, touch_capture_wanted(key_wait, key_ended, bio_live): while a touch-gated call owns the capture, it is wanted until the call is cancelled, signalled or the driver goes away, or until /dev/sep-bio has a capture of its own that has not ended. The key call holds the sensor lock, so such a capture can only be one waiting for it.
  • key_touch_run(): a call that finds a /dev/sep-bio capture already pending returns EBUSY before starting a capture; a capture given up for /dev/sep-bio is reported as EBUSY (not EIO), the lock is dropped and the queued work item runs.
  • UAPI header: EBUSY added to the documented /dev/sep-key errors ("try again later").

A match or a non-match that was already decided is reported as before. Calls with no /dev/sep-bio activity behave exactly as before. No new lock, field, timer or parameter.

Testing

  • KUnit (apple_sep_key*, arm64 under QEMU), new case a_bio_capture_takes_the_sensor_from_a_key_touch_wait covering the decision table. 40/40 pass; with the old expression (key_wait && !key_ended) || bio_live the new case fails (39/40).
  • W=1 build of apple-sep: no new warnings.

Still to run

  • Hardware row on a Touch ID Mac on the default cmdline: a touch-gated SEP_KEY_SIGN waiting, then an fprintd verify -> the key call returns EBUSY and the verify gets the sensor; SEP_KEY_CANCEL ends a wait while a verify is queued. Plus the SEP attach/Touch ID smoke of the other SEP rows.
  • Userspace (aurora-sep-userspace) should treat EBUSY from /dev/sep-key as "try again".

A touch-gated /dev/sep-key call holds the sensor lock while it waits
for a finger, up to a minute. A verify or an enrolment that /dev/sep-bio
starts in that time queues its work item behind the lock, so a login or
sudo prompt gets no sensor until the key call ends. The capture of the
key call was also kept alive by the queued /dev/sep-bio capture:
capture_live() returned true for either owner, so SEP_KEY_CANCEL and a
signal to the caller did not end the wait while a prompt was queued.

Decide who the running capture belongs to in one place,
touch_capture_wanted(). While a touch-gated call owns the capture it is
wanted until the call is cancelled, signalled or the driver goes away,
or until /dev/sep-bio has a capture of its own that has not ended. The
key call holds the sensor lock, so such a capture can only be waiting
for it. The call then returns EBUSY and drops the lock, and the queued
work item runs. A call that finds a /dev/sep-bio capture already queued
when it gets the lock returns EBUSY without starting a capture.

The UAPI header lists EBUSY for this case.

A match or a non-match that was already decided is reported as before.
Calls with no /dev/sep-bio activity behave as before.

Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Non-author review of d91adf9. Verdict: no blocker. I read the code; I didn't run KUnit and have no hardware row.

Checked and holding

  • The key call's own capture can't trip the new check. It runs through capture_begin()/run_verify()/capture_end(). bio_capture_live() reads capture_is_live(bio_session, capture_epoch), which is true only for a /dev/sep-bio enrol/verify op, so the EBUSY at the loop head doesn't fire on the call's own retries.
  • Lock order is unchanged. bio_capture_live() takes bio_session while catacomb_writer is held, the same nesting the old capture_wanted expression already had inside run_verify().
  • The decision table matches the description, and the case it adds (true, false, true → false) is the one the old expression got wrong. Cancel, signal and shutdown still win over a queued bio capture (key_ended is checked first), and ECANCELED/EINTR are still reported ahead of EBUSY after a capture, because those checks come before the match.
  • A decided match or non-match is reported as before. Only Failed(_)/None with a live bio capture becomes EBUSY.

Points

  1. "A capture of its own that has not ended" includes a long-running verify: for example, a lock screen or a pending PAM prompt that keeps a fprintd verify open until a finger arrives. For as long as that verify is open, every touch-gated /dev/sep-key call returns EBUSY at the loop head without trying. That is probably the right priority. But "treat EBUSY as try again" in userspace then needs a backoff, or a wait on something, instead of an immediate retry, or it spins for the whole prompt. Is there an aurora-sep-userspace change for that yet? Please link it from "Still to run".
  2. The hardware row should include that steady-state case (verify open, then a key call → immediate EBUSY, no capture started), not only "a key call waiting, then a verify starts". Run it on each Touch ID Mac in the lab that has a working sensor path, since the timing differs per sensor.
  3. Nit: the new match arm Some(TouchOutcome::Failed(_)) | None if self.bio_capture_live() also turns a real sensor failure (not one caused by giving the sensor up) into EBUSY whenever a bio capture happens to be queued. That's harmless with retry semantics, but the comment says "a capture given up". Consider saying "failed or given up" so the next reader doesn't take EBUSY to mean only preemption.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Review at d91adf9.

The ownership logic is right. One security tightening and two coverage gaps.

  1. Correct as far as I can see. With no key wait, touch_capture_wanted() reduces to the old expression. NoMatch is its own variant, so a real non-match is still EACCES; only Failed/None become EBUSY. bio_session was already taken under catacomb_writer through capture_live(), so the new bio_capture_live() calls in key_touch_run() add no new lock order. The try_lock() users in sbio.rs are lockout bookkeeping, not captures, so "the queued capture can only be waiting for the lock" holds.
  2. Fail closed on an ambiguous touch. A Matched outcome that comes back while bio_capture_live() is true still returns Ok (key.rs:1689), so it authorises the SIGN/UNSEAL. A finger that lands just after a login/sudo prompt opened was most likely meant for that prompt. This isn't a regression (before, the key call took every such touch), but the PR now decides ownership in one place, so treat Matched && bio_capture_live() as EBUSY: the key operation is denied and the caller retries. The check is still racy against a prompt that opens after the match, but it strictly narrows the window.
  3. Starvation. A key call now loses to any live /dev/sep-bio verify, including fprintd's continuous verify on the GNOME lock screen. Touch-gated key calls made while locked (e.g. an agent signing for a background job) get EBUSY for as long as the screen is locked. Please say in the UAPI comment that callers must back off rather than spin. Also state who can open /dev/sep-bio: if that set is wider than the key callers, a loop of verifies denies all touch-gated key use.
  4. Tests: KUnit covers the decision table only. Neither new EBUSY arm in key_touch_run() (the loop-top check at :1667 and the Failed|None arm at :1697) is exercised. A case with a live bio session before capture_begin(), and one where it goes live mid-capture, would cover both.
  5. A new errno under the same SEP_KEY_IFACE_VERSION 4 is fine. Please link the aurora-sep-userspace change that handles it, so the two land together.

Rows: as listed. Please add the lock-screen case: screen locked with fprintd verifying, then a touch-gated SEP_KEY_SIGN returns EBUSY promptly, and unlocking by fingerprint still works.

@DjDeveloperr DjDeveloperr left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adversarial pre-PR checklist (§1–§6) review at d91adf9ae97d1f311d397a947868d3ff6854b481 (CI: 7/7 green — host-tests, kunit, rust-build, source, and all 3 DWC3/ATC builds).

Verdict: REQUEST CHANGES — the core touch_capture_wanted() ownership truth table and key_touch_run() EBUSY preemption design are clean, and commit/PR hygiene (§4, §6) passes, but two remaining sites in drivers/soc/apple/sbio.rs still use the old disjunctive key_touch_active || bio::verify_is_live logic (causing a spurious dev_err on every preemption and leaving bring-up retries unpreempted), and the §5 hardware row is still unrun.

Blocking findings

  1. Spurious dev_err_ratelimited! on every preemption / cancel (drivers/soc/apple/sbio.rs:3073-3084):

    • When /dev/sep-bio starts a capture during a /dev/sep-key touch wait, await_capture() returns CaptureWait::Abandon because !self.capture_live() (sbio.rs:4338).
    • The CaptureWait::Abandon arm at sbio.rs:3075 still checks:
      if self.key_touch_active.load(Relaxed)
          || bio::verify_is_live(&self.bio_session.lock(), self.capture_epoch.load(Relaxed))
      instead of self.capture_live().
    • Because key_touch_active is true (and bio::verify_is_live is also true for a verify), every /dev/sep-bio preemption (as well as SEP_KEY_CANCEL or a caller signal) logs a false kernel error: "verify: the sensor status became unreadable during the capture". That violates §5's 0 new kernel errors bar on the exact normal path this PR introduces. Replace the guard with if self.capture_live().
  2. verify_wanted() still uses the old disjunctive check (drivers/soc/apple/sbio.rs:2556-2560):

    • The commit message states ownership is decided in one place (touch_capture_wanted()), but verify_wanted() (called by bring_sensor_online_for_verify() on nonce-session sensors during retry) still evaluates:
      !self.shutting_down.load(Relaxed)
          && ((self.key_touch_active.load(Relaxed) && !self.key_touch_cancel.load(Relaxed))
              || bio::verify_is_live(&self.bio_session.lock(), self.capture_epoch.load(Relaxed)))
    • It neither yields to a queued /dev/sep-bio capture nor checks signal_pending(), and with a /dev/sep-bio verify queued, SEP_KEY_CANCEL still fails to abort bring-up retries — the exact bug this PR fixes in capture_live(). Delegate verify_wanted() to self.capture_live().
  3. Missing §5 hardware evidence:

    • As noted in Still to run, no Touch ID Mac hardware row has been executed yet on the default command line. Before merge, record hardware evidence covering: (a) touch-gated SEP_KEY_SIGN preempted by an fprintd verify -> EBUSY and verify succeeds, (b) steady-state open verify (e.g., lock screen) -> immediate EBUSY without starting a capture, (c) SEP_KEY_CANCEL while a verify is queued, and (d) regression check: 0 new kernel errors (which will also confirm blocker #1 is fixed), 0 SELinux denials, 0 failed units.

Non-blocking notes

  • KUnit currently tests only the pure touch_capture_wanted() table; adding coverage for the two new EBUSY branches in key_touch_run() (key.rs:1667, :1697) would pin the ioctl-level behavior.
  • In include/uapi/linux/apple-sep.h, consider clarifying that callers retrying EBUSY should back off rather than busy-spin while a continuous /dev/sep-bio verify (such as a lock screen prompt) is open, and linking the companion aurora-sep-userspace change.

§1–§6 Checklist Summary

  • §1 No model gating: Pass (no chip/board/firmware gates).
  • §2 Production-ready: Blocked — sbio.rs:3075 spurious dev_err on preemption and sbio.rs:2556 stale verify_wanted() check.
  • §3 Safety: Pass (unchanged lock ordering: catacomb_writer -> bio_session; no hardcoded safety limits).
  • §4 Clean-room & attribution: Pass (human author/committer + human Signed-off-by: only, zero AI trailers in commit, Assisted-by: in PR body).
  • §5 Evidence: Blocked — KUnit/W=1 pass, but 0 Touch ID Mac hardware rows run yet.
  • §6 Naming: Pass.

Two places in sbio.rs still decided on their own whether the capture
was wanted, with the expression capture_live() had before:

- The verify capture's CaptureWait::Abandon arm logged "the sensor
  status became unreadable during the capture" whenever a touch-gated
  call was active, so a capture given up for /dev/sep-bio, cancelled or
  ended by a signal was reported as a sensor fault.
- verify_wanted(), which bounds the bring-up retries of a verify on
  sensors with a nonce session, neither gave way to /dev/sep-bio nor
  ended on a signal to the caller, and kept retrying after
  SEP_KEY_CANCEL while a /dev/sep-bio verify was queued.

Use capture_live() in both. The UAPI text now also says that a caller
retrying after EBUSY should back off, as a /dev/sep-bio verify can stay
open for a long time.

Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Thanks; blockers 1 and 2 were real. New commit b729c69 (no history rewrite): the verify capture's CaptureWait::Abandon arm and verify_wanted() now both use capture_live(), so a capture given up for /dev/sep-bio, cancelled or signalled no longer logs "the sensor status became unreadable", and the bring-up retries yield and stop on SEP_KEY_CANCEL or a signal like the capture does. The UAPI text now says to back off on EBUSY. KUnit apple_sep* 315/315, W=1 adds no warnings. The Touch ID hardware row (a-d as you listed) is next; I'll post it here.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Review at b729c69.

b729c69 is right for what it covers. verify_wanted() and the CaptureWait::Abandon arm now share capture_live(), so a capture given up for /dev/sep-bio no longer logs a sensor fault, and the UAPI text says to back off on EBUSY. Status of my points from d91adf9:

  • 2 (fail closed on an ambiguous touch): open. key_touch_run() still returns Ok for Matched while bio_capture_live() is true, so a finger meant for a just-opened login/sudo prompt can still authorise a SIGN/UNSEAL. Mapping Matched && bio_capture_live() to EBUSY is a one-line change. Now that ownership is decided in one place, this is where it belongs. If you disagree, please say why the key caller should keep that touch.
  • 3 (starvation): half done. The back-off sentence is in. Still missing: who can open /dev/sep-bio (mode/group, udev rule). If that set is wider than the key callers, a verify loop denies all touch-gated key use.
  • 4 (tests): open. The two new EBUSY arms in key_touch_run(), the loop-top check and the Failed|None arm, still have no KUnit case (bio session live before capture_begin(), and going live mid-capture). The 315/315 run doesn't reach them.
  • 5: open. Please link the aurora-sep userspace change that handles the new EBUSY.

Rows: the Touch ID a-d rows you're running, plus the lock-screen case (fprintd verifying, a touch-gated SEP_KEY_SIGN gets EBUSY promptly, fingerprint unlock still works). Verdict: changes (point 2), nits for 3-5.

@DjDeveloperr DjDeveloperr left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formal adversarial §1–§6 re-review at b729c69a9356ab5b7e03671f8d488f10decbc5d9 (REQUEST_CHANGES — Wave 58B code blockers resolved, 0 remaining code blockers; still blocked on owed §5 Touch ID hardware row and pending CI).

Wave 58B Fix Verification

  1. drivers/soc/apple/sbio.rs:3073-3083 (CaptureWait::Abandon spurious dev_err): Fixed. Now checks if self.capture_live(), so a capture abandoned due to /dev/sep-bio preemption, SEP_KEY_CANCEL, or a caller signal no longer logs "verify: the sensor status became unreadable during the capture". Verified sbio.rs:4183 (enrolment Abandon) is /dev/sep-bio-only and unaffected.
  2. drivers/soc/apple/sbio.rs:2558-2560 (verify_wanted() stale disjunctive check): Fixed. Now delegates directly to !self.shutting_down.load(Relaxed) && self.capture_live(). Audited all other key_touch_active / verify_is_live sites in sbio.rs (:2660 is the sensor-reuse guard; :2716 is key_mode) — zero remaining stale liveness checks.
  3. UAPI backoff guidance (include/uapi/linux/apple-sep.h:309-312): Addressed. Now explicitly tells callers to back off when retrying EBUSY since a /dev/sep-bio verify (e.g., lock screen) can stay open for a long time.

Checklist Summary

  • §1 (No model gating): Pass.
  • §2 (Production-ready, no hacks): Pass — both prior sbio.rs blockers resolved cleanly in b729c69a9356.
  • §3 (Safety): Pass — lock ordering (catacomb_writer → bio_session) unchanged.
  • §4 (Clean-room & attribution): Pass — both commits (d91adf9ae97d, b729c69a9356) carry human author/committer (Ryan Murray <[email protected]>) and human Signed-off-by: only (zero AI trailers in commits); PR body includes Assisted-by:.
  • §5 (Evidence): Blocked — see Blockers below.
  • §6 (Naming): Pass.

Remaining Blockers

  1. §5 (Owed Touch ID hardware row): No hardware row has been posted yet at b729c69a9356. Owed on a Touch ID Mac on the default command line: (a) touch-gated SEP_KEY_SIGN preempted by fprintd verify → EBUSY and verify succeeds, (b) steady-state open verify / lock screen → immediate EBUSY without starting a capture and fingerprint unlock still works, (c) SEP_KEY_CANCEL while a verify is queued, and (d) regression counts: 0 new kernel errors, 0 SELinux denials, 0 failed units.
  2. CI pending: 2/7 green (source, rust-build); 5/7 still QUEUED (host-tests, kunit, DWC3/ATC ×3).

Non-blocking Notes

  • Ambiguous Matched && bio_capture_live() touch: Note that inside run_verify() (sbio.rs:2853-2871), self.key_touch_sign() / self.key_touch_after_close() execute before key_touch_run() inspects outcome (key.rs:1691). If you choose to fail closed on an ambiguous match when a /dev/sep-bio prompt has just opened, guard both sbio.rs:2853 (so the enclave sign/unseal is not invoked) and key.rs:1691 (returning EBUSY).
  • Adding KUnit cases exercising the two EBUSY arms in key_touch_run() (key.rs:1670, :1700), documenting /dev/sep-bio device permissions wrt starvation, and linking the companion aurora-sep-userspace EBUSY handling PR remain helpful follow-ups.

@github-actions github-actions Bot added area:platform Area from CODEOWNERS (bot) changes-requested A reviewer requested changes (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Merge readiness at b729c69a: ready to merge

Check Detail
CI at head ok 7 checks passed
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok comment at b729c69a
Conflicts ok none
PR text adopt when you next edit add a 'Tested:' line; a 'Risk:' line (door and Macs) (guide)

Areas: area:platform
Merge: gh pr merge 2903 --merge (Owners and Core through the bypass: add --admin).

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: FINISH, then merge at b729c69a9356: the code is ready; it needs only a row at this head.

Blockers: none in the code. Missing row: one Touch ID Mac at this head: a touch-gated SEP_KEY_SIGN is ended by an fprintd verify with EBUSY and the verify succeeds, and the lock screen unlocks by fingerprint as before.

Checked: no Apple material, no gates. CI green.

@DjDeveloperr
DjDeveloperr dismissed stale reviews from themself November 25, 2026 03:56

Superseded by the review at b729c69

@github-actions github-actions Bot removed changes-requested A reviewer requested changes (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 25, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

b729c69a9356 (batched cleanly in J616s Batch #2 5b411e230229 over main 95a983c08be4, 0 merge-tree diffs across all 3 changed files) J616s (MacBook Pro 16" M4 Pro, T6040, Apple M4 Pro (G16S B1), macOS 26.6.2 fw, guarded one-shot 7.3.0-aurora-pr2905+, default cmdline, stock Stage 2 1.0.0b17, boot_id=de17fad3) PASS: 0 failed units, Enforcing, 0 new AVC (1 matching baseline), 0 GPU faults, 0 errors in this subsystem, real rtc1 s2idle 2/2 (success=2 fail=0), eDP connected pre/post-sleep, 406600000.sep + 514600000.mtp RTKit v12 (AppleMTPFirmwareMac-5340.61.4~502, HID keyboard/trackpad/accel/actuator/touch) clean, Borealis VK dEQP-VK.api.smoke.* 8/8 (pre & post-sleep) + glsl.loops.* 624/624, Wi-Fi 3/3 ping pre/post-sleep; stock 7.3.0-aurora-fleet89 restored & verified (b67edc6c).

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed needs-hw-row No hardware row at the PR head (bot) labels Nov 25, 2026
@RyanTheTide
RyanTheTide merged commit dbd26fb into main Nov 26, 2026
10 of 11 checks passed
@RyanTheTide
RyanTheTide deleted the sec/sep-key-touch-preempt branch November 27, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:platform Area from CODEOWNERS (bot) needs-template PR body lacks Tested or Risk (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants