From 4ad5bfb0cdf43f62a31310a54999746a07044db3 Mon Sep 17 00:00:00 2001 From: Adrian Rangel Date: Thu, 26 Nov 2026 00:32:01 -0600 Subject: [PATCH 1/2] soc: apple: sep: Retry T6000 registration before enrolment The J316c M1 Max can time out reading the sensor serial before its first scan. Retry registration while the original enrolment is live, before creating any enclave enrolment. Preserve the single startup attempt on other profiles. Signed-off-by: Adrian Rangel --- drivers/soc/apple/profile.rs | 7 ++ drivers/soc/apple/sbio.rs | 29 +++++++- tools/aurora-sep/tests/test_enrol_bringup.py | 78 ++++++++++++++++++++ 3 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 tools/aurora-sep/tests/test_enrol_bringup.py diff --git a/drivers/soc/apple/profile.rs b/drivers/soc/apple/profile.rs index 6803c1464652e0..46e61fa0a62fc9 100644 --- a/drivers/soc/apple/profile.rs +++ b/drivers/soc/apple/profile.rs @@ -154,6 +154,8 @@ const DART_T8112: DartWindow = DartWindow { pub(crate) struct PlatformProfile { pub(crate) name: &'static str, + /// Retry sensor registration before opening an enrolment on the enclave. + pub(crate) retry_enrol_registration: bool, /// Capacity of the boot shared-memory window. The layout is still checked /// against the manifests; this only bounds the allocation. pub(crate) shmem_capacity: usize, @@ -187,6 +189,7 @@ pub(crate) struct PlatformProfile { pub(crate) const T8103: PlatformProfile = PlatformProfile { name: "T8103/J313", + retry_enrol_registration: false, shmem_capacity: 0x3_0000, shmem_first_item: b"CNIP", bootstrap: Bootstrap::Boot, @@ -229,6 +232,7 @@ pub(crate) const T8103: PlatformProfile = PlatformProfile { /// identically. Enrolment persistence is reboot-tested on J314s. pub(crate) const T6000: PlatformProfile = PlatformProfile { name: "T6000/J316s", + retry_enrol_registration: true, shmem_capacity: 0x3_0000, shmem_first_item: b"CNIP", bootstrap: Bootstrap::Boot, @@ -266,6 +270,7 @@ pub(crate) const T6000: PlatformProfile = PlatformProfile { pub(crate) const T6020: PlatformProfile = PlatformProfile { name: "T6020/J414s", + retry_enrol_registration: false, shmem_capacity: 0x4_0000, shmem_first_item: b"CINP", bootstrap: Bootstrap::WarmRegister, @@ -322,6 +327,7 @@ pub(crate) const T8140: PlatformProfile = PlatformProfile { key_store: KeyStore::Variant5, persistent_enrol: true, name: "T8140/J700", + retry_enrol_registration: false, shmem_capacity: 0x4_0000, shmem_first_item: b"CINP", bootstrap: Bootstrap::WarmRegister, @@ -365,6 +371,7 @@ pub(crate) const T8140: PlatformProfile = PlatformProfile { /// warm-registration platforms (T6020 on current firmware, T8140). pub(crate) const T8112: PlatformProfile = PlatformProfile { name: "T8112/J415", + retry_enrol_registration: false, shmem_capacity: 0x4_0000, shmem_first_item: b"CINP", bootstrap: Bootstrap::WarmRegister, diff --git a/drivers/soc/apple/sbio.rs b/drivers/soc/apple/sbio.rs index 9c69ca184c6912..0a03c6a47424be 100644 --- a/drivers/soc/apple/sbio.rs +++ b/drivers/soc/apple/sbio.rs @@ -1796,10 +1796,35 @@ impl SepData { bio::VerifyOutcome::Matched(bio::MatchEvidence::from_enclave_reply(identity)) } + /// A T6000/T6001 can time out reading the sensor serial before the + /// first scan. Retry only bring-up, before opening an enclave enrolment. + fn bring_sensor_online_for_enrol(&self, epoch: u64) -> bool { + let wanted = || { + !self.shutting_down.load(Relaxed) + && !self.suspending.load(Relaxed) + && bio::enrol_is_live(&self.bio_session.lock(), epoch) + }; + if !wanted() { + return false; + } + let online = if self.profile.retry_enrol_registration { + self.bring_sensor_online_retrying( + c"enrol", + Bringup::Enrol, + ®istration::VERIFY, + wanted, + ) + .online() + } else { + self.bring_sensor_online() + }; + online && wanted() + } + pub(crate) fn run_enrolment(&self) { self.enrol_frames_accepted.store(0, Relaxed); - if !self.bring_sensor_online() { + if !self.bring_sensor_online_for_enrol(self.capture_epoch.load(Relaxed)) { dev_err!(self.dev, "enrol: the sensor did not come back online\n"); self.finish_enrolment(Err(ENROL_STATUS_SENSOR)); let _ = sensor::idle(); @@ -3899,6 +3924,8 @@ impl SepData { /// Which bring-up a round of attempts makes. #[derive(Clone, Copy, PartialEq, Eq)] enum Bringup { + /// Before an enrolment. + Enrol, /// As Touch ID is activated. Attach, /// The late round after an attach that fell short. diff --git a/tools/aurora-sep/tests/test_enrol_bringup.py b/tools/aurora-sep/tests/test_enrol_bringup.py new file mode 100644 index 00000000000000..a353fb01bc91a8 --- /dev/null +++ b/tools/aurora-sep/tests/test_enrol_bringup.py @@ -0,0 +1,78 @@ +# SPDX-License-Identifier: MIT +"""Run the driver's pre-enrolment bring-up against a scripted sensor.""" +from pathlib import Path +import subprocess +import tempfile +import unittest + +from test_verify_bringup import APPLE, method, registration_module + + +class EnrolBringupTest(unittest.TestCase): + def test_registration_before_opening_an_enrolment(self): + source = (APPLE / 'sbio.rs').read_text() + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + (root / 'test.rs').write_text( + registration_module() + HARNESS + method(source, 'bring_sensor_online_for_enrol') + CASES) + subprocess.run(['rustc', '--edition=2021', str(root / 'test.rs'), '-o', str(root / 'test')], check=True) + subprocess.run([str(root / 'test')], check=True) + + +HARNESS = r""" +use std::cell::Cell; +use std::ffi::CStr; +use std::sync::atomic::{AtomicBool, Ordering::Relaxed}; +struct Profile { retry_enrol_registration: bool } +enum Bringup { Enrol } +struct Session { epoch: u64, attempts: Cell, cancel_after: u32 } +impl Session { fn lock(&self) -> &Self { self } } +mod bio { + pub fn enrol_is_live(s: &super::Session, epoch: u64) -> bool { + s.epoch == epoch && s.attempts.get() < s.cancel_after + } +} +struct Sensor { + profile: Profile, bio_session: Session, shutting_down: AtomicBool, + suspending: AtomicBool, ready_after: u32, +} +struct Round<'a, W>(&'a Sensor, W); +impl bool> registration::Attempts for Round<'_, W> { + fn attempt(&mut self) -> bool { self.0.bring_sensor_online() } + fn wanted(&self) -> bool { (self.1)() } + fn elapsed_ms(&self) -> u64 { 0 } + fn failed(&mut self, _: u32, _: u32, _: u32) {} + fn pause(&mut self, _: u32) -> bool { true } +} +impl Sensor { + fn bring_sensor_online(&self) -> bool { + let count = &self.bio_session.attempts; + count.set(count.get() + 1); + count.get() == self.ready_after + } + fn bring_sensor_online_retrying(&self, _: &CStr, _: Bringup, policy: ®istration::Retry, + wanted: impl Fn() -> bool) -> registration::Outcome { + registration::bring_up(policy, &mut Round(self, wanted)) + } +""" + +CASES = r""" +} +fn run(retry: bool, ready_after: u32, cancel_after: u32, epoch: u64) -> (bool, u32) { + let sensor = Sensor { + profile: Profile { retry_enrol_registration: retry }, + bio_session: Session { epoch: 10, attempts: Cell::new(0), cancel_after }, + suspending: false.into(), shutting_down: false.into(), ready_after, + }; + (sensor.bring_sensor_online_for_enrol(epoch), sensor.bio_session.attempts.get()) +} +fn main() { + assert_eq!(run(true, 1, 99, 10), (true, 1)); + assert_eq!(run(true, 3, 99, 10), (true, 3)); + assert_eq!(run(true, 4, 99, 10), (false, 3)); + assert_eq!(run(false, 2, 99, 10), (false, 1)); + assert_eq!(run(true, 2, 1, 10), (false, 1)); + assert_eq!(run(true, 1, 1, 10), (false, 1)); // cancelled during a successful attempt + assert_eq!(run(true, 1, 99, 9), (false, 0)); // obsolete worker +} +""" From 53867b7f15faea4aa9e75ac36c0136c2d47250c2 Mon Sep 17 00:00:00 2001 From: Adrian Rangel Date: Thu, 26 Nov 2026 00:47:36 -0600 Subject: [PATCH 2/2] soc: apple: sep: Power down after cancelled enrolment bring-up Signed-off-by: Adrian Rangel --- drivers/soc/apple/sbio.rs | 24 +++++++++----- tools/aurora-sep/tests/test_enrol_bringup.py | 33 ++++++++++++++------ 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/drivers/soc/apple/sbio.rs b/drivers/soc/apple/sbio.rs index 0a03c6a47424be..1821c360c69535 100644 --- a/drivers/soc/apple/sbio.rs +++ b/drivers/soc/apple/sbio.rs @@ -1796,6 +1796,12 @@ impl SepData { bio::VerifyOutcome::Matched(bio::MatchEvidence::from_enclave_reply(identity)) } + fn power_down_enrol_sensor(&self) { + let _ = sensor::idle(); + sensor::power(false); + self.note_capture_end(); + } + /// A T6000/T6001 can time out reading the sensor serial before the /// first scan. Retry only bring-up, before opening an enclave enrolment. fn bring_sensor_online_for_enrol(&self, epoch: u64) -> bool { @@ -1818,16 +1824,22 @@ impl SepData { } else { self.bring_sensor_online() }; - online && wanted() + if !wanted() { + self.power_down_enrol_sensor(); + return false; + } + if !online { + dev_err!(self.dev, "enrol: the sensor did not come back online\n"); + self.finish_enrolment(Err(ENROL_STATUS_SENSOR)); + let _ = sensor::idle(); + } + online } pub(crate) fn run_enrolment(&self) { self.enrol_frames_accepted.store(0, Relaxed); if !self.bring_sensor_online_for_enrol(self.capture_epoch.load(Relaxed)) { - dev_err!(self.dev, "enrol: the sensor did not come back online\n"); - self.finish_enrolment(Err(ENROL_STATUS_SENSOR)); - let _ = sensor::idle(); return; } @@ -1946,9 +1958,7 @@ impl SepData { self.reconcile_identities(); } - let _ = sensor::idle(); - sensor::power(false); - self.note_capture_end(); + self.power_down_enrol_sensor(); if let Some(result) = outcome { let filed = match (result, identity, enrolment_persisted) { diff --git a/tools/aurora-sep/tests/test_enrol_bringup.py b/tools/aurora-sep/tests/test_enrol_bringup.py index a353fb01bc91a8..ee48011ad8cd2d 100644 --- a/tools/aurora-sep/tests/test_enrol_bringup.py +++ b/tools/aurora-sep/tests/test_enrol_bringup.py @@ -14,7 +14,8 @@ def test_registration_before_opening_an_enrolment(self): with tempfile.TemporaryDirectory() as directory: root = Path(directory) (root / 'test.rs').write_text( - registration_module() + HARNESS + method(source, 'bring_sensor_online_for_enrol') + CASES) + registration_module() + HARNESS + method(source, 'power_down_enrol_sensor') + + method(source, 'bring_sensor_online_for_enrol') + CASES) subprocess.run(['rustc', '--edition=2021', str(root / 'test.rs'), '-o', str(root / 'test')], check=True) subprocess.run([str(root / 'test')], check=True) @@ -23,6 +24,14 @@ def test_registration_before_opening_an_enrolment(self): use std::cell::Cell; use std::ffi::CStr; use std::sync::atomic::{AtomicBool, Ordering::Relaxed}; +macro_rules! dev_err { ($($args:tt)*) => {} } +const ENROL_STATUS_SENSOR: u32 = 1; +thread_local! { static EVENTS: std::cell::RefCell> = Default::default(); } +fn event(name: &'static str) { EVENTS.with(|events| events.borrow_mut().push(name)); } +mod sensor { + pub fn idle() -> bool { super::event("idle"); true } + pub fn power(on: bool) { assert!(!on); super::event("off"); } +} struct Profile { retry_enrol_registration: bool } enum Bringup { Enrol } struct Session { epoch: u64, attempts: Cell, cancel_after: u32 } @@ -45,6 +54,10 @@ def test_registration_before_opening_an_enrolment(self): fn pause(&mut self, _: u32) -> bool { true } } impl Sensor { + fn note_capture_end(&self) { event("settle"); } + fn finish_enrolment(&self, result: Result<(), u32>) { + assert_eq!(result, Err(ENROL_STATUS_SENSOR)); event("fault"); + } fn bring_sensor_online(&self) -> bool { let count = &self.bio_session.attempts; count.set(count.get() + 1); @@ -58,21 +71,21 @@ def test_registration_before_opening_an_enrolment(self): CASES = r""" } -fn run(retry: bool, ready_after: u32, cancel_after: u32, epoch: u64) -> (bool, u32) { +fn run(retry: bool, ready_after: u32, cancel_after: u32, epoch: u64) -> (bool, u32, Vec<&'static str>) { let sensor = Sensor { profile: Profile { retry_enrol_registration: retry }, bio_session: Session { epoch: 10, attempts: Cell::new(0), cancel_after }, suspending: false.into(), shutting_down: false.into(), ready_after, }; - (sensor.bring_sensor_online_for_enrol(epoch), sensor.bio_session.attempts.get()) + (sensor.bring_sensor_online_for_enrol(epoch), sensor.bio_session.attempts.get(), EVENTS.with(|e| e.take())) } fn main() { - assert_eq!(run(true, 1, 99, 10), (true, 1)); - assert_eq!(run(true, 3, 99, 10), (true, 3)); - assert_eq!(run(true, 4, 99, 10), (false, 3)); - assert_eq!(run(false, 2, 99, 10), (false, 1)); - assert_eq!(run(true, 2, 1, 10), (false, 1)); - assert_eq!(run(true, 1, 1, 10), (false, 1)); // cancelled during a successful attempt - assert_eq!(run(true, 1, 99, 9), (false, 0)); // obsolete worker + assert_eq!(run(true, 1, 99, 10), (true, 1, vec![])); + assert_eq!(run(true, 3, 99, 10), (true, 3, vec![])); + assert_eq!(run(true, 4, 99, 10), (false, 3, vec!["fault", "idle"])); + assert_eq!(run(false, 2, 99, 10), (false, 1, vec!["fault", "idle"])); + assert_eq!(run(true, 2, 1, 10), (false, 1, vec!["idle", "off", "settle"])); + assert_eq!(run(true, 1, 1, 10), (false, 1, vec!["idle", "off", "settle"])); // cancelled during a successful attempt + assert_eq!(run(true, 1, 99, 9), (false, 0, vec![])); // obsolete worker } """