Skip to content
Closed
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
7 changes: 7 additions & 0 deletions drivers/soc/apple/profile.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// SPDX-License-Identifier: GPL-2.0-only OR MIT
// Copyright 2026 Dj
// Copyright 2026 Ryan Murray
Expand Down Expand Up @@ -154,6 +154,8 @@

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,
Expand Down Expand Up @@ -187,6 +189,7 @@

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,
Expand Down Expand Up @@ -229,6 +232,7 @@
/// 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,
Expand Down Expand Up @@ -266,6 +270,7 @@

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,
Expand Down Expand Up @@ -322,6 +327,7 @@
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,
Expand Down Expand Up @@ -365,6 +371,7 @@
/// 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,
Expand Down
49 changes: 43 additions & 6 deletions drivers/soc/apple/sbio.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// SPDX-License-Identifier: GPL-2.0-only OR MIT
// Copyright 2026 Dj
// Copyright 2026 Ryan Murray
Expand Down Expand Up @@ -1796,13 +1796,50 @@
bio::VerifyOutcome::Matched(bio::MatchEvidence::from_enclave_reply(identity))
}

pub(crate) fn run_enrolment(&self) {
self.enrol_frames_accepted.store(0, Relaxed);
fn power_down_enrol_sensor(&self) {
let _ = sensor::idle();
sensor::power(false);
self.note_capture_end();
}

if !self.bring_sensor_online() {
/// 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,
&registration::VERIFY,
wanted,
)
.online()
} else {
self.bring_sensor_online()
};
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)) {
return;
}

Expand Down Expand Up @@ -1921,9 +1958,7 @@
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) {
Expand Down Expand Up @@ -3899,6 +3934,8 @@
/// 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.
Expand Down
91 changes: 91 additions & 0 deletions tools/aurora-sep/tests/test_enrol_bringup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# 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, '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)


HARNESS = r"""
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<Vec<&'static str>> = 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<u32>, 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<W: Fn() -> 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 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);
count.get() == self.ready_after
}
fn bring_sensor_online_retrying(&self, _: &CStr, _: Bringup, policy: &registration::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, 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(), EVENTS.with(|e| e.take()))
}
fn main() {
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
}
"""
Loading