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
2 changes: 2 additions & 0 deletions .github/workflows/sep-source.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ jobs:
python3 -O -m unittest tools/aurora-sep/tests/test_store_open_errors.py -v
python3 -m unittest tools/aurora-sep/tests/test_identity_preservation.py -v
python3 -O -m unittest tools/aurora-sep/tests/test_identity_preservation.py -v
- name: Test sensor registration before capture
run: python3 -m unittest tools/aurora-sep/tests/test_verify_bringup.py -v
- name: Test capture wiping on rejected reads
run: |
python3 -I tools/aurora-sep/tests/capture-error-wipe/run.py
Expand Down
76 changes: 60 additions & 16 deletions drivers/soc/apple/registration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ pub(crate) const ATTACH: Retry = Retry {
budget_ms: 10_000,
};

/// Before a verify, which someone is waiting on: three attempts, back to
/// Before an interactive capture: three attempts, back to
/// back.
pub(crate) const VERIFY: Retry = Retry {
pub(crate) const CAPTURE: Retry = Retry {
attempts: 3,
first_pause_ms: 0,
budget_ms: u64::MAX,
Expand Down Expand Up @@ -265,6 +265,10 @@ impl Outcome {
pub(crate) trait Attempts {
/// One bring-up, from a power-cycled sensor.
fn attempt(&mut self) -> bool;
/// Whether this failure can be recovered by a new registration.
fn retryable(&self) -> bool {
true
}
/// Whether the result is still wanted.
fn wanted(&self) -> bool;
/// Milliseconds since the first attempt began.
Expand All @@ -285,6 +289,9 @@ pub(crate) fn bring_up(retry: &Retry, steps: &mut impl Attempts) -> Outcome {
if steps.attempt() {
return Outcome::Online(attempt);
}
if !steps.retryable() {
return Outcome::GaveUp(attempt);
}
let Some(pause) = retry.pause_before(attempt + 1, steps.elapsed_ms()) else {
return Outcome::GaveUp(attempt);
};
Expand Down Expand Up @@ -669,13 +676,13 @@ mod tests {

#[test]
fn verify_attempts_follow_each_other_at_once() {
assert_eq!(VERIFY.pause_before(2, 0), Some(0));
assert_eq!(VERIFY.pause_before(3, u64::MAX - 1), Some(0));
assert_eq!(VERIFY.pause_before(4, 0), None);
assert_eq!(CAPTURE.pause_before(2, 0), Some(0));
assert_eq!(CAPTURE.pause_before(3, u64::MAX - 1), Some(0));
assert_eq!(CAPTURE.pause_before(4, 0), None);

let mut m = Model::new();
m.nonce = [false; 8];
assert_eq!(bring_up(&VERIFY, &mut m), Outcome::GaveUp(3));
assert_eq!(bring_up(&CAPTURE, &mut m), Outcome::GaveUp(3));
assert_eq!(m.paused, 0);
assert_eq!(m.failed, 2);
}
Expand Down Expand Up @@ -732,14 +739,17 @@ mod tests {
stage: u32,
session: bool,
shares: [bool; 8],
clears: usize,
/// Stage at power-on and the SBIO status returned by REGISTER_SERIAL.
serial_replies: [Option<(u32, u16)>; 8],
attempt: usize,
/// The first `fail` attempts fail after the session commit, as at
/// the sequence counter's challenge.
fail: usize,
/// As the J314s did after a failed sequence counter init: the
/// enclave refuses the serial re-registration that follows
/// CLEAR_STATE, and a fresh registration starts a new session.
clear_refused: bool,
/// enclave accepts CLEAR_STATE but refuses the REGISTER_SERIAL
/// that follows it. A fresh registration is accepted.
refuse_serial_after_clear: bool,
/// Whether the system begins to sleep during this attempt, once the
/// serial is registered and before the session share.
suspend_at: Option<usize>,
Expand All @@ -752,9 +762,11 @@ mod tests {
stage: FRESH,
session: false,
shares: [false; 8],
clears: 0,
serial_replies: [None; 8],
attempt: 0,
fail,
clear_refused: false,
refuse_serial_after_clear: false,
suspend_at: None,
suspending: false,
}
Expand All @@ -767,13 +779,19 @@ mod tests {
self.stage = retry_stage(self.stage, false, retry);
}
let clear = plan(self.stage, true, false, true).clear_state;
if clear && self.clear_refused {
// REGISTER_SERIAL after CLEAR_STATE: 0x16.
return false;
}
if clear || (self.clear_refused && self.stage == FRESH) {
if clear {
self.clears += 1;
self.session = false;
}
let status = if clear && self.refuse_serial_after_clear {
crate::sbio::SBIO_STATUS_16
} else {
0
};
self.serial_replies[this] = Some((self.stage, status));
if status != 0 {
return false;
}
self.stage = ESTABLISHED;
if self.suspend_at == Some(this) {
self.suspending = true;
Expand Down Expand Up @@ -837,7 +855,7 @@ mod tests {
// The J314s: after a failed sequence counter init, the CLEAR_STATE
// re-registration is refused for the rest of the boot.
let mut e = SessionEnclave::new(1);
e.clear_refused = true;
e.refuse_serial_after_clear = true;
let mut round = Round {
enclave: &mut e,
retry: 0,
Expand All @@ -849,6 +867,32 @@ mod tests {
assert_eq!(e.stage, ESTABLISHED);
}

#[test]
fn t6000_verify_retries_register_serial_0x16_from_fresh() {
// On J316c an established registration cleared successfully, then
// REGISTER_SERIAL returned 0x16 at 26-33 ms after power-on. Keep
// returning that status on re-registration to exercise the fresh try.
let mut e = SessionEnclave::new(0);
e.stage = ESTABLISHED;
e.session = true;
e.refuse_serial_after_clear = true;
let mut round = Round {
enclave: &mut e,
retry: 0,
};
assert_eq!(bring_up(&CAPTURE, &mut round), Outcome::Online(3));
assert_eq!(e.clears, 2);
assert_eq!(
&e.serial_replies[..3],
&[
Some((ESTABLISHED, 0x16)),
Some((ESTABLISHED, 0x16)),
Some((FRESH, 0)),
]
);
assert_eq!(&e.shares[..3], &[false, false, true]);
}

#[test]
fn a_suspend_mid_attempt_stops_cleanly_and_resume_recovers() {
// The system begins to sleep after the first attempt registered the
Expand Down
Loading
Loading