Skip to content
Draft
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
26 changes: 16 additions & 10 deletions Documentation/ABI/testing/sysfs-driver-apple-sep
Original file line number Diff line number Diff line change
Expand Up @@ -341,26 +341,32 @@ Description:

========== ==========================================
usable xART writes are enabled and no guard runs.
unverified A guard runs with its list loaded on a
warm-attach Mac (boot "warm") and has refused
nothing yet. Whether every record a match
rewrites is on the list is not known until a
unverified A guard runs with its list loaded and has
refused nothing yet, on a warm-attach Mac
(boot "warm") or on a cold-boot Mac (boot
"cold") whose keybag was created under the
guard with xart_guard_pin=1. Whether every
record a match rewrites is on the list, or
is the pinned locker, is not known until a
match is tried.
blocked A match's write is refused or known to be:
xART writes are disabled (xart "disabled"),
the guard has refused a write
(xart_guard_refusals above 0), the guard
has no list (xart_guard_list
"unavailable"), or a guard runs on a
cold-boot Mac (boot "cold"). On a cold-boot
Mac, creating the keybag needs xart_guard=0,
so the records a match rewrites are not on
the list.
cold-boot Mac (boot "cold") whose keybag
was not created under it. Creating the
keybag there needs xart_guard=0, which
leaves the records a match rewrites off the
list, or xart_guard_pin=1.
========== ==========================================

For the guard cases the documented opt-out is xart_guard=0,
which lets the enclave rewrite session records that another
OS on the Mac may have created; see
tools/aurora-sep/XART-SAFETY.md. During a boot the value
can only move from "unverified" to "blocked", once the guard
refuses a write.
moves from "unverified" to "blocked" once the guard refuses
a write. On a cold-boot Mac with xart_guard_pin=1 it also
moves from "blocked" to "unverified" when the first keybag
creation is sent under the guard, and nowhere else.
18 changes: 17 additions & 1 deletion drivers/soc/apple/diag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ extern "C" {
fn sep_diag_set_sensor_attach(state: c_int);
fn sep_diag_set_restore(state: c_int);
fn sep_diag_set_xart_guard(level: c_uint, list_loaded: bool, matching: c_int);
fn sep_diag_set_matching(matching: c_int);
fn sep_diag_xart_guard_refused(matching: c_int);
fn sep_diag_bringup_ended();
}
Expand Down Expand Up @@ -70,12 +71,15 @@ pub(crate) enum Restore {
/// group goes away when the driver unbinds.
///
/// `guard` is the xART guard as the store opened it: its effective level and
/// whether Linux's list loaded, or `None` when no guard runs.
/// whether Linux's list loaded, or `None` when no guard runs. `guarded_setup`
/// is whether that list says this install's first keybag creation was sent
/// under the guard.
pub(crate) fn register(
dev: &device::Device<device::Bound>,
profile: &profile::PlatformProfile,
xart_writable: bool,
guard: Option<(u8, bool)>,
guarded_setup: bool,
) -> Result {
// Exhaustive, so a new bootstrap or key store fails to build here until
// the ABI has a value for it.
Expand All @@ -91,6 +95,7 @@ pub(crate) fn register(
// Probe runs before the guard can refuse anything.
XART_WRITABLE.store(xart_writable, Relaxed);
COLD.store(cold, Relaxed);
GUARDED_SETUP.store(guarded_setup, Relaxed);
let (level, list_loaded) = guard.unwrap_or((0, false));
GUARD_LEVEL.store(u32::from(level), Relaxed);
GUARD_LIST.store(list_loaded, Relaxed);
Expand Down Expand Up @@ -178,6 +183,7 @@ pub(crate) fn restore(state: Restore) {

static XART_WRITABLE: Atomic<bool> = Atomic::new(false);
static COLD: Atomic<bool> = Atomic::new(false);
static GUARDED_SETUP: Atomic<bool> = Atomic::new(false);
static GUARD_LEVEL: Atomic<u32> = Atomic::new(0);
static GUARD_LIST: Atomic<bool> = Atomic::new(false);
static REFUSALS: Atomic<u32> = Atomic::new(0);
Expand All @@ -189,6 +195,7 @@ fn matching() -> crate::xart_guard::Matching {
MatchFacts {
xart_writable: XART_WRITABLE.load(Relaxed),
cold: COLD.load(Relaxed),
guarded_setup: GUARDED_SETUP.load(Relaxed),
guard: (level != 0).then(|| {
(
u8::try_from(level).unwrap_or(u8::MAX),
Expand All @@ -200,6 +207,15 @@ fn matching() -> crate::xart_guard::Matching {
.matching()
}

/// The xART guard opened this install's first-setup window and recorded it in
/// its list, so the keybag creation about to be sent runs under the guard.
pub(crate) fn xart_guard_setup_recorded() {
GUARDED_SETUP.store(true, Relaxed);
// SAFETY: no preconditions; stores one word. The refusals counted since
// probe stand, which `sep_diag_set_xart_guard` would clear.
unsafe { sep_diag_set_matching(matching() as c_int) };
}

/// The xART guard refused one of the enclave's writes or deletes.
pub(crate) fn xart_guard_refused() {
REFUSALS.fetch_add(1, Relaxed);
Expand Down
17 changes: 17 additions & 0 deletions drivers/soc/apple/diag_shim.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,23 @@ void sep_diag_set_xart_guard(unsigned int level, bool list_loaded,
atomic_set(&sep_diag.matching, matching);
}

/*
* After probe, when a fact matching is derived from changes without a
* refusal: the guard recorded this install's first-setup window. The level,
* the list and the refusals counted so far stand.
*
* The caller derived matching before this call, and a refusal may have
* landed since. A refusal always leaves "blocked", so the count is read
* after the store: either this sees the refusal and restores "blocked", or
* the refusal's own store comes later.
*/
void sep_diag_set_matching(int matching)
{
atomic_set(&sep_diag.matching, matching);
if (atomic_read(&sep_diag.xart_refusals))
atomic_set(&sep_diag.matching, SEP_DIAG_MATCHING_BLOCKED);
}

/* With matching as the refusal leaves it. */
void sep_diag_xart_guard_refused(int matching)
{
Expand Down
3 changes: 2 additions & 1 deletion drivers/soc/apple/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ pub(crate) const T6000: PlatformProfile = PlatformProfile {
nonce_session: false,
// As T8103. On J316s, creating the identity keybag also rewrites a
// session record that predates Linux. The guard refuses that, so the
// keybag can only be created there with xart_guard=0.
// keybag can only be created there with xart_guard=0, or under the
// guard with xart_guard_pin=1, which pins that one record.
xart_guard: 1,
};

Expand Down
22 changes: 20 additions & 2 deletions drivers/soc/apple/sep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -849,10 +849,15 @@ impl SepData {
let xart_start = *module_parameters::xart_start_sector.value();
let xart_guard =
xart_guard::level(*module_parameters::xart_guard.value(), profile.xart_guard);
let cold = match profile.bootstrap {
profile::Bootstrap::Boot => true,
profile::Bootstrap::WarmRegister => false,
};
let xart_setup = xart_guard::setup(cold, *module_parameters::xart_guard_pin.value());
let store = match xart_store::Store::open_owner(xart_writes, xart_start) {
Ok(mut store) => {
match xart_guard {
Some(level) if store.writes_enabled() => store.set_guard(level)?,
Some(level) if store.writes_enabled() => store.set_guard(level, xart_setup)?,
None if store.writes_enabled() => dev_info!(
dev,
"xART guard off: the enclave may rewrite any session record\n"
Expand Down Expand Up @@ -2656,7 +2661,16 @@ impl platform::Driver for SepDriver {
// As soon as the fixed facts are known, so a tool can watch the attach
// from "pending" on. Diagnostics are not worth failing the probe for.
let guard = data.with_store(|store| store.guard_state()).flatten();
if let Err(e) = diag::register(dev, data.profile, data.xart_writable(), guard) {
let guarded_setup = data
.with_store(|store| store.guarded_setup())
.unwrap_or(false);
if let Err(e) = diag::register(
dev,
data.profile,
data.xart_writable(),
guard,
guarded_setup,
) {
dev_warn!(dev, "diag: could not add the sysfs attributes ({:?})\n", e);
}

Expand Down Expand Up @@ -2752,6 +2766,10 @@ module! {
default: -1,
description: "-1: the platform's level, 1 on M1, M2 and M3 Macs and 0 on the MacBook Neo; 0: off; 1: refuse the enclave's writes and deletes of xART session records this Linux install did not create; 2: also refuse writes to the shared root records",
},
xart_guard_pin: u8 {
default: 0,
description: "On a Mac that cold-boots its SEP (M1 family) at xart_guard=1: 1 lets the enclave rewrite the one SEP-xART locker from before Linux that this install's first keybag creation rewrites, then and afterwards, while every other record stays guarded; 0: that rewrite is refused",
},
os_uuid_hi: u64 {
default: 0,
description: "High 64 bits of an explicit xART OS UUID",
Expand Down
1 change: 1 addition & 0 deletions drivers/soc/apple/shim.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ void sep_diag_set_sensor_attach(int state);
void sep_diag_set_restore(int state);
void sep_diag_set_xart_guard(unsigned int level, bool list_loaded,
int matching);
void sep_diag_set_matching(int matching);
void sep_diag_xart_guard_refused(int matching);
void sep_diag_bringup_ended(void);

Expand Down
33 changes: 17 additions & 16 deletions drivers/soc/apple/sks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,24 +670,25 @@ impl SepData {
}
};
// A cold-boot Mac's create rewrites a pre-Linux record for its own
// reasons (XART-SAFETY.md), so only warm attach gets the window.
let first_setup = if self.profile.bootstrap == profile::Bootstrap::WarmRegister {
match self.with_store(|store| store.open_first_setup()) {
Some(Ok(open)) => open,
None => false,
// Unsent, so the intent is dropped as retryable.
Some(Err(e)) => {
dev_err!(
self.dev,
"sks: cannot record the xART guard's first-setup window ({:?}); not creating the keybag this boot\n",
e
);
return false;
}
// reasons (XART-SAFETY.md), so the guard gives it a window only under
// xart_guard_pin, and then pins that record.
let first_setup = match self.with_store(|store| store.open_first_setup()) {
Some(Ok(open)) => open,
None => false,
// Unsent, so the intent is dropped as retryable.
Some(Err(e)) => {
dev_err!(
self.dev,
"sks: cannot record the xART guard's first-setup window ({:?}); not creating the keybag this boot\n",
e
);
return false;
}
} else {
false
};
if first_setup {
// The create is sent under the guard: matching follows.
crate::diag::xart_guard_setup_recorded();
}
intent.sending();
let exchanged = self.sks_exchange(request.name, request.msg, &request.img);
if first_setup {
Expand Down
4 changes: 4 additions & 0 deletions drivers/soc/apple/xarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ pub(crate) fn service(
};
}
inbound[..value.len()].copy_from_slice(&value);
// Only a read that hands the enclave the record counts,
// for the lockers the guard lets it rewrite under
// xart_guard_pin.
store.note_enclave_read(&key);
Serviced {
reply: Reply::ok(req, value.len() as u16),
reply_bytes: value.len(),
Expand Down
Loading