Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions drivers/soc/apple/sbio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 => {
Expand Down
6 changes: 6 additions & 0 deletions drivers/soc/apple/sep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,11 @@ struct SepData {
// anything that powers the sensor off or resets it.
sensor_kept: Atomic<bool>,

// 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<bool>,

// 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<bool>,
Expand Down Expand Up @@ -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()),
Expand Down
Loading