diff --git a/drivers/soc/apple/Kconfig b/drivers/soc/apple/Kconfig index ba57db91f8860b..3eec878e7b58f4 100644 --- a/drivers/soc/apple/Kconfig +++ b/drivers/soc/apple/Kconfig @@ -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 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 87b90a7d986ee6..a46dd094fd4c0d 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,44 +902,27 @@ 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) => { - 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, false) } }; @@ -921,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), @@ -983,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, ) @@ -1011,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!( @@ -1035,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, @@ -2127,6 +2176,73 @@ 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); + 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); + } + 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 + ), + } + 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"); + // 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) { + return; + } + 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 + // settle only once that flag is already set. + Self::arm_settle(this); + } + } + fn settle_tick(this: &Arc) { match this.phase.load(Relaxed) { PHASE_ATTACH => Self::tick_attach(this), @@ -2383,9 +2499,20 @@ 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 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()); @@ -2397,6 +2524,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); @@ -2572,6 +2702,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; @@ -2605,12 +2743,22 @@ 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 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, + (), + [(of::DeviceId::new(c"apple,sep"), ())] +); impl platform::Driver for SepDriver { type IdInfo = (); @@ -2662,7 +2810,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); @@ -2737,16 +2889,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/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 aa8d5ce4e7a6b9..3448a2cfc20d45 100644 --- a/tools/aurora-sep/README.md +++ b/tools/aurora-sep/README.md @@ -49,16 +49,39 @@ 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 where the device tree +already enables the SEP node. That is the M1 family and J700 (MacBook Neo, +T8140), whose device tree enables the SEP node, so it should work there too, +but J700 has not been tested with this change. 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. `aurora-sep` +and `aurora-touchid` each install `/usr/lib/modprobe.d/apple-sep.conf` with +`options apple_sep xart_writes=1 provision_keybag=1`, and each conflicts with +the other: that path can have only one owner. A bare `modprobe` before that +file is installed stays read-only. A `--read-only` install hides the packaged +file by writing the same name, `/etc/modprobe.d/apple-sep.conf`, with +`options apple_sep xart_writes=0 provision_keybag=0`. An older install wrote +`/etc/modprobe.d/aurora-sep.conf`; the installer and `aurora-touchid` rename +that file onto `apple-sep.conf`. Another name in `/etc/modprobe.d` does not +override the packaged file: 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 -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 @@ -165,10 +188,12 @@ by the Quickshell lock screen. ## Packages -`packaging/` builds `aurora-sep`, with the loader, its service and the fprintd -policy, as a distribution package. libfprint with the aurora driver comes from +`packaging/` builds `aurora-sep`, with the loader, its service, the modprobe +option file and the fprintd policy, as a distribution package. libfprint with +the aurora driver comes from https://github.com/aurora-silicon/aurora-sep-userspace; install both. Installing -`aurora-sep` lets fprintd load the driver with xART writes on, as above. +`aurora-sep` lets fprintd load the driver with xART writes on, as above. It +conflicts with `aurora-touchid`, which ships the same modprobe file. On Fedora, `packaging/fedora/build.sh` builds `aurora-sep`. It installs build dependencies, so run it in a throwaway container from the top of this tree: diff --git a/tools/aurora-sep/XART-SAFETY.md b/tools/aurora-sep/XART-SAFETY.md index b8282abc5250e6..de82d1b686106a 100644 --- a/tools/aurora-sep/XART-SAFETY.md +++ b/tools/aurora-sep/XART-SAFETY.md @@ -2,11 +2,18 @@ ## 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. `aurora-sep` and `aurora-touchid` +each install `/usr/lib/modprobe.d/apple-sep.conf` with +`xart_writes=1 provision_keybag=1` and conflict over that path. +A `--read-only` install hides that file with `/etc/modprobe.d/apple-sep.conf` +setting both back to 0. An older install used +`/etc/modprobe.d/aurora-sep.conf`; install renames it onto `apple-sep.conf`. +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. diff --git a/tools/aurora-sep/apple-sep.conf b/tools/aurora-sep/apple-sep.conf new file mode 120000 index 00000000000000..43e0881570ee6b --- /dev/null +++ b/tools/aurora-sep/apple-sep.conf @@ -0,0 +1 @@ +aurora-touchid/apple-sep.conf \ No newline at end of file diff --git a/tools/aurora-sep/aurora-touchid/PKGBUILD b/tools/aurora-sep/aurora-touchid/PKGBUILD index ebad07307e9665..fffcd3a6b4c264 100644 --- a/tools/aurora-sep/aurora-touchid/PKGBUILD +++ b/tools/aurora-sep/aurora-touchid/PKGBUILD @@ -1,16 +1,21 @@ # 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" license=('GPL-2.0-only') depends=('fprintd' 'libfprint>=1.94.100-1.1' 'python' 'kmod') +# Same path as aurora-sep's apple-sep.conf. One owner, or the set-once +# parameters see two option lines and refuse to load. +conflicts=('aurora-sep') +install=aurora-touchid.install 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 +24,7 @@ sha256sums=('406da23baf0127dd5ba116c2f83808fb10d979315a17227a78731c5d3081efe4' '15a878dcf382a22c5d807f0f2c754fe70d39baec88f65aea183b1fe56cf69441' '4f7b8a97e35e3511afa482ee8aedd019e960b1a67320675bd347f534feab49c3' '2f4b265a4c2180a9e0e4926c53ec77c3dbb074ddc3e083d7925d58db10a576b9' + 'aa3189cea883b24f9f57ee6af6ae7c43673d58355753b8dab63b07ed6cc79b93' 'e1b1152e576e9588cc134b09291b3a2306ac686d9a47be6f128670608da535fc' 'a87526383319cc7c1214082196d0d80ad9a6da09b5c30bf215f866e01443c611' '062f70bb84e4139baf75d4dbefff21478af28f67e5569ee095692734d764746b' @@ -29,6 +35,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..3161db8f0a3497 --- /dev/null +++ b/tools/aurora-sep/aurora-touchid/apple-sep.conf @@ -0,0 +1,8 @@ +# Installed by aurora-touchid: the owner opted in to shared xART writes and +# 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/aurora-touchid/aurora-touchid.install b/tools/aurora-sep/aurora-touchid/aurora-touchid.install new file mode 100644 index 00000000000000..ff609ab199f59a --- /dev/null +++ b/tools/aurora-sep/aurora-touchid/aurora-touchid.install @@ -0,0 +1,24 @@ +# An earlier --read-only install wrote /etc/modprobe.d/aurora-sep.conf. +# That name does not hide /usr/lib/modprobe.d/apple-sep.conf, so modprobe +# passes both option lines and the set-once parameters refuse to load. +# Rename it onto the name that hides the packaged file. If both exist, +# drop the old one. + +_migrate_read_only_modprobe() { + old=/etc/modprobe.d/aurora-sep.conf + new=/etc/modprobe.d/apple-sep.conf + [ -e "$old" ] || return 0 + if [ -e "$new" ]; then + rm -f -- "$old" + else + mv -- "$old" "$new" + fi +} + +post_install() { + _migrate_read_only_modprobe +} + +post_upgrade() { + _migrate_read_only_modprobe +} diff --git a/tools/aurora-sep/install-aurora-sep.sh b/tools/aurora-sep/install-aurora-sep.sh index 778bf309e518e1..0fa92d27e6a335 100755 --- a/tools/aurora-sep/install-aurora-sep.sh +++ b/tools/aurora-sep/install-aurora-sep.sh @@ -255,8 +255,8 @@ RUN_ID=$(cat /proc/sys/kernel/random/uuid 2>/dev/null) || RUN_ID="" # The kernel package version and the release tag move independently: a release # that only changes m1n1 reuses the previous kernel packages unchanged. -VERSION=7.1.12.aurora2-12.4 -TAG=sep-7.1.12.aurora2-12.4 +VERSION=7.1.12.aurora2-12.6 +TAG=sep-7.1.12.aurora2-12.6-stable # Packages are fetched from this script's own tag, never from "latest": the # checksums below belong to this release and nothing else. PUBLIC_RELEASE_URL=https://github.com/omacom/linux-aurora/releases/download/$TAG @@ -272,20 +272,20 @@ RELEASES_API=${AURORA_RELEASES_API:-$PUBLIC_RELEASES_API} # Where to always get the current script, whatever this copy turns out to be. LATEST_URL=https://github.com/omacom/linux-aurora/releases/latest/download/install-aurora-sep.sh PACKAGES=( - "linux-aurora-$VERSION-aarch64.pkg.tar.zst fded7d73e13dbe7f82722b925a257835761584203c5189337a251abab298bbde" - "linux-aurora-headers-$VERSION-aarch64.pkg.tar.zst a8da8cd00a40010ebe6096ae50c53b1ae461ae6570aa437f5b79a02f10b80cca" + "linux-aurora-$VERSION-aarch64.pkg.tar.zst d954e8c90f57b33d19d4a166d6f70225d7377abed59b35f3e20ac6d20427a39f" + "linux-aurora-headers-$VERSION-aarch64.pkg.tar.zst 758c469c2eab45f87ced3f44a59d86539b1b7b53aa1040dcbe1ef52f5c36c156" "libfprint-1.94.100-1.1-aarch64.pkg.tar.zst bc7d9762db6644f2cfb58ddb209602c1d513845eb1498c098e01f12600fcbdf9" - "aurora-touchid-20261003-1-any.pkg.tar.zst 29b0360fac8c257d754e64bd1b9c33c487eb2595dd3c31e9138d7a476afa3d64" + "aurora-touchid-20261003-3-any.pkg.tar.zst 6cadb78378f0fb7fe068b2efd9e33896eccf5a07b19905ee9c44aac9a3b3170a" ) # The one m1n1 for every Mac, as "file sha256": M1 and M2, an M3 on the handoff # path (see m3_plan), and the MacBook Neo once NEO_AURORA_M1N1 is 1. Macs differ # only in the switches /etc/m1n1.conf arms (m3_switches), never in the binary. -M1N1_PACKAGE="m1n1-aurora-1.6.1.aurora13-1-aarch64.pkg.tar.zst 23c7aff0f7b2da5ce272bce0eab7893e01091ce4d9350e4e650af1e9195208fa" +M1N1_PACKAGE="m1n1-aurora-1.6.1.aurora14-1-aarch64.pkg.tar.zst 4b4304a3f6e41e738e4003903084ee759fae2677162d960b6be65ccdf99de991" # The sha256 of the m1n1.bin in M1N1_PACKAGE: the bytes update-m1n1 puts at # the start of boot.bin. The script tells m1n1 builds apart by these bytes, # never by the version string they report: aurora8.5-1 and 8.5-2 both reported # v1.6.1-omarchy.aurora8.5. -M1N1_BIN_SHA=bf7b74a4648216432ac36171d896b11fa0584da19b242b16a11aa055963091de +M1N1_BIN_SHA=78b10efa89dcdc4aa9dfe8922e839b71ab1321ba19897ccc888b5e57eef5a6b9 # 0: a MacBook Neo keeps its own m1n1 (its M1N1= and U_BOOT= in # /etc/default/update-m1n1), as before 12.0. 1: it gets M1N1_PACKAGE like every # other Mac, and update-m1n1 builds its boot.bin from that m1n1 and the Neo's @@ -297,8 +297,13 @@ 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 aurora-sep and +# aurora-touchid install 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. Earlier installs wrote MODPROBE_CONF_OLD; +# sep_migrate_modprobe_conf renames that onto this name. +MODPROBE_CONF=/etc/modprobe.d/apple-sep.conf +MODPROBE_CONF_OLD=/etc/modprobe.d/aurora-sep.conf READ_ONLY=0 DESKTOP_FIXES=0 DESKTOP_FIXES_DATA="" @@ -3643,6 +3648,28 @@ calibration() { warn "could not extract the calibration; Touch ID will not work until it is present at $out" } +# Path of a --read-only override, under either name this script has used. +sep_read_only_conf() { + if [[ -f $MODPROBE_CONF ]]; then + printf '%s\n' "$MODPROBE_CONF" + elif [[ -f $MODPROBE_CONF_OLD ]]; then + printf '%s\n' "$MODPROBE_CONF_OLD" + fi +} + +# An earlier --read-only install wrote MODPROBE_CONF_OLD. That name does not +# hide /usr/lib/modprobe.d/apple-sep.conf, so modprobe passes both option +# lines and the set-once parameters refuse to load. Rename it. If both +# names exist, drop the old one. +sep_migrate_modprobe_conf() { + [[ -e $MODPROBE_CONF_OLD ]] || return 0 + if [[ -e $MODPROBE_CONF ]]; then + $sudo rm -f -- "$MODPROBE_CONF_OLD" + else + $sudo mv -- "$MODPROBE_CONF_OLD" "$MODPROBE_CONF" + fi +} + # The first line in modprobe.d that blacklists or redirects apple_sep, other # than our own file. Either spelling is the owner saying "do not load this". sep_block_line() { @@ -3661,6 +3688,7 @@ sep_block_line() { # the owner has to be able to opt out, and a block they already set must win. sep_policy() { local block + sep_migrate_modprobe_conf block=$(sep_block_line) if [[ -n $block ]]; then warn "apple_sep is blocked on this Mac ($block). @@ -3686,7 +3714,7 @@ sep_policy() { sep_write_notice() { (( READ_ONLY )) && return 0 - [[ -f $MODPROBE_CONF || -n $(sep_block_line) ]] && return 0 + [[ -n $(sep_read_only_conf) || -n $(sep_block_line) ]] && return 0 warn "on the first boot of a Mac with a Touch ID profile, the SEP driver creates an identity keybag and writes to the enclave's anti-replay store. Use a Mac you can DFU-restore. If you cannot, press Ctrl-C now and run with --read-only: @@ -4213,10 +4241,11 @@ package_database_check() { } install_all() { - local entry file sha kernel chain rc + local entry file sha kernel chain rc ro local -a entries candidate_archives=() release_source require_supported_soc + sep_migrate_modprobe_conf if ((ESP_ARCHIVE_HISTORY)); then ((!READ_ONLY)) || die "--archive-esp-history changes the EFI partition and cannot be combined with --read-only" esp_history_run archive @@ -4472,9 +4501,9 @@ install_all() { say "Done. Reboot: expect the desktop on the boot framebuffer. Touch ID is not supported on M3 yet. How to help bring this M3 further: step 11 of the test plan that the --agent-prompt command below prints." - elif [[ -f $MODPROBE_CONF ]]; then + elif ro=$(sep_read_only_conf); [[ -n $ro ]]; then say "Done, read-only. Reboot; the SEP driver will attach and report without writing." - echo " Enrolling a finger needs writes: delete $MODPROBE_CONF, reboot, then run aurora-touchid-setup." + echo " Enrolling a finger needs writes: delete $ro, reboot, then run aurora-touchid-setup." else say "Done. Reboot, then run: aurora-touchid-setup" fi @@ -4615,7 +4644,7 @@ uninstall_all() { ;; handoff) m3_restore_bringup ;; esac - $sudo rm -f "$MODPROBE_CONF" + $sudo rm -f "$MODPROBE_CONF" "$MODPROBE_CONF_OLD" # Keep recovery state and modules if the checked entry cannot be removed. if [[ $(boot_chain) == limine ]] && m3_limine_cleanup_needed; then m3_limine_remove_check remove @@ -4675,7 +4704,7 @@ sep_diag() { } reset_touchid() { - local yes=0 force=0 arg f d keybag found=0 + local yes=0 force=0 arg f d keybag found=0 ro for arg in "$@"; do case $arg in --yes) yes=1 ;; @@ -4684,8 +4713,9 @@ reset_touchid() { esac done grep -qa 'apple,' /proc/device-tree/compatible 2>/dev/null || die "this is not an Apple Silicon Mac" - [[ -f $MODPROBE_CONF ]] && - die "this Mac was installed read-only ($MODPROBE_CONF): a new keybag needs enclave writes. Delete that file first if you mean to allow them." + ro=$(sep_read_only_conf) + [[ -z $ro ]] || + die "this Mac was installed read-only ($ro): a new keybag needs enclave writes. Delete that file first if you mean to allow them." for f in "${TOUCHID_STATE_FILES[@]}"; do [[ -e $f ]] && found=1; done ((found)) || die "no Touch ID state on this Mac; nothing to reset" diff --git a/tools/aurora-sep/load-driver b/tools/aurora-sep/load-driver index fbf43e5093f005..984c4e52a48393 100755 --- a/tools/aurora-sep/load-driver +++ b/tools/aurora-sep/load-driver @@ -39,12 +39,56 @@ 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 +# aurora-sep and aurora-touchid each own /usr/lib/modprobe.d/apple-sep.conf +# and conflict. Writing it here leaves an unowned file. 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). diag/xart is the running +# driver's own report of writes. AURORA_SEP_DIAG_XART overrides that file; +# "none" skips the hint. +module_dir=${AURORA_SEP_MODULE_DIR:-/sys/module/apple_sep} +already_loaded=0 +if [ ! -d "$module_dir" ]; then + modprobe apple_sep +else + already_loaded=1 +fi + +# A module loaded read-only keeps those parameters until the next boot. +# Said only after the trusted-key wait fails: diag xart is also "disabled" +# while the iBoot container link is still missing, and that wait is long +# enough for the store to open when writes are actually on. +read_only_loaded_hint() { + [ "$already_loaded" = 1 ] || return 0 + if [ -z "${AURORA_SEP_DIAG_XART+x}" ]; then + diag= + for f in /sys/bus/platform/devices/*.sep/diag/xart; do + if [ -r "$f" ]; then + diag=$f + break + fi + done + else + diag=$AURORA_SEP_DIAG_XART + if [ -z "$diag" ] || [ "$diag" = none ]; then + return 0 + fi + fi + [ -n "$diag" ] && [ -r "$diag" ] || return 0 + read -r xart_state <"$diag" || return 0 + if [ "$xart_state" = disabled ]; then + log "apple_sep was already loaded read-only (diag xart=disabled). The option file applies on the next boot; reboot before expecting writes." + 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 @@ -72,6 +116,7 @@ done if [ "$verified" != true ]; then log "the enclave did not seal and unseal a trusted key within ${ready_timeout} s" + read_only_loaded_hint exit 1 fi log "trusted keys work after $(($(uptime_s) - start)) s" diff --git a/tools/aurora-sep/packaging/arch/aurora-sep/PKGBUILD b/tools/aurora-sep/packaging/arch/aurora-sep/PKGBUILD index b2254d7098fc56..4115aabf568b05 100644 --- a/tools/aurora-sep/packaging/arch/aurora-sep/PKGBUILD +++ b/tools/aurora-sep/packaging/arch/aurora-sep/PKGBUILD @@ -7,7 +7,7 @@ pkgname=aurora-sep pkgver=1 -pkgrel=12 +pkgrel=13 pkgdesc="Loader and desktop integration for the Apple SEP (Touch ID) driver" url="https://github.com/aurora-silicon/linux/tree/aurora-wip/tools/aurora-sep" arch=(any) @@ -19,6 +19,9 @@ depends=( kmod sh ) +# Same path as aurora-touchid's apple-sep.conf. A second copy would pass +# both option lines, and the set-once parameters refuse to load. +conflicts=(aurora-touchid) optdepends=('glib2-devel: fingerprint at the GNOME login screen') source=(load-driver aurora-sep.service @@ -29,9 +32,10 @@ source=(load-driver logind-aurora-sep.conf aurora-sep-greeter-fingerprint aurora-sep-greeter-fingerprint.service + apple-sep.conf README.md XART-SAFETY.md) -sha256sums=('abea60bb264ced349f7cf671d8d26e1609a81a60ea4c34d66ec6f7f73b847dbb' +sha256sums=('67cf483a359406447969f5c17504c0899041b7166fc0cea374d082f9b7559c57' '447f99cc3c7e683134f31b993aa825fadde24e4854954a3035c96e6631d4d4d0' 'f8d0c4b9385e6716d5ac5dd9941a57459fbc551a8238383bcde36cd929d0523f' '40f0d21446a85bab3e3800b31342e94e553af0fcde2c985503147519737e011d' @@ -40,8 +44,9 @@ sha256sums=('abea60bb264ced349f7cf671d8d26e1609a81a60ea4c34d66ec6f7f73b847dbb' '0695bd9ce4c207241db13c3ea07819a032d8213417021378f5015ab9317cde12' '5936eb76db666496a8700dade7ac6bcb3785b517958dcea10685690f1822c86f' 'ffab97b20bfd5f0eb1ab641179a131843349cf16890fff0cf2d893f0b5681b37' - 'dbcf59cecd62c0245cf39c3c8ee41e3088e2890da89288e91d1c53ee3f02cba4' - '393bd394471e33706253027c48c19d9c1c8a4f6c0d9891bad1bd1364f7081a16') + 'aa3189cea883b24f9f57ee6af6ae7c43673d58355753b8dab63b07ed6cc79b93' + '34757a603150d4e4b6a22fc2495b9a5df79c798fd81f0b37782bea763769e184' + '2f98e34c7048f26d1ef93df23b1b080fcf1b0af5c6354fbf582c9f29cb29628c') # A unit and the helper it runs ($1, installed as $3), pointed at the # packaged helper. @@ -69,5 +74,7 @@ package() { >"$pkgdir/usr/lib/systemd/system/fprintd.service.d/50-aurora-sep-no-timeout.conf" install -Dm644 logind-aurora-sep.conf \ "$pkgdir/usr/lib/systemd/logind.conf.d/50-aurora-sep.conf" + install -Dm644 apple-sep.conf \ + "$pkgdir/usr/lib/modprobe.d/apple-sep.conf" install -Dm644 -t "$pkgdir/usr/share/doc/$pkgname" README.md XART-SAFETY.md } diff --git a/tools/aurora-sep/packaging/arch/aurora-sep/apple-sep.conf b/tools/aurora-sep/packaging/arch/aurora-sep/apple-sep.conf new file mode 120000 index 00000000000000..b8de9cfdfde62f --- /dev/null +++ b/tools/aurora-sep/packaging/arch/aurora-sep/apple-sep.conf @@ -0,0 +1 @@ +../../../aurora-touchid/apple-sep.conf \ No newline at end of file diff --git a/tools/aurora-sep/packaging/fedora/aurora-sep.spec b/tools/aurora-sep/packaging/fedora/aurora-sep.spec index c32d5363130473..3b50595f7ed0f2 100644 --- a/tools/aurora-sep/packaging/fedora/aurora-sep.spec +++ b/tools/aurora-sep/packaging/fedora/aurora-sep.spec @@ -8,7 +8,7 @@ Name: aurora-sep Version: 1 -Release: 7%{?dist} +Release: 8%{?dist} Summary: Loader and desktop integration for the Apple SEP fingerprint driver License: GPL-2.0-only @@ -26,6 +26,7 @@ Source9: aurora-sep-greeter-fingerprint Source10: aurora-sep-greeter-fingerprint.service Source11: aurora_sep.te Source12: aurora_sep.fc +Source13: apple-sep.conf BuildArch: noarch BuildRequires: systemd-rpm-macros @@ -35,6 +36,8 @@ Requires: coreutils Requires: fprintd Requires: keyutils Requires: kmod +# Same path as aurora-touchid. A second copy passes both option lines. +Conflicts: aurora-touchid Requires: (%{name}-selinux = %{version}-%{release} if selinux-policy-%{selinuxtype}) # Only for aurora-sep-greeter-fingerprint.service, which is off by default. Suggests: /usr/bin/gresource @@ -90,6 +93,8 @@ sed 's|@FPRINTD@|%{_libexecdir}/fprintd|' %{SOURCE7} \ >%{buildroot}%{_unitdir}/fprintd.service.d/50-aurora-sep-no-timeout.conf install -Dpm 0644 %{SOURCE8} \ %{buildroot}%{_prefix}/lib/systemd/logind.conf.d/50-aurora-sep.conf +install -Dpm 0644 %{SOURCE13} \ + %{buildroot}%{_prefix}/lib/modprobe.d/apple-sep.conf # Load the driver at boot, so the enclave is up before the login screen asks. install -d %{buildroot}%{_presetdir} echo 'enable aurora-sep.service' >%{buildroot}%{_presetdir}/80-aurora-sep.preset @@ -137,6 +142,7 @@ fi %{_unitdir}/fprintd.service.d/aurora-sep.conf %{_unitdir}/fprintd.service.d/50-aurora-sep-no-timeout.conf %{_prefix}/lib/systemd/logind.conf.d/50-aurora-sep.conf +%{_prefix}/lib/modprobe.d/apple-sep.conf %{_presetdir}/80-aurora-sep.preset %files selinux @@ -144,6 +150,10 @@ fi %ghost %verify(not md5 size mode mtime) %{_sharedstatedir}/selinux/%{selinuxtype}/active/modules/200/%{modulename} %changelog +* Sat Oct 31 2026 Lucas Goossen - 1-8 +- Ship /usr/lib/modprobe.d/apple-sep.conf (xart_writes=1 provision_keybag=1) +- Conflict with aurora-touchid, which installs the same path + * Mon Oct 19 2026 Ryan Murray - 1-7 - XART-SAFETY.md: what the xART guard allows for restore, use, setup and recovery, per platform, and what a rollback does to its list 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..7cc5bb493ce917 --- /dev/null +++ b/tools/aurora-sep/tests/test_load_driver.py @@ -0,0 +1,122 @@ +#!/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, diag=None): + 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