Skip to content
Open
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
30 changes: 21 additions & 9 deletions drivers/soc/apple/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,27 @@ config APPLE_SEP
the iBoot system container, locating its .gl extent through read-only,
checksum-validated APFS metadata. It validates the complete store and
both root records before registering with SEP.
xART writes are enabled by default, but accepted only when the driver
validates the physical extent ownership invariants. Unsupported APFS
layouts fail closed. A Linux identity keybag is created automatically
when none exists; existing identities and reference keys are retained.
Set xart_writes=0 provision_keybag=0 for read-only operation.
With writes off the driver still attaches, but refuses Touch ID enrol
and verify: the enclave saves anti-replay state after every match.

Say Y here if you have an Apple silicon Mac.
The driver loads on its own (udev) and boots the enclave where the
device tree already enables the SEP node (M1 family and J700). On
the M1 laptops the Secure Enclave sits in the path of the microphone
data lines, so those microphones depend on it. The M2, M2 Pro/Max
and M3 Air nodes stay disabled and are enabled by module init, so
those machines still need the loader. If the iBoot system
container is not reachable yet, the boot waits up to 30 s for it,
then runs without the store. Read-only operation is the default:
set xart_writes=1 provision_keybag=1 (for instance in a modprobe.d
file installed by the Touch ID setup) to allow writes, accepted only
when the driver validates the physical extent ownership invariants.
Unsupported APFS layouts fail closed. With writes off the driver
still attaches, but refuses Touch ID enrol and verify: the enclave
saves anti-replay state after every match. A default load still
creates /var/lib/aurora-sep-host-state.bin (2359296 bytes) the
first time it opens that Linux-only store. That is not an xART write.

Say M here if you have an Apple silicon Mac. Built in, the
modprobe.d options never reach the driver, so Touch ID setup can
only pass xart_writes and provision_keybag on the kernel command
line. M is the default on Apple silicon.

config APPLE_SEP_KUNIT_TEST
bool "KUnit tests for the Apple SEP driver" if !KUNIT_ALL_TESTS
Expand Down
17 changes: 17 additions & 0 deletions drivers/soc/apple/diag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ extern "C" {
fn sep_diag_set_touchid(started: bool);
fn sep_diag_set_sensor_attach(state: c_int);
fn sep_diag_set_restore(state: c_int);
fn sep_diag_set_xart(xart: bool);
fn sep_diag_set_xart_guard(level: c_uint, list_loaded: bool, matching: c_int);
fn sep_diag_xart_guard_refused(matching: c_int);
fn sep_diag_bringup_ended();
Expand Down Expand Up @@ -115,6 +116,22 @@ pub(crate) fn register(
kernel::error::to_result(ret)
}

/// The xART store opened after probe. Updates the cached facts. Does not
/// register the sysfs group again.
pub(crate) fn refresh_store(xart_writable: bool, guard: Option<(u8, bool)>) {
XART_WRITABLE.store(xart_writable, Relaxed);
let (level, list_loaded) = guard.unwrap_or((0, false));
GUARD_LEVEL.store(u32::from(level), Relaxed);
GUARD_LIST.store(list_loaded, Relaxed);
REFUSALS.store(0, Relaxed);
// SAFETY: stores the words the diag attributes read. The group already
// exists; this does not add it.
unsafe {
sep_diag_set_xart(xart_writable);
sep_diag_set_xart_guard(c_uint::from(level), list_loaded, matching() as c_int);
}
}

pub(crate) fn attach(attached: bool) {
// SAFETY: no preconditions; stores one word.
unsafe { sep_diag_set_attach(attached) };
Expand Down
6 changes: 6 additions & 0 deletions drivers/soc/apple/diag_shim.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,12 @@ int sep_diag_register(struct device *dev, const char *profile,
return devm_device_add_group(dev, &sep_diag_group);
}

/* A store that opens after probe. Does not add the sysfs group again. */
void sep_diag_set_xart(bool xart)
{
sep_diag.xart = xart;
}

void sep_diag_set_attach(bool attached)
{
atomic_set(&sep_diag.attach,
Expand Down
47 changes: 45 additions & 2 deletions drivers/soc/apple/keybag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,51 @@ pub(crate) fn write_intent(slot: Slot) -> Result<()> {
write_record(slot, 0, &[], &[0; UUID_LEN], &[])
}

pub(crate) fn mark_refused(slot: Slot) -> Result<()> {
write_record(slot, STATE_REFUSED, &[], &[0; UUID_LEN], &[])
/// Removes a header-only intent or refused record. A committed bag, or any
/// file that is not exactly that 52-byte header, is left in place: unlinking
/// it would hide a bag the enclave may still hold.
pub(crate) fn discard_uncommitted(slot: Slot) -> Result<()> {
let file = match shim::StoreFile::open_readonly(slot.path()) {
Ok(file) => file,
Err(e) if e == ENOENT => return Ok(()),
Err(e) => return Err(e),
};
let size = file.size()?;
if size != HEADER as u64 {
return Err(EEXIST);
}
let mut head = [0u8; HEADER];
file.read_exact(0, &mut head)?;
if head[..MAGIC.len()] != MAGIC {
return Err(EINVAL);
}
let state = u32::from_le_bytes([
head[OFF_STATE],
head[OFF_STATE + 1],
head[OFF_STATE + 2],
head[OFF_STATE + 3],
]);
let len = u32::from_le_bytes([
head[OFF_LEN],
head[OFF_LEN + 1],
head[OFF_LEN + 2],
head[OFF_LEN + 3],
]);
let secret_len = u32::from_le_bytes([
head[OFF_SECRET_LEN],
head[OFF_SECRET_LEN + 1],
head[OFF_SECRET_LEN + 2],
head[OFF_SECRET_LEN + 3],
]);
if (state != 0 && state != STATE_REFUSED) || len != 0 || secret_len != 0 {
return Err(EEXIST);
}
drop(file);
match shim::unlink(slot.path()) {
Ok(()) => Ok(()),
Err(e) if e == ENOENT => Ok(()),
Err(e) => Err(e),
}
}

pub(crate) fn write_bag_uuid(
Expand Down
Loading