From b770e8d3b077402cf0a1d0a8d68f437eb8ded7b0 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 11 Nov 2026 16:56:02 +0700 Subject: [PATCH] soc: apple: sep: Bring a kept Touch ID sensor up afresh for a new prompt The verify path keeps the sensor powered between touches so the next try of the same prompt does not pay for a bring-up. A sensor kept across two separate authentications is not safe to reuse: on the MacBook Air 15-inch (M5, J815) a sensor that sat idle for 57 s between two sudo prompts had reset itself and asked for its patch again (state 9) in the middle of the next capture, so the second prompt failed with "sensor failed" and fell back to the password. Reuse the kept sensor only within the authentication that is still open (same match scope generation, match context still present, no key touch in progress); otherwise power it off and bring it up afresh, which takes about 40 ms. If the sensor still falls to state 9 under a capture, report a retry with PLACE guidance instead of a sensor failure, end the prompt's match operation and drop the sensor, so the user's next touch starts from a fresh bring-up. Tested on J815 (two boots): sudo with the finger in prompts minutes apart and two more enrolments; no state-9 failure since the change. Assisted-by: Claude Opus 5.5 Signed-off-by: Nick --- drivers/soc/apple/sbio.rs | 35 +++++++++++++++++++++++++++++++++-- drivers/soc/apple/sep.rs | 6 ++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/drivers/soc/apple/sbio.rs b/drivers/soc/apple/sbio.rs index 77a44c1c1f7a5..81e77a2bb235d 100644 --- a/drivers/soc/apple/sbio.rs +++ b/drivers/soc/apple/sbio.rs @@ -2584,6 +2584,23 @@ impl SepData { return; }; + // Reuse the kept sensor only for the next touch of the authentication + // that is still open. A new authentication brings it up afresh: on + // J815 a sensor kept idle for 57 s between two sudo prompts had reset + // itself and lost its patch (state 9 in the next capture, boot + // 0f4c4bbd), while a fresh bring-up takes about 40 ms. + if self.sensor_kept.load(Relaxed) + && (self.key_touch_active.load(Relaxed) + || self.match_scope_gen.load(Relaxed) != self.bio_open_gen.load(Relaxed) + || self.match_context.lock().is_none()) + { + dev_info!(self.dev, "verify: a new authentication; bringing the sensor up afresh instead of reusing it\n"); + let _ = sensor::idle(); + self.sensor_kept.store(false, Relaxed); + self.forget_finger_lift(); + sensor::power(false); + } + // Arm the capture once the last touch's finger is off the sensor, as // macOS does; a sensor brought up afresh has no touch to wait out. if !self.sensor_kept.load(Relaxed) { @@ -2687,12 +2704,17 @@ impl SepData { // A retry straight from the capture (no finger in time, partial // contact, a damaged frame) compared nothing and needs no new // bring-up; the touch is simply taken again in the same prompt. - let capture_retry = matches!(outcome, bio::VerifyOutcome::Failed(ENROL_STATUS_RETRY)); + // A sensor that reset under the capture is a retry for the user but + // not a capture retry here: the prompt's match operation ends and the + // sensor is dropped (below), so the next try starts from a bring-up. + let sensor_reset = self.sensor_reset_in_capture.xchg(false, Relaxed); + let capture_retry = + matches!(outcome, bio::VerifyOutcome::Failed(ENROL_STATUS_RETRY)) && !sensor_reset; let touched_at = shim::boottime_ns(); // The touch's frames are taken: stop imaging but keep watching the // finger, as macOS does right after the image cleanup. The next // capture is armed when it is lifted. - if matches!(outcome, bio::VerifyOutcome::Failed(ENROL_STATUS_SENSOR)) { + if matches!(outcome, bio::VerifyOutcome::Failed(ENROL_STATUS_SENSOR)) || sensor_reset { self.forget_finger_lift(); let _ = sensor::idle(); } else { @@ -2938,6 +2960,15 @@ impl SepData { "verify: the sensor fell to state {} during the capture\n", state ); + if state == sensor::STATE_NEEDS_PATCH { + // The sensor reset itself: nothing was compared, and a + // fresh bring-up recovers it. Ask for another touch rather + // than fail the authentication. + dev_info!(self.dev, "verify: the sensor reset under the capture; asking for another touch after a fresh bring-up\n"); + self.sensor_reset_in_capture.store(true, Relaxed); + self.retry_cause(bio::Guidance::Place); + return bio::VerifyOutcome::Failed(ENROL_STATUS_RETRY); + } return bio::VerifyOutcome::Failed(ENROL_STATUS_SENSOR); } CaptureWait::Abandon => { diff --git a/drivers/soc/apple/sep.rs b/drivers/soc/apple/sep.rs index 8541529392c35..7d1655cabfb45 100644 --- a/drivers/soc/apple/sep.rs +++ b/drivers/soc/apple/sep.rs @@ -705,6 +705,11 @@ struct SepData { // anything that powers the sensor off or resets it. sensor_kept: Atomic, + // The kept sensor reset itself under a verify capture (state 9, it asks + // for its patch again). The verify reports a retry, ends the prompt's + // match operation and drops the sensor, so the next try brings it up. + sensor_reset_in_capture: Atomic, + // The enclave announced (SBIO tag 0x03) that a background operation // result is ready; it waits for the host to collect it with 0x21. bg_ops_ready: Atomic, @@ -1077,6 +1082,7 @@ impl SepData { match_context_generation: Atomic::new(0), cold_match_contexts <- new_mutex!(KVec::new()), sensor_kept: Atomic::new(false), + sensor_reset_in_capture: Atomic::new(false), bg_ops_ready: Atomic::new(false), persistence_owed: Atomic::new(false), enrol_identity_candidates <- new_mutex!(KVec::new()),