From 25c9f0d3836e0e83450f753a0c9a111e746af61c Mon Sep 17 00:00:00 2001 From: Lucas Goossen Date: Wed, 21 Oct 2026 21:47:33 -0300 Subject: [PATCH 01/15] soc: apple: sep: boot the SEP even when the xART store is unavailable The driver refused to probe when the xART gigalocker could not be opened from the iBoot system container, so the SEP was never booted. On the M1 and M2 laptops the Secure Enclave sits in the path of the microphone data lines: without the boot, the AOP's PDM capture runs on a constant input and every recording is a null stream (omacom/linux-aurora#141). This is what broke the built-in microphones between 7.1.12.aurora2-12 (CONFIG_APPLE_SEP=y with the earlier stub driver, which only booted the enclave) and every later build: the rewritten driver either failed its probe at the xART store before udev had created the partition-label link (CONFIG_APPLE_SEP=y, 7.1.12.aurora8-1), or was a module that is never loaded without the Touch ID loader units (7.2.10.aurora1-2). Treat an unavailable or invalid store like xart_writes=0 taken one step further: warn, keep `store` empty and boot the enclave anyway. The xARM path already answers the enclave's requests with a failure when there is no store, so Touch ID and trusted keys stay unavailable until a boot where the store opens; nothing is written. Verified on a MacBook Air (M1, 2020) J313 / t8103, macOS 13.5 firmware, on 7.1.12.aurora2-12.6: with the driver loaded by hand after boot the microphones record live audio; with no SEP driver running the capture is the null stream. Co-Authored-By: Claude Fable 5.1 --- drivers/soc/apple/sep.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/soc/apple/sep.rs b/drivers/soc/apple/sep.rs index 87b90a7d986ee6..f52f9602bd589b 100644 --- a/drivers/soc/apple/sep.rs +++ b/drivers/soc/apple/sep.rs @@ -877,12 +877,17 @@ impl SepData { Some(store) } Err(e) => { - dev_err!( + // The enclave must still be booted: on the M1 and M2 laptops + // the Secure Enclave sits in the path of the microphone data + // lines, and the microphones only work once it runs. Without + // the store the enclave's xART requests are refused (see + // `on_xarm`), so Touch ID and trusted keys stay unavailable. + dev_warn!( dev, - "xART gigalocker in the iBoot container is unavailable or invalid: {:?}\n", + "xART gigalocker in the iBoot container is unavailable or invalid ({:?}); booting the SEP without it: Touch ID and trusted keys stay unavailable until the next boot\n", e ); - return Err(e); + None } }; From 1ba60be4bd59e2cfee52564d37739d5cab78f071 Mon Sep 17 00:00:00 2001 From: Lucas Goossen Date: Wed, 21 Oct 2026 21:49:35 -0300 Subject: [PATCH 02/15] soc: apple: sep: autoload the driver and wait for the iBoot container The built-in microphones of the M1 and M2 laptops depend on a booted Secure Enclave, so the SEP driver has to run on every such Mac, not only where the Touch ID loader units are installed. Export the OF table as a module alias again, so udev loads the driver on every board whose device tree enables the SEP, and resolve the two problems that made commit 36ebdeec504b ("soc: apple: sep: Do not autoload the driver through a module alias") remove the alias: - A udev load runs before udev has created the iBoot system container's partition-label link, through which the xART store is opened, and nothing retried the open. Now a cold boot whose store open fails with ENODEV waits for the link in 500 ms steps, up to 30 s, opens the store once it exists and boots the enclave then; after the last step it boots without the store. The boot never waits forever: the microphones depend on it. - A load the owner did not ask for provisioned an identity keybag and wrote to the shared xART store. xart_writes and provision_keybag now default to 0: read-only operation boots the enclave and refuses Touch ID enrol and verify, as before. The aurora-touchid package, installed when the owner opts in, carries a modprobe.d file that enables both; a --read-only install overrides it from /etc/modprobe.d. Its apple-sep.service and .path stay harmless (modprobe of a loaded module). The diag sysfs group keeps the xART facts seen at probe; when the store is opened later its "writable" value stays at probe's. Verified on a MacBook Air (M1, 2020) J313 / t8103: the driver autoloads at boot, the TZ0 handshake completes, the store opens with writes disabled, and the microphones record live audio. Co-Authored-By: Claude Fable 5.1 --- drivers/soc/apple/Kconfig | 18 +- drivers/soc/apple/sep.rs | 184 ++++++++++++++---- tools/aurora-sep/README.md | 25 ++- tools/aurora-sep/aurora-touchid/PKGBUILD | 5 +- .../aurora-sep/aurora-touchid/apple-sep.conf | 5 + 5 files changed, 182 insertions(+), 55 deletions(-) create mode 100644 tools/aurora-sep/aurora-touchid/apple-sep.conf diff --git a/drivers/soc/apple/Kconfig b/drivers/soc/apple/Kconfig index ba57db91f8860b..7146af32265b3f 100644 --- a/drivers/soc/apple/Kconfig +++ b/drivers/soc/apple/Kconfig @@ -155,13 +155,17 @@ 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. + The driver loads on its own (udev) and boots the enclave; on the M1 + and M2 laptops the Secure Enclave sits in the path of the microphone + data lines, so the microphones depend on it. 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. Say Y here if you have an Apple silicon Mac. diff --git a/drivers/soc/apple/sep.rs b/drivers/soc/apple/sep.rs index f52f9602bd589b..98a1af0433dcc0 100644 --- a/drivers/soc/apple/sep.rs +++ b/drivers/soc/apple/sep.rs @@ -101,6 +101,16 @@ static_assert!(VERIFY_WORK_ID != 0); const LATE_ATTACH_WORK_ID: u64 = 4; static_assert!(LATE_ATTACH_WORK_ID != VERIFY_WORK_ID && LATE_ATTACH_WORK_ID != ENROL_WORK_ID); static_assert!(LATE_ATTACH_WORK_ID != SETTLE_WORK_ID && LATE_ATTACH_WORK_ID != 0); +const STORE_WAIT_WORK_ID: u64 = 5; +static_assert!(STORE_WAIT_WORK_ID != SETTLE_WORK_ID && STORE_WAIT_WORK_ID != ENROL_WORK_ID); +static_assert!(STORE_WAIT_WORK_ID != VERIFY_WORK_ID && STORE_WAIT_WORK_ID != LATE_ATTACH_WORK_ID); + +// A udev load runs before udev has created the iBoot system container's +// partition-label link, which the xART store is opened through. A cold boot +// waits for the link in steps of this length, at most this many steps, so the +// enclave's first xART requests find the store; then it boots without it. +const STORE_WAIT_STEP_MS: time::Msecs = 500; +const STORE_WAIT_STEPS: u32 = 60; // When an attach-time sensor bring-up falls short, one more round runs this // long after Touch ID was activated. A round that cannot run yet, because the @@ -690,6 +700,11 @@ struct SepData { late_attach_wanted: Atomic, late_attach_defers: Atomic, + // The iBoot system container's link did not exist at probe; the cold boot + // waits for it (see `store_wait_tick`). And how many steps it has waited. + store_pending: Atomic, + store_wait_steps: Atomic, + #[pin] ool_sks: Mutex>, @@ -793,6 +808,9 @@ struct SepData { #[pin] late_attach_work: DelayedWork, + + #[pin] + store_wait_work: DelayedWork, } impl_has_work! { @@ -804,6 +822,7 @@ impl_has_work! { impl_has_delayed_work! { impl HasDelayedWork for SepData { self.settle_work } impl HasDelayedWork for SepData { self.late_attach_work } + impl HasDelayedWork for SepData { self.store_wait_work } } // SAFETY: every field is either internally synchronised (the mutexes, the @@ -815,6 +834,44 @@ unsafe impl Send for SepData {} unsafe impl Sync for SepData {} impl SepData { + /// Opens the shared xART store from the iBoot system container, with the + /// module parameters and the platform's guard applied, and logs its + /// summary. `ENODEV` means the container's device link does not exist. + fn open_xart_store( + dev: &device::Device, + profile: &profile::PlatformProfile, + ) -> Result { + let xart_writes = *module_parameters::xart_writes.value() != 0; + let xart_start = *module_parameters::xart_start_sector.value(); + let xart_guard = + xart_guard::level(*module_parameters::xart_guard.value(), profile.xart_guard); + let mut store = xart_store::Store::open_owner(xart_writes, xart_start)?; + match xart_guard { + Some(level) if store.writes_enabled() => store.set_guard(level)?, + None if store.writes_enabled() => dev_info!( + dev, + "xART guard off: the enclave may rewrite any session record\n" + ), + _ => {} + } + let (slots, records, revision, malformed, duplicates, repaired, writable) = + store.summary(); + let base = store.base(); + dev_info!( + dev, + "xART: APFS-resolved .gl extent (base {:#x}); {} slots, {} live records, max revision {}, {} malformed, {} duplicate, {} repaired; writes {}\n", + base, + slots, + records, + revision, + malformed, + duplicates, + repaired, + if writable { "ENABLED" } else { "disabled" } + ); + Ok(store) + } + fn new(pdev: &platform::Device>) -> Result> { let profile = profile::detect()?; let built = shmem::build(pdev, profile.shmem_capacity, profile.shmem_first_item)?; @@ -845,36 +902,14 @@ impl SepData { )?; let dma_ring = dma::Coherent::::zeroed_slice(dev, DMA_RING_SIZE, GFP_KERNEL)?; - let xart_writes = *module_parameters::xart_writes.value() != 0; - let xart_start = *module_parameters::xart_start_sector.value(); - let xart_guard = - xart_guard::level(*module_parameters::xart_guard.value(), profile.xart_guard); - 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)?, - None if store.writes_enabled() => dev_info!( - dev, - "xART guard off: the enclave may rewrite any session record\n" - ), - _ => {} - } - let (slots, records, revision, malformed, duplicates, repaired, writable) = - store.summary(); - let base = store.base(); + let (store, store_pending) = match Self::open_xart_store(dev, profile) { + Ok(store) => (Some(store), false), + Err(e) if e == ENODEV => { dev_info!( dev, - "xART: APFS-resolved .gl extent (base {:#x}); {} slots, {} live records, max revision {}, {} malformed, {} duplicate, {} repaired; writes {}\n", - base, - slots, - records, - revision, - malformed, - duplicates, - repaired, - if writable { "ENABLED" } else { "disabled" } + "xART: the iBoot system container is not available yet; waiting for it before booting the SEP\n" ); - Some(store) + (None, true) } Err(e) => { // The enclave must still be booted: on the M1 and M2 laptops @@ -887,7 +922,7 @@ impl SepData { "xART gigalocker in the iBoot container is unavailable or invalid ({:?}); booting the SEP without it: Touch ID and trusted keys stay unavailable until the next boot\n", e ); - None + (None, false) } }; @@ -926,6 +961,8 @@ impl SepData { sensor_test_fault_done: Atomic::new(false), late_attach_wanted: Atomic::new(false), late_attach_defers: Atomic::new(0), + store_pending: Atomic::new(store_pending), + store_wait_steps: Atomic::new(0), keybag_designated: Atomic::new(false), bringup_started: Atomic::new(false), touchid_started: Atomic::new(false), @@ -988,6 +1025,7 @@ impl SepData { verify_work <- new_work!("SepData::verify_work"), settle_work <- new_delayed_work!("SepData::settle_work"), late_attach_work <- new_delayed_work!("SepData::late_attach_work"), + store_wait_work <- new_delayed_work!("SepData::store_wait_work"), }), GFP_KERNEL, ) @@ -2132,6 +2170,49 @@ impl SepData { .enqueue_delayed::, SETTLE_WORK_ID>(this.clone(), delay); } + /// Waits one step for the iBoot system container; see `store_wait_tick`. + fn arm_store_wait(this: &Arc) { + if this.shutting_down.load(Relaxed) { + return; + } + let delay = time::msecs_to_jiffies(STORE_WAIT_STEP_MS); + let _ = workqueue::system_dfl() + .enqueue_delayed::, STORE_WAIT_WORK_ID>(this.clone(), delay); + } + + /// One step of the wait for the container: opens the store once its link + /// exists, or gives up after the last step, and boots the enclave either + /// way. The boot must not wait for the store forever: the microphones of + /// the M1 and M2 laptops depend on it. + fn store_wait_tick(this: &Arc) { + if this.shutting_down.load(Relaxed) { + return; + } + let steps = this.store_wait_steps.load(Relaxed) + 1; + this.store_wait_steps.store(steps, Relaxed); + match Self::open_xart_store(&this.dev, this.profile) { + Ok(store) => *this.store.lock() = Some(store), + Err(e) if e == ENODEV && steps < STORE_WAIT_STEPS => { + return Self::arm_store_wait(this); + } + Err(e) => dev_warn!( + this.dev, + "xART gigalocker in the iBoot container is unavailable or invalid after {} steps of {} ms ({:?}); booting the SEP without it: Touch ID and trusted keys stay unavailable until the next boot\n", + steps, + STORE_WAIT_STEP_MS, + e + ), + } + this.store_pending.store(false, Relaxed); + let Some(sep_node) = dt::sep_node() else { + dev_err!(this.dev, "the SEP node is gone; not booting the SEP\n"); + return; + }; + if let Err(e) = this.attach(&sep_node) { + dev_err!(this.dev, "could not boot the SEP ({:?})\n", e); + } + } + fn settle_tick(this: &Arc) { match this.phase.load(Relaxed) { PHASE_ATTACH => Self::tick_attach(this), @@ -2390,7 +2471,7 @@ impl SepData { *self.mbox.lock() = None; - // SAFETY: all five pointers refer to pinned work fields in `self`. + // SAFETY: all six pointers refer to pinned work fields in `self`. // Shutdown blocks requeueing, and the mailbox can no longer add work. unsafe { sep_cancel_work_sync(Work::raw_get(core::ptr::addr_of!(self.rx_work)).cast()); @@ -2402,6 +2483,9 @@ impl SepData { sep_cancel_delayed_work_sync( DelayedWork::raw_as_work(core::ptr::addr_of!(self.late_attach_work)).cast(), ); + sep_cancel_delayed_work_sync( + DelayedWork::raw_as_work(core::ptr::addr_of!(self.store_wait_work)).cast(), + ); } sensor::power(false); @@ -2577,6 +2661,14 @@ impl WorkItem for SepData { } } +impl WorkItem for SepData { + type Pointer = Arc; + + fn run(this: Arc) { + SepData::store_wait_tick(&this); + } +} + impl WorkItem for SepData { type Pointer = Arc; @@ -2610,12 +2702,20 @@ impl WorkItem for SepData { struct SepDriver(Arc); -// Deliberately not exported as a module alias: udev must not load the driver -// on its own. The loader service loads it once the iBoot system container's -// partition link exists, which the xART store needs at probe, and only after -// the owner has enabled it (or chosen read-only) for this Mac. -const OF_TABLE: kernel::device_id::IdArray = - kernel::device_id::IdArray::new([(of::DeviceId::new(c"apple,sep"), ())]); +// Exported as a module alias so that udev loads the driver on every board +// whose device tree enables the SEP: the M1 and M2 laptops need the enclave +// booted for their microphones. A udev load may run before the iBoot system +// container's partition link exists, which the xART store is opened through; +// probe then waits for it before booting (see `store_wait_tick`). Writes to +// the shared store and identity provisioning stay opt-in through the +// xart_writes and provision_keybag module parameters, so a load the owner did +// not ask for changes nothing on the Mac. +kernel::of_device_table!( + OF_TABLE, + MODULE_OF_TABLE, + (), + [(of::DeviceId::new(c"apple,sep"), ())] +); impl platform::Driver for SepDriver { type IdInfo = (); @@ -2667,7 +2767,11 @@ impl platform::Driver for SepDriver { *data.mbox.lock() = Some(Mailbox::new_byname(dev, c"mbox", data.clone())?); - data.attach(&sep_node)?; + if data.store_pending.load(Relaxed) { + SepData::arm_store_wait(&data); + } else { + data.attach(&sep_node)?; + } if let Err(e) = data.register_fv_kernel() { dev_err!(dev, "could not register the FileVault kernel API: {:?}\n", e); @@ -2742,16 +2846,16 @@ module! { license: "Dual MIT/GPL", params: { xart_writes: u8 { - default: 1, - description: "Allow shared xART writes only if APFS proves a single unsnapshotted .gl extent; set to 0 for read-only operation", + default: 0, + description: "Allow shared xART writes only if APFS proves a single unsnapshotted .gl extent; 0 (the default) is read-only operation, enough to boot the enclave", }, xart_start_sector: u64 { default: 0, description: "Expected 512-byte start sector of the APFS .gl extent in the iBoot container. Zero accepts the APFS result; nonzero must match it and cannot override it", }, provision_keybag: u8 { - default: 1, - description: "Create the Linux identity keybag when none exists; set to 0 to disable first-boot provisioning; requires xart_writes=1", + default: 0, + description: "Create the Linux identity keybag when none exists (first-boot provisioning); requires xart_writes=1", }, xart_guard: i8 { default: -1, diff --git a/tools/aurora-sep/README.md b/tools/aurora-sep/README.md index aa8d5ce4e7a6b9..fe577281208247 100644 --- a/tools/aurora-sep/README.md +++ b/tools/aurora-sep/README.md @@ -49,16 +49,27 @@ for example with `systemctl edit aurora-sep.service`: Environment=AURORA_SEP_READY_TIMEOUT=180 ``` -The driver defaults to `xart_writes=1`. It exports no module alias, so udev -never loads it on its own: the service above loads it, once the iBoot system -container is reachable. Writes are accepted only when the APFS `.gl` +The driver exports its module alias, so udev loads it on every Mac whose device +tree enables the SEP and the enclave is booted early: on the M1 and M2 laptops +the Secure Enclave sits in the path of the microphone data lines, and the +microphones only work once it runs. If udev loads the driver before the iBoot +system container's partition link exists, the boot waits up to 30 s for it and +then runs without the xART store (Touch ID and trusted keys stay unavailable +until the next boot). The service above remains harmless and is no longer +required to load the driver. + +The driver defaults to `xart_writes=0 provision_keybag=0`: read-only operation, +which boots the enclave but refuses Touch ID enrol and verify. The Touch ID +package installs `/usr/lib/modprobe.d/apple-sep.conf` with +`options apple_sep xart_writes=1 provision_keybag=1`; a `--read-only` install +overrides it with `options apple_sep xart_writes=0 provision_keybag=0` in +`/etc/modprobe.d/`. Writes are accepted only when the APFS `.gl` extent passes the driver's narrow ownership checks: one physical extent, no snapshots or revert state, and a single extent reference owned by the `.gl` inode. The kernel resolves that extent from checksum-validated APFS metadata; unsupported layouts -fail closed. Set `options apple_sep xart_writes=0 provision_keybag=0` in a -modprobe configuration to retain read-only operation. `provision_keybag=1` -is also the default: first boot creates the Linux identity needed for trusted -keys, and later boots recover that identity and its machine reference key. +fail closed. With `provision_keybag=1`, the first boot creates the Linux +identity needed for trusted keys, and later boots recover that identity and its +machine reference key. An existing unreadable or invalid identity is not silently replaced. Enabling writes has been tested on m2 with identity-keybag provisioning, trusted-key seal/unseal, and reboot reload. The raw iBoot container hash did not diff --git a/tools/aurora-sep/aurora-touchid/PKGBUILD b/tools/aurora-sep/aurora-touchid/PKGBUILD index ebad07307e9665..30442c4ee92bf9 100644 --- a/tools/aurora-sep/aurora-touchid/PKGBUILD +++ b/tools/aurora-sep/aurora-touchid/PKGBUILD @@ -1,7 +1,7 @@ # Maintainer: Chris Kearney <303316+iconidentify@users.noreply.github.com> pkgname=aurora-touchid pkgver=20261003 -pkgrel=2 +pkgrel=3 pkgdesc="Touch ID for Omarchy on Apple Silicon (aurora kernel SEP driver)" arch=('any') url="https://github.com/iconidentify/aurora-linux" @@ -11,6 +11,7 @@ source=('aurora-touchid-setup' 'extract-mesa-calibration' 'apple-sep.service' 'apple-sep.path' + 'apple-sep.conf' 'fprintd-aurora.conf' 'aurora-touchid.sleep' 'wait-for-display' @@ -19,6 +20,7 @@ sha256sums=('406da23baf0127dd5ba116c2f83808fb10d979315a17227a78731c5d3081efe4' '15a878dcf382a22c5d807f0f2c754fe70d39baec88f65aea183b1fe56cf69441' '4f7b8a97e35e3511afa482ee8aedd019e960b1a67320675bd347f534feab49c3' '2f4b265a4c2180a9e0e4926c53ec77c3dbb074ddc3e083d7925d58db10a576b9' + 'd733cb47ae1da1547d7a6633b47976c7c1b5dae695e8687a00ed1ed24a3ea6fe' 'e1b1152e576e9588cc134b09291b3a2306ac686d9a47be6f128670608da535fc' 'a87526383319cc7c1214082196d0d80ad9a6da09b5c30bf215f866e01443c611' '062f70bb84e4139baf75d4dbefff21478af28f67e5569ee095692734d764746b' @@ -29,6 +31,7 @@ package() { install -Dm755 extract-mesa-calibration "$pkgdir/usr/lib/aurora-touchid/extract-mesa-calibration" install -Dm644 apple-sep.service "$pkgdir/usr/lib/systemd/system/apple-sep.service" install -Dm644 apple-sep.path "$pkgdir/usr/lib/systemd/system/apple-sep.path" + install -Dm644 apple-sep.conf "$pkgdir/usr/lib/modprobe.d/apple-sep.conf" install -Dm644 fprintd-aurora.conf "$pkgdir/usr/lib/systemd/system/fprintd.service.d/aurora.conf" install -Dm755 aurora-touchid.sleep "$pkgdir/usr/lib/systemd/system-sleep/aurora-touchid" install -Dm755 wait-for-display "$pkgdir/usr/lib/aurora-touchid/wait-for-display" diff --git a/tools/aurora-sep/aurora-touchid/apple-sep.conf b/tools/aurora-sep/aurora-touchid/apple-sep.conf new file mode 100644 index 00000000000000..f8a45518c921da --- /dev/null +++ b/tools/aurora-sep/aurora-touchid/apple-sep.conf @@ -0,0 +1,5 @@ +# Installed by aurora-touchid: the owner opted in to shared xART writes and +# first-boot identity provisioning when installing Touch ID support. Override +# with "options apple_sep xart_writes=0 provision_keybag=0" in /etc/modprobe.d +# for read-only operation (the enclave still boots; Touch ID stays off). +options apple_sep xart_writes=1 provision_keybag=1 From 5cd816a2266029b4ea6a950720aa48efbeadd328 Mon Sep 17 00:00:00 2001 From: Lucas Goossen Date: Mon, 26 Oct 2026 21:54:45 -0300 Subject: [PATCH 03/15] soc: apple: sep: refresh deferred boot and drop a failed keybag A default load still creates /var/lib/aurora-sep-host-state.bin (2359296 bytes). That is a Linux-only file, not an xART write. After the iBoot container opens late, refresh the cached xART diag facts before attach. Arm settle after that attach. Cold boot sets registered only on the IMG4 ack, so the timer is not gated on it. Join the store wait before dropping the mailbox, and do not publish the boot marker once shutdown has started. A keybag create that is not sent, or that the enclave answers with a non-zero status, removes the 52-byte uncommitted header. A create that was sent and not answered keeps the intent. A committed bag is left in place. Kconfig asks for a module so modprobe.d options reach the driver. load-driver writes /usr/lib/modprobe.d/apple-sep.conf only when that file is absent. The loader is no longer required only where the device tree enables the SEP node: the M1 family and J700. Signed-off-by: Lucas Goossen --- drivers/soc/apple/Kconfig | 11 +++-- drivers/soc/apple/diag.rs | 17 ++++++++ drivers/soc/apple/diag_shim.c | 6 +++ drivers/soc/apple/keybag.rs | 47 +++++++++++++++++++- drivers/soc/apple/sep.rs | 40 ++++++++++++++++- drivers/soc/apple/shim.h | 2 + drivers/soc/apple/shim.rs | 7 +++ drivers/soc/apple/sks.rs | 17 +++++--- drivers/soc/apple/store.rs | 5 ++- drivers/soc/apple/store_shim.c | 80 ++++++++++++++++++++++++++++++++++ tools/aurora-sep/README.md | 20 +++++---- tools/aurora-sep/load-driver | 19 +++++++- 12 files changed, 247 insertions(+), 24 deletions(-) diff --git a/drivers/soc/apple/Kconfig b/drivers/soc/apple/Kconfig index 7146af32265b3f..e89711dca4a12e 100644 --- a/drivers/soc/apple/Kconfig +++ b/drivers/soc/apple/Kconfig @@ -165,9 +165,14 @@ config APPLE_SEP 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. - - Say Y here if you have an Apple silicon Mac. + 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 diff --git a/drivers/soc/apple/diag.rs b/drivers/soc/apple/diag.rs index 288c92a3cd94c3..9a2e5261c144dd 100644 --- a/drivers/soc/apple/diag.rs +++ b/drivers/soc/apple/diag.rs @@ -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(); @@ -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) }; diff --git a/drivers/soc/apple/diag_shim.c b/drivers/soc/apple/diag_shim.c index 5c54d5d8410b32..de08544b16af3e 100644 --- a/drivers/soc/apple/diag_shim.c +++ b/drivers/soc/apple/diag_shim.c @@ -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, diff --git a/drivers/soc/apple/keybag.rs b/drivers/soc/apple/keybag.rs index ef629ae4fd484b..475d0e426b99bd 100644 --- a/drivers/soc/apple/keybag.rs +++ b/drivers/soc/apple/keybag.rs @@ -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( diff --git a/drivers/soc/apple/sep.rs b/drivers/soc/apple/sep.rs index 98a1af0433dcc0..25a83e7128c29e 100644 --- a/drivers/soc/apple/sep.rs +++ b/drivers/soc/apple/sep.rs @@ -1054,6 +1054,9 @@ impl SepData { if dt::registration_already_sent(sep_node) { return Err(EBUSY); } + if self.shutting_down.load(Relaxed) { + return Err(ENODEV); + } if let Err(e) = dt::mark_registration_sent(sep_node, iova) { dev_err!( @@ -1078,6 +1081,9 @@ impl SepData { // reload's TZ0 would go unanswered. Record the boot first, as the warm // path does, so a reload stops at probe and says to reboot instead. let iova = self.shmem.lock().as_ref().map_or(0, |buf| buf.dma_handle()); + if self.shutting_down.load(Relaxed) { + return Err(ENODEV); + } if let Err(e) = dt::mark_registration_sent(sep_node, iova) { dev_err!( self.dev, @@ -2191,7 +2197,12 @@ impl SepData { let steps = this.store_wait_steps.load(Relaxed) + 1; this.store_wait_steps.store(steps, Relaxed); match Self::open_xart_store(&this.dev, this.profile) { - Ok(store) => *this.store.lock() = Some(store), + Ok(store) => { + *this.store.lock() = Some(store); + let writable = this.xart_writable(); + let guard = this.with_store(|store| store.guard_state()).flatten(); + diag::refresh_store(writable, guard); + } Err(e) if e == ENODEV && steps < STORE_WAIT_STEPS => { return Self::arm_store_wait(this); } @@ -2203,13 +2214,25 @@ impl SepData { e ), } + if this.shutting_down.load(Relaxed) { + return; + } this.store_pending.store(false, Relaxed); let Some(sep_node) = dt::sep_node() else { dev_err!(this.dev, "the SEP node is gone; not booting the SEP\n"); return; }; + if this.shutting_down.load(Relaxed) { + return; + } if let Err(e) = this.attach(&sep_node) { dev_err!(this.dev, "could not boot the SEP ({:?})\n", e); + diag::attach(false); + } else { + // Cold boot sets `registered` only after the IMG4 ack, so this + // cannot wait for that flag. The synchronous probe path arms + // settle only once that flag is already set. + Self::arm_settle(this); } } @@ -2469,6 +2492,17 @@ impl SepData { handle.unregister(); } + // Finish the store wait before dropping the mailbox. A tick blocked in + // open_xart_store rechecks shutting_down before it attaches, and this + // waits for that return. Waiting until after the mailbox is gone lets + // the tick publish the boot marker, so the next probe stops with + // EBUSY. + unsafe { + sep_cancel_delayed_work_sync( + DelayedWork::raw_as_work(core::ptr::addr_of!(self.store_wait_work)).cast(), + ); + } + *self.mbox.lock() = None; // SAFETY: all six pointers refer to pinned work fields in `self`. @@ -2709,7 +2743,9 @@ struct SepDriver(Arc); // probe then waits for it before booting (see `store_wait_tick`). Writes to // the shared store and identity provisioning stay opt-in through the // xart_writes and provision_keybag module parameters, so a load the owner did -// not ask for changes nothing on the Mac. +// not ask for does not write the shared xART store. It does create +// /var/lib/aurora-sep-host-state.bin (2359296 bytes) the first time that +// Linux-only store is opened. kernel::of_device_table!( OF_TABLE, MODULE_OF_TABLE, diff --git a/drivers/soc/apple/shim.h b/drivers/soc/apple/shim.h index 0425bf2cdaa6ed..77f4aa69de78ea 100644 --- a/drivers/soc/apple/shim.h +++ b/drivers/soc/apple/shim.h @@ -53,6 +53,7 @@ long sep_store_write(void *handle, long long off, const void *buf, size_t len); int sep_store_sync(void *handle); int sep_store_sync_parent(void *handle); +int sep_store_unlink(const char *path); /* -- sha_shim.c --------------------------------------------------------- */ @@ -189,6 +190,7 @@ void sep_diag_set_bio_published(void); void sep_diag_set_touchid(bool started); void sep_diag_set_sensor_attach(int state); void sep_diag_set_restore(int state); +void sep_diag_set_xart(bool xart); void sep_diag_set_xart_guard(unsigned int level, bool list_loaded, int matching); void sep_diag_xart_guard_refused(int matching); diff --git a/drivers/soc/apple/shim.rs b/drivers/soc/apple/shim.rs index 8e30c3f54b8177..30024277344926 100644 --- a/drivers/soc/apple/shim.rs +++ b/drivers/soc/apple/shim.rs @@ -17,9 +17,16 @@ extern "C" { fn sep_store_write(handle: *mut c_void, off: i64, buf: *const c_void, len: usize) -> c_long; fn sep_store_sync(handle: *mut c_void) -> c_int; fn sep_store_sync_parent(handle: *mut c_void) -> c_int; + fn sep_store_unlink(path: *const c_char) -> c_int; fn sep_random_bytes(buf: *mut c_void, len: usize) -> c_int; } +pub(crate) fn unlink(path: &CStr) -> Result<()> { + // SAFETY: `path` is NUL-terminated. The shim unlinks that one directory + // entry under init's root and retains no pointer to it. + kernel::error::to_result(unsafe { sep_store_unlink(path.as_char_ptr()) }) +} + pub(crate) fn random_bytes(buf: &mut [u8]) -> Result<()> { // SAFETY: `buf.as_mut_ptr()` is valid for writes of `buf.len()` bytes for // the duration of the call, and `sep_random_bytes` writes exactly that many diff --git a/drivers/soc/apple/sks.rs b/drivers/soc/apple/sks.rs index bbc6c723c9cd20..26f7a746615a0c 100644 --- a/drivers/soc/apple/sks.rs +++ b/drivers/soc/apple/sks.rs @@ -35,10 +35,10 @@ impl<'a> KeybagCreateIntent<'a> { impl Drop for KeybagCreateIntent<'_> { fn drop(&mut self) { if !self.sent { - if let Err(e) = keybag::mark_refused(self.slot) { + if let Err(e) = keybag::discard_uncommitted(self.slot) { dev_err!( self.dev, - "sks: cannot mark unsent keybag create retryable: {:?}\n", + "sks: cannot remove unsent keybag create record: {:?}\n", e ); } @@ -610,17 +610,18 @@ impl SepData { } // A completed CREATE_KEYBAG that the enclave answered with a non-zero - // status created nothing, so the persisted intent must not block the next - // attempt: without this, every later seal fails with EEXIST. Any other - // failure (timeout, no answer) keeps the intent and stays fail-closed. + // status created nothing, so the header-only intent must not block the + // next attempt and must not stay behind as a 52-byte file. A timeout or + // no answer after sending() keeps the intent and stays fail-closed: the + // enclave may hold a bag this host never named. fn sks_mark_create_refused(&self, slot: keybag::Slot, status: i8) { if status == 0 { return; } - if let Err(e) = keybag::mark_refused(slot) { + if let Err(e) = keybag::discard_uncommitted(slot) { dev_err!( self.dev, - "sks: cannot mark refused keybag create retryable: {:?}\n", + "sks: cannot remove refused keybag create record: {:?}\n", e ); } @@ -698,6 +699,8 @@ impl SepData { self.dev, "sks: CREATE_KEYBAG exchange did not complete (buffers unregistered, wedged, or OOL write failed)\n" ); + // sent is true, so the intent file stays. A timeout can mean the + // enclave created a bag this host never named. return false; }; let Some(body) = self.sks_report_response(crate::sks::SKS_CREATE_NAME, &out) else { diff --git a/drivers/soc/apple/store.rs b/drivers/soc/apple/store.rs index e3abe11c7d5c82..e4957d924df3c2 100644 --- a/drivers/soc/apple/store.rs +++ b/drivers/soc/apple/store.rs @@ -260,7 +260,10 @@ impl Store { let size = store.file.size()?; if created && size == 0 { store.create()?; - pr_info!("created a new host-state store\n"); + pr_info!( + "created a new host-state store at /var/lib/aurora-sep-host-state.bin ({} bytes)\n", + STORE_SIZE + ); return Ok(store); } diff --git a/drivers/soc/apple/store_shim.c b/drivers/soc/apple/store_shim.c index 0eabe7305b0497..44f57a10e6214b 100644 --- a/drivers/soc/apple/store_shim.c +++ b/drivers/soc/apple/store_shim.c @@ -16,7 +16,10 @@ #include #include #include +#include #include +#include +#include #include #include "shim.h" @@ -175,3 +178,80 @@ int sep_store_sync_parent(void *handle) fput(dir); return ret; } + +/* + * Removes a driver-owned file under init's root and kernel credentials, the + * same way the opens above run. The parent directory stays. A negative + * dentry is ENOENT. Passes NULL for the delegation out-parameter: this file + * is not NFS-exported, and a lease break is not waited on. + */ +int sep_store_unlink(const char *path) +{ + const char *slash, *base; + char *dir; + size_t dirlen; + struct cred *kern; + const struct cred *old; + struct path root; + struct path parent; + struct dentry *dentry; + struct qstr name; + int ret; + + if (!path || path[0] != '/') + return -EINVAL; + slash = strrchr(path, '/'); + if (!slash || slash == path || !slash[1]) + return -EINVAL; + base = slash + 1; + dirlen = slash - path; + dir = kmalloc(dirlen + 1, GFP_KERNEL); + if (!dir) + return -ENOMEM; + memcpy(dir, path, dirlen); + dir[dirlen] = '\0'; + + kern = prepare_kernel_cred(&init_task); + if (!kern) { + kfree(dir); + return -ENOMEM; + } + task_lock(&init_task); + get_fs_root(init_task.fs, &root); + task_unlock(&init_task); + + old = override_creds(kern); + ret = vfs_path_lookup(root.dentry, root.mnt, dir, LOOKUP_DIRECTORY, + &parent); + kfree(dir); + if (ret) + goto out_cred; + + ret = mnt_want_write(parent.mnt); + if (ret) + goto out_parent; + + name = QSTR(base); + inode_lock_nested(d_inode(parent.dentry), I_MUTEX_PARENT); + dentry = lookup_one(mnt_idmap(parent.mnt), &name, parent.dentry); + if (IS_ERR(dentry)) { + ret = PTR_ERR(dentry); + goto unlock; + } + if (d_is_negative(dentry)) + ret = -ENOENT; + else + ret = vfs_unlink(mnt_idmap(parent.mnt), d_inode(parent.dentry), + dentry, NULL); + dput(dentry); +unlock: + inode_unlock(d_inode(parent.dentry)); + mnt_drop_write(parent.mnt); +out_parent: + path_put(&parent); +out_cred: + put_cred(revert_creds(old)); + path_put(&root); + put_cred(kern); + return ret; +} diff --git a/tools/aurora-sep/README.md b/tools/aurora-sep/README.md index fe577281208247..982555f71f6478 100644 --- a/tools/aurora-sep/README.md +++ b/tools/aurora-sep/README.md @@ -49,14 +49,18 @@ for example with `systemctl edit aurora-sep.service`: Environment=AURORA_SEP_READY_TIMEOUT=180 ``` -The driver exports its module alias, so udev loads it on every Mac whose device -tree enables the SEP and the enclave is booted early: on the M1 and M2 laptops -the Secure Enclave sits in the path of the microphone data lines, and the -microphones only work once it runs. If udev loads the driver before the iBoot -system container's partition link exists, the boot waits up to 30 s for it and -then runs without the xART store (Touch ID and trusted keys stay unavailable -until the next boot). The service above remains harmless and is no longer -required to load the driver. +The driver exports its module alias, so udev loads it where the device tree +already enables the SEP node. That is the M1 family and J700. On the M1 +laptops the Secure Enclave sits in the path of the microphone data lines, and +the microphones only work once it runs. There the service above remains +harmless and is no longer required to load the driver. The M2, M2 Pro/Max, +and M3 Air nodes stay disabled in the device tree and are enabled by module +init, so those machines still need the loader. If udev loads the driver before the iBoot system +container's partition link exists, the boot waits up to 30 s for it and then +runs without the xART store (Touch ID and trusted keys stay unavailable until +the next boot). A default load, including one with `xart_writes=0`, still +creates `/var/lib/aurora-sep-host-state.bin` (2359296 bytes) the first time +it opens that Linux-only store. That file is not an xART write. The driver defaults to `xart_writes=0 provision_keybag=0`: read-only operation, which boots the enclave but refuses Touch ID enrol and verify. The Touch ID diff --git a/tools/aurora-sep/load-driver b/tools/aurora-sep/load-driver index fbf43e5093f005..05c88a64d2f3bc 100755 --- a/tools/aurora-sep/load-driver +++ b/tools/aurora-sep/load-driver @@ -39,7 +39,24 @@ if [ "${AURORA_SEP_SESSION:-0}" != 1 ]; then exec keyctl session aurora-sep-load env AURORA_SEP_SESSION=1 "$0" "$@" fi -modprobe apple_sep xart_writes=1 provision_keybag=1 +# The options have to be on disk before udev's first load. Do not replace a +# file the Touch ID package or a --read-only install already wrote: /etc +# overrides this path, and rewriting it would force writes back on. +modprobe_conf=/usr/lib/modprobe.d/apple-sep.conf +if [ ! -f "$modprobe_conf" ]; then + mkdir -p /usr/lib/modprobe.d + printf '%s\n' 'options apple_sep xart_writes=1 provision_keybag=1' >"$modprobe_conf" +fi +if [ -d /sys/module/apple_sep ]; then + writes=$(cat /sys/module/apple_sep/parameters/xart_writes 2>/dev/null || true) + bag=$(cat /sys/module/apple_sep/parameters/provision_keybag 2>/dev/null || true) + if [ "$writes" != 1 ] || [ "$bag" != 1 ]; then + log "apple_sep is already loaded with xart_writes=${writes:-missing} provision_keybag=${bag:-missing}. $modprobe_conf applies on the next boot; reboot before expecting those options." + exit 1 + fi +else + modprobe apple_sep +fi work=$(mktemp -d /run/aurora-sep-load.XXXXXX) cleanup() { From a97d2d4bd7318c3308fd7b6f045639f018702331 Mon Sep 17 00:00:00 2001 From: Lucas Goossen Date: Fri, 30 Oct 2026 06:56:13 -0300 Subject: [PATCH 04/15] tools: aurora-sep: refresh the Arch package checksums load-driver and README.md moved on after the sums in the PKGBUILD. updpkgsums records the tree that packaging test compares against. Signed-off-by: Lucas Goossen --- tools/aurora-sep/packaging/arch/aurora-sep/PKGBUILD | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/aurora-sep/packaging/arch/aurora-sep/PKGBUILD b/tools/aurora-sep/packaging/arch/aurora-sep/PKGBUILD index b2254d7098fc56..844df8c55bfd0c 100644 --- a/tools/aurora-sep/packaging/arch/aurora-sep/PKGBUILD +++ b/tools/aurora-sep/packaging/arch/aurora-sep/PKGBUILD @@ -31,7 +31,7 @@ source=(load-driver aurora-sep-greeter-fingerprint.service README.md XART-SAFETY.md) -sha256sums=('abea60bb264ced349f7cf671d8d26e1609a81a60ea4c34d66ec6f7f73b847dbb' +sha256sums=('3f0bb8ab7031b435551128128a4438af2e062e9baf8776b0986a146042a088f4' '447f99cc3c7e683134f31b993aa825fadde24e4854954a3035c96e6631d4d4d0' 'f8d0c4b9385e6716d5ac5dd9941a57459fbc551a8238383bcde36cd929d0523f' '40f0d21446a85bab3e3800b31342e94e553af0fcde2c985503147519737e011d' @@ -40,7 +40,7 @@ sha256sums=('abea60bb264ced349f7cf671d8d26e1609a81a60ea4c34d66ec6f7f73b847dbb' '0695bd9ce4c207241db13c3ea07819a032d8213417021378f5015ab9317cde12' '5936eb76db666496a8700dade7ac6bcb3785b517958dcea10685690f1822c86f' 'ffab97b20bfd5f0eb1ab641179a131843349cf16890fff0cf2d893f0b5681b37' - 'dbcf59cecd62c0245cf39c3c8ee41e3088e2890da89288e91d1c53ee3f02cba4' + '86c530a48a53f40c3a08d3cdce457ec899ea16fd5320c3344459b33de9c16a64' '393bd394471e33706253027c48c19d9c1c8a4f6c0d9891bad1bd1364f7081a16') # A unit and the helper it runs ($1, installed as $3), pointed at the From ad5b7a174b3d02a31bc7276cd004982b77ce2165 Mon Sep 17 00:00:00 2001 From: Lucas Goossen Date: Fri, 30 Oct 2026 06:57:28 -0300 Subject: [PATCH 05/15] tools: aurora-sep: hide read-only options under apple-sep.conf A --read-only install wrote /etc/modprobe.d/aurora-sep.conf while the Touch ID package owns /usr/lib/modprobe.d/apple-sep.conf. modprobe passes both, the set-once parameters return EEXIST, and apple_sep does not load. The override has to use the same name so it hides the packaged file. Signed-off-by: Lucas Goossen --- tools/aurora-sep/README.md | 7 +++++-- tools/aurora-sep/aurora-touchid/PKGBUILD | 2 +- tools/aurora-sep/aurora-touchid/apple-sep.conf | 9 ++++++--- tools/aurora-sep/install-aurora-sep.sh | 7 +++++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/tools/aurora-sep/README.md b/tools/aurora-sep/README.md index 982555f71f6478..8fcaeee09cea2d 100644 --- a/tools/aurora-sep/README.md +++ b/tools/aurora-sep/README.md @@ -66,8 +66,11 @@ The driver defaults to `xart_writes=0 provision_keybag=0`: read-only operation, which boots the enclave but refuses Touch ID enrol and verify. The Touch ID package installs `/usr/lib/modprobe.d/apple-sep.conf` with `options apple_sep xart_writes=1 provision_keybag=1`; a `--read-only` install -overrides it with `options apple_sep xart_writes=0 provision_keybag=0` in -`/etc/modprobe.d/`. Writes are accepted only when the APFS `.gl` +hides that file by writing the same name, +`/etc/modprobe.d/apple-sep.conf`, with +`options apple_sep xart_writes=0 provision_keybag=0`. Another name in +`/etc/modprobe.d` does not override it: modprobe passes both lines, and the +set-once parameters abort the load. Writes are accepted only when the APFS `.gl` extent passes the driver's narrow ownership checks: one physical extent, no snapshots or revert state, and a single extent reference owned by the `.gl` inode. The kernel resolves that extent from checksum-validated APFS metadata; unsupported layouts diff --git a/tools/aurora-sep/aurora-touchid/PKGBUILD b/tools/aurora-sep/aurora-touchid/PKGBUILD index 30442c4ee92bf9..af617093283108 100644 --- a/tools/aurora-sep/aurora-touchid/PKGBUILD +++ b/tools/aurora-sep/aurora-touchid/PKGBUILD @@ -20,7 +20,7 @@ sha256sums=('406da23baf0127dd5ba116c2f83808fb10d979315a17227a78731c5d3081efe4' '15a878dcf382a22c5d807f0f2c754fe70d39baec88f65aea183b1fe56cf69441' '4f7b8a97e35e3511afa482ee8aedd019e960b1a67320675bd347f534feab49c3' '2f4b265a4c2180a9e0e4926c53ec77c3dbb074ddc3e083d7925d58db10a576b9' - 'd733cb47ae1da1547d7a6633b47976c7c1b5dae695e8687a00ed1ed24a3ea6fe' + 'aa3189cea883b24f9f57ee6af6ae7c43673d58355753b8dab63b07ed6cc79b93' 'e1b1152e576e9588cc134b09291b3a2306ac686d9a47be6f128670608da535fc' 'a87526383319cc7c1214082196d0d80ad9a6da09b5c30bf215f866e01443c611' '062f70bb84e4139baf75d4dbefff21478af28f67e5569ee095692734d764746b' diff --git a/tools/aurora-sep/aurora-touchid/apple-sep.conf b/tools/aurora-sep/aurora-touchid/apple-sep.conf index f8a45518c921da..3161db8f0a3497 100644 --- a/tools/aurora-sep/aurora-touchid/apple-sep.conf +++ b/tools/aurora-sep/aurora-touchid/apple-sep.conf @@ -1,5 +1,8 @@ # Installed by aurora-touchid: the owner opted in to shared xART writes and -# first-boot identity provisioning when installing Touch ID support. Override -# with "options apple_sep xart_writes=0 provision_keybag=0" in /etc/modprobe.d -# for read-only operation (the enclave still boots; Touch ID stays off). +# first-boot identity provisioning when installing Touch ID support. A +# read-only install hides this file with /etc/modprobe.d/apple-sep.conf +# containing "options apple_sep xart_writes=0 provision_keybag=0" (the +# enclave still boots; Touch ID stays off). The override has to use this +# name. A different name is passed as well, and the set-once parameters +# then refuse to load. options apple_sep xart_writes=1 provision_keybag=1 diff --git a/tools/aurora-sep/install-aurora-sep.sh b/tools/aurora-sep/install-aurora-sep.sh index 778bf309e518e1..9a3089c81039f9 100755 --- a/tools/aurora-sep/install-aurora-sep.sh +++ b/tools/aurora-sep/install-aurora-sep.sh @@ -297,8 +297,11 @@ PIN_BEGIN="# >>> aurora-sep pin (remove with: install-aurora-sep.sh --uninstall) PIN_END="# <<< aurora-sep pin" STATE=/var/lib/aurora-sep FALLBACK_ID=aurora-sep-previous-kernel -# Written only by --read-only; keeps the driver from writing to the enclave. -MODPROBE_CONF=/etc/modprobe.d/aurora-sep.conf +# Written only by --read-only. The name matches the file the Touch ID +# package owns under /usr/lib/modprobe.d, so this file hides it. A second +# name would pass both option lines, and the driver's set-once parameters +# then refuse to load. +MODPROBE_CONF=/etc/modprobe.d/apple-sep.conf READ_ONLY=0 DESKTOP_FIXES=0 DESKTOP_FIXES_DATA="" From 04b58e6ec1033c7256218a6031baa13f7247764a Mon Sep 17 00:00:00 2001 From: Lucas Goossen Date: Fri, 30 Oct 2026 06:57:28 -0300 Subject: [PATCH 06/15] tools: aurora-sep: keep going when apple_sep is already loaded Rust parameters are registered with perm 0, so xart_writes and provision_keybag never appear in sysfs. Treating that as a bad load exited 1 on every M1 and J700 boot, and aurora-sep-ready never ran. The packaged modprobe file stays owned by aurora-touchid; this script no longer writes it. Signed-off-by: Lucas Goossen --- tools/aurora-sep/load-driver | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/tools/aurora-sep/load-driver b/tools/aurora-sep/load-driver index 05c88a64d2f3bc..2ade48f5cd65c3 100755 --- a/tools/aurora-sep/load-driver +++ b/tools/aurora-sep/load-driver @@ -39,29 +39,24 @@ if [ "${AURORA_SEP_SESSION:-0}" != 1 ]; then exec keyctl session aurora-sep-load env AURORA_SEP_SESSION=1 "$0" "$@" fi -# The options have to be on disk before udev's first load. Do not replace a -# file the Touch ID package or a --read-only install already wrote: /etc -# overrides this path, and rewriting it would force writes back on. -modprobe_conf=/usr/lib/modprobe.d/apple-sep.conf -if [ ! -f "$modprobe_conf" ]; then - mkdir -p /usr/lib/modprobe.d - printf '%s\n' 'options apple_sep xart_writes=1 provision_keybag=1' >"$modprobe_conf" -fi -if [ -d /sys/module/apple_sep ]; then - writes=$(cat /sys/module/apple_sep/parameters/xart_writes 2>/dev/null || true) - bag=$(cat /sys/module/apple_sep/parameters/provision_keybag 2>/dev/null || true) - if [ "$writes" != 1 ] || [ "$bag" != 1 ]; then - log "apple_sep is already loaded with xart_writes=${writes:-missing} provision_keybag=${bag:-missing}. $modprobe_conf applies on the next boot; reboot before expecting those options." - exit 1 - fi -else +# aurora-touchid owns /usr/lib/modprobe.d/apple-sep.conf. Writing it here +# leaves an unowned file, and installing the package afterwards conflicts. +# A --read-only install hides that file with /etc/modprobe.d/apple-sep.conf. +# Rust parameters are registered with perm 0, so +# /sys/module/apple_sep/parameters never appears. An already-loaded module +# is not a failure: udev loads it on the M1 family and J700 before this +# service runs, and stopping here skips Touch ID activation and fingerprint +# restore (aurora-sep-ready Requires this unit). +module_dir=${AURORA_SEP_MODULE_DIR:-/sys/module/apple_sep} +if [ ! -d "$module_dir" ]; then modprobe apple_sep fi -work=$(mktemp -d /run/aurora-sep-load.XXXXXX) +run_dir=${AURORA_SEP_RUN_DIR:-/run} +work=$(mktemp -d "$run_dir/aurora-sep-load.XXXXXX") cleanup() { case "$work" in - /run/aurora-sep-load.*) rm -rf -- "$work" ;; + "$run_dir"/aurora-sep-load.*) rm -rf -- "$work" ;; esac } trap cleanup EXIT HUP INT TERM From 4dfa5584e897204febddeb76d736fbd77aaa6949 Mon Sep 17 00:00:00 2001 From: Lucas Goossen Date: Fri, 30 Oct 2026 06:57:28 -0300 Subject: [PATCH 07/15] soc: apple: sep: end bring-up when a deferred attach cannot start A missing SEP node or a failed attach after the store wait only logged the error. touchid and keystore stayed unknown, so trusted-key callers waited out the full bring-up timeout. Mark the attach failed and publish bring-up completion on both paths, as tick_attach already does. Signed-off-by: Lucas Goossen --- drivers/soc/apple/sep.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/soc/apple/sep.rs b/drivers/soc/apple/sep.rs index 25a83e7128c29e..a46dd094fd4c0d 100644 --- a/drivers/soc/apple/sep.rs +++ b/drivers/soc/apple/sep.rs @@ -2220,6 +2220,11 @@ impl SepData { this.store_pending.store(false, Relaxed); let Some(sep_node) = dt::sep_node() else { dev_err!(this.dev, "the SEP node is gone; not booting the SEP\n"); + // Same end as a failed settle: diag must not stay `unknown`, or + // every trusted-key caller waits out the full bring-up timeout. + diag::attach(false); + diag::bringup_ended(); + this.finish_bringup(); return; }; if this.shutting_down.load(Relaxed) { @@ -2228,6 +2233,8 @@ impl SepData { if let Err(e) = this.attach(&sep_node) { dev_err!(this.dev, "could not boot the SEP ({:?})\n", e); diag::attach(false); + diag::bringup_ended(); + this.finish_bringup(); } else { // Cold boot sets `registered` only after the IMG4 ack, so this // cannot wait for that flag. The synchronous probe path arms From 858f864521c4d84f1f96d11eac8cf766b969b329 Mon Sep 17 00:00:00 2001 From: Lucas Goossen Date: Fri, 30 Oct 2026 06:57:28 -0300 Subject: [PATCH 08/15] soc: apple: sep: do not say udev boots the M2 microphones The alias covers boards whose device tree enables the SEP node: the M1 family and J700. M2, M2 Pro/Max and M3 Air nodes stay disabled and still need the loader. The Kconfig help now matches that. Signed-off-by: Lucas Goossen --- drivers/soc/apple/Kconfig | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/soc/apple/Kconfig b/drivers/soc/apple/Kconfig index e89711dca4a12e..3eec878e7b58f4 100644 --- a/drivers/soc/apple/Kconfig +++ b/drivers/soc/apple/Kconfig @@ -155,9 +155,12 @@ 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. - The driver loads on its own (udev) and boots the enclave; on the M1 - and M2 laptops the Secure Enclave sits in the path of the microphone - data lines, so the microphones depend on it. If the iBoot system + 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 From 5b518de1e0d0fa5be79d5ec881f48afeed92839e Mon Sep 17 00:00:00 2001 From: Lucas Goossen Date: Fri, 30 Oct 2026 06:57:29 -0300 Subject: [PATCH 09/15] tools: aurora-sep: document the read-only driver defaults xart_writes and provision_keybag both default to 0. Writes and keybag provisioning come from the Touch ID package's modprobe file, which a read-only install hides. Signed-off-by: Lucas Goossen --- tools/aurora-sep/XART-SAFETY.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/aurora-sep/XART-SAFETY.md b/tools/aurora-sep/XART-SAFETY.md index b8282abc5250e6..f34f873e646fa1 100644 --- a/tools/aurora-sep/XART-SAFETY.md +++ b/tools/aurora-sep/XART-SAFETY.md @@ -2,11 +2,15 @@ ## Current default -`xart_writes=1` is the driver default. The APFS extent-ownership checks, -record validation and write-ordering checks remain mandatory; unsupported -layouts fail closed. `xart_writes=0 provision_keybag=0` explicitly selects -read-only operation. `provision_keybag=1` is the default: create the Linux -identity if missing and recover an existing identity without replacing it. +`xart_writes=0 provision_keybag=0` is the driver default: read-only +operation. The enclave still boots. Touch ID enrol and verify stay off, +because a match saves anti-replay state. The Touch ID package installs +`/usr/lib/modprobe.d/apple-sep.conf` with `xart_writes=1 provision_keybag=1`. +A `--read-only` install hides that file with `/etc/modprobe.d/apple-sep.conf` +setting both back to 0. The APFS extent-ownership checks, record validation +and write-ordering checks remain mandatory whenever writes are enabled; +unsupported layouts fail closed. `provision_keybag=1` creates the Linux +identity if missing and recovers an existing identity without replacing it. The historical evidence below records the earlier opt-in deployments and does not establish qualification on every supported Mac or APFS layout. From df0a807abfe45237e904723af08b2d7b59a5b661 Mon Sep 17 00:00:00 2001 From: Lucas Goossen Date: Fri, 30 Oct 2026 06:57:29 -0300 Subject: [PATCH 10/15] tools: aurora-sep: test load-driver and the deferred store wait A fake sysfs with no parameter files used to make load-driver stop before the trusted-key probe. The store-wait test checks that a missing node or a failed attach ends bring-up, and that remove() joins that wait before it drops the mailbox. Refresh the Arch checksums for the loader and the docs those checks sit next to. Signed-off-by: Lucas Goossen --- .../packaging/arch/aurora-sep/PKGBUILD | 6 +- tools/aurora-sep/tests/test_load_driver.py | 95 +++++++++++++++++++ tools/aurora-sep/tests/test_packaging.py | 3 + tools/aurora-sep/tests/test_sep_bringup.py | 47 +++++++++ 4 files changed, 148 insertions(+), 3 deletions(-) create mode 100644 tools/aurora-sep/tests/test_load_driver.py create mode 100644 tools/aurora-sep/tests/test_sep_bringup.py diff --git a/tools/aurora-sep/packaging/arch/aurora-sep/PKGBUILD b/tools/aurora-sep/packaging/arch/aurora-sep/PKGBUILD index 844df8c55bfd0c..9dbb634d0c2d74 100644 --- a/tools/aurora-sep/packaging/arch/aurora-sep/PKGBUILD +++ b/tools/aurora-sep/packaging/arch/aurora-sep/PKGBUILD @@ -31,7 +31,7 @@ source=(load-driver aurora-sep-greeter-fingerprint.service README.md XART-SAFETY.md) -sha256sums=('3f0bb8ab7031b435551128128a4438af2e062e9baf8776b0986a146042a088f4' +sha256sums=('39f24c692faec391b45866be64493a67048ea27c93b7400831bab20af1130c0c' '447f99cc3c7e683134f31b993aa825fadde24e4854954a3035c96e6631d4d4d0' 'f8d0c4b9385e6716d5ac5dd9941a57459fbc551a8238383bcde36cd929d0523f' '40f0d21446a85bab3e3800b31342e94e553af0fcde2c985503147519737e011d' @@ -40,8 +40,8 @@ sha256sums=('3f0bb8ab7031b435551128128a4438af2e062e9baf8776b0986a146042a088f4' '0695bd9ce4c207241db13c3ea07819a032d8213417021378f5015ab9317cde12' '5936eb76db666496a8700dade7ac6bcb3785b517958dcea10685690f1822c86f' 'ffab97b20bfd5f0eb1ab641179a131843349cf16890fff0cf2d893f0b5681b37' - '86c530a48a53f40c3a08d3cdce457ec899ea16fd5320c3344459b33de9c16a64' - '393bd394471e33706253027c48c19d9c1c8a4f6c0d9891bad1bd1364f7081a16') + '73d177cf3cca6c60af942ffd30c8906cd95c43ce91223e57ff2563012664ef9c' + 'ceaa590430a84736b3442627df4e1e2c5c23820e7aa88b64c6ff3914100c11ef') # A unit and the helper it runs ($1, installed as $3), pointed at the # packaged helper. diff --git a/tools/aurora-sep/tests/test_load_driver.py b/tools/aurora-sep/tests/test_load_driver.py new file mode 100644 index 00000000000000..9c09d51bd490a2 --- /dev/null +++ b/tools/aurora-sep/tests/test_load_driver.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only +"""load-driver keeps going when apple_sep is already loaded. + +Rust module parameters are registered with perm 0, so they never show up +under /sys/module/apple_sep/parameters. Exiting there used to fail +aurora-sep.service and, because aurora-sep-ready Requires it, skip Touch +ID activation and fingerprint restore. +""" + +import os +import stat +import subprocess +import tempfile +import textwrap +import unittest +from pathlib import Path + +SEP = Path(__file__).resolve().parents[1] +LOAD = SEP / "load-driver" +INSTALL = SEP / "install-aurora-sep.sh" + + +def write_exe(path, body): + path.write_text(textwrap.dedent(body).lstrip("\n")) + path.chmod(path.stat().st_mode | stat.S_IEXEC) + + +class LoadDriverTest(unittest.TestCase): + def run_loader(self, module_present): + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + bindir = root / "bin" + bindir.mkdir() + module = root / "sys" / "module" / "apple_sep" + if module_present: + module.mkdir(parents=True) + # parameters/ is absent on purpose: that is what the kernel exports. + write_exe(bindir / "keyctl", """\ + #!/bin/sh + if [ "$1" = session ]; then + # keyctl session env VAR=1