From 0a1a0c75cec3696908990ef46320b69844f37187 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Wed, 28 Oct 2026 21:44:42 +1100 Subject: [PATCH 1/4] soc: apple: sep: warn once when a trusted key cannot be sealed aurora-sep-load seals and unseals a test key every 100 ms for up to two minutes while it waits for the machine ref-key. Each failed seal logged a warning, so a J616s boot whose ref-key was not up logged the same line 2290 times and buried everything else at warning level. The first failure keeps the warning that says what is wrong. The repeats only say the caller is still waiting, so they go to debug. Assisted-by: LLM Signed-off-by: Ryan Murray --- drivers/soc/apple/trusted.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/soc/apple/trusted.rs b/drivers/soc/apple/trusted.rs index 8ee02c62fe12d5..db444ff69e2f5e 100644 --- a/drivers/soc/apple/trusted.rs +++ b/drivers/soc/apple/trusted.rs @@ -106,11 +106,16 @@ unsafe extern "C" fn tk_seal(p: *mut c_void, _datablob: *mut c_char) -> c_int { let blob = match sep.refkey_seal_trusted(key) { Ok(blob) => blob, Err(e) => { - dev_warn!( - sep.dev, - "trusted-keys: seal failed ({:?}); the machine ref-key may not be established yet\n", - e - ); + // Callers retry until the ref-key is up: warn once, and keep + // each failure for debugging. + kernel::do_once_lite! { + dev_warn!( + sep.dev, + "trusted-keys: seal failed ({:?}); the machine ref-key may not be established yet\n", + e + ); + } + dev_dbg!(sep.dev, "trusted-keys: seal failed ({:?})\n", e); return e.to_errno(); } }; From 6f777290dfcdac22938118f6c09a2ea724dd0877 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Wed, 28 Oct 2026 21:37:21 +1100 Subject: [PATCH 2/4] tools/aurora-sep: start the login screen without waiting for Touch ID aurora-sep-greeter-fingerprint.service held gdm back until aurora-sep-ready.service finished, so the login screen would find the reader and its fingerprints. The enclave takes tens of seconds after boot, and when it does not come up the job timeout holds gdm until 90 s after boot. On the J616s the desktop appeared at 95 s; with automatic login that wait bought nothing at all. The greeter unit now only prepares the login screen's shell and no longer waits for Touch ID. A new aurora-sep-greeter-refresh.service runs once both gdm and Touch ID are up. When nobody has logged in yet, it shows the login screen again so it asks fprintd for the reader again and offers fingerprint. With automatic login, or once anyone has logged in, it changes nothing, since restarting gdm would end their session. Enabling the greeter unit enables the refresh unit with it. Assisted-by: LLM Signed-off-by: Ryan Murray --- tools/aurora-sep/README.md | 17 +++++++++-------- tools/aurora-sep/aurora-sep-greeter-fingerprint | 13 +++++++++++++ .../aurora-sep-greeter-fingerprint.service | 9 +++++---- .../aurora-sep-greeter-refresh.service | 14 ++++++++++++++ .../packaging/arch/aurora-sep/PKGBUILD | 12 +++++++++--- .../aurora-sep/packaging/fedora/aurora-sep.spec | 16 ++++++++++++---- 6 files changed, 62 insertions(+), 19 deletions(-) create mode 100644 tools/aurora-sep/aurora-sep-greeter-refresh.service diff --git a/tools/aurora-sep/README.md b/tools/aurora-sep/README.md index aa8d5ce4e7a6b9..695e55c62c006f 100644 --- a/tools/aurora-sep/README.md +++ b/tools/aurora-sep/README.md @@ -300,17 +300,18 @@ and serves the copy to the login screen's shell alone through a GResource overlay. When the check is not exactly as expected, for example after a GNOME update, it changes nothing. The enable key above still applies. -The login screen asks fprintd for the reader once, as it comes up, so the -same unit also holds it back until `aurora-sep-ready.service` has finished: -a few seconds on a healthy boot, but as long as the enclave takes when it is -slow, up to 90 s after boot. Without fingerprint at the login screen that -wait buys nothing, which is why both are one switch, off by default. It -needs `gresource` from glib2-devel. With the packages, or after installing -it by hand, turn it on with `systemctl enable`: +The login screen asks fprintd for the reader once, as it comes up, and the +enclave can take most of a minute after boot. The login screen does not wait +for it: `aurora-sep-greeter-refresh.service` runs once both are up, and when +Touch ID came up later and nobody has logged in, it shows the login screen +again so it offers fingerprint. With automatic login, or once someone has +logged in, it changes nothing. Both are one switch, off by default. It needs +`gresource` from glib2-devel. With the packages, or after installing it by +hand, turn it on with `systemctl enable`: ```sh install -Dm755 aurora-sep-greeter-fingerprint /usr/local/sbin/aurora-sep-greeter-fingerprint -install -Dm644 aurora-sep-greeter-fingerprint.service /etc/systemd/system/ +install -Dm644 aurora-sep-greeter-fingerprint.service aurora-sep-greeter-refresh.service /etc/systemd/system/ systemctl daemon-reload systemctl enable aurora-sep-greeter-fingerprint.service ``` diff --git a/tools/aurora-sep/aurora-sep-greeter-fingerprint b/tools/aurora-sep/aurora-sep-greeter-fingerprint index 7f04a19d24d20d..5793a2c93f88f6 100644 --- a/tools/aurora-sep/aurora-sep-greeter-fingerprint +++ b/tools/aurora-sep/aurora-sep-greeter-fingerprint @@ -25,6 +25,19 @@ log() { echo "aurora-sep-greeter-fingerprint: $*" >&2 } +if [ "${1:-}" = refresh ]; then + # Touch ID came up after the login screen asked fprintd for the reader, + # so the login screen has no fingerprint option. Show it again, but only + # while nobody is logged in: restarting gdm ends graphical sessions. + systemctl -q is-active gdm.service || exit 0 + for s in $(loginctl list-sessions --no-legend | awk '{print $1}'); do + [ "$(loginctl show-session "$s" -p Class --value)" != user ] || exit 0 + done + [ -f "$out/authServicesLegacy.js" ] || exit 0 + log "Touch ID is ready; showing the login screen again so it offers fingerprint" + exec systemctl restart gdm.service +fi + rm -rf "$out" "$dropin" [ "${1:-}" != stop ] || exit 0 diff --git a/tools/aurora-sep/aurora-sep-greeter-fingerprint.service b/tools/aurora-sep/aurora-sep-greeter-fingerprint.service index 108b1e4ccbc875..562133eb9fa812 100644 --- a/tools/aurora-sep/aurora-sep-greeter-fingerprint.service +++ b/tools/aurora-sep/aurora-sep-greeter-fingerprint.service @@ -1,10 +1,10 @@ [Unit] Description=Offer fingerprint at the GNOME login screen Documentation=file:///usr/share/doc/aurora-sep/README.md -# The login screen asks fprintd for the reader once, as it comes up. Hold it -# back until Touch ID is up, so that it finds the reader and the fingerprints. -Wants=aurora-sep-ready.service -After=aurora-sep-ready.service +# Only prepares the login screen's shell, so it never waits for Touch ID: the +# enclave can take most of a minute, and the login screen must not. When +# Touch ID comes up after the login screen has asked for the reader, +# aurora-sep-greeter-refresh.service shows the login screen again. Before=gdm.service [Service] @@ -15,3 +15,4 @@ ExecStop=/usr/local/sbin/aurora-sep-greeter-fingerprint stop [Install] WantedBy=gdm.service +Also=aurora-sep-greeter-refresh.service diff --git a/tools/aurora-sep/aurora-sep-greeter-refresh.service b/tools/aurora-sep/aurora-sep-greeter-refresh.service new file mode 100644 index 00000000000000..eeb672843fac7b --- /dev/null +++ b/tools/aurora-sep/aurora-sep-greeter-refresh.service @@ -0,0 +1,14 @@ +[Unit] +Description=Offer fingerprint on a login screen that came up before Touch ID +Documentation=file:///usr/share/doc/aurora-sep/README.md +# Runs once both are up. Requisite: when Touch ID did not come up, there is +# nothing to offer and the login screen stays as it is. +After=aurora-sep-ready.service gdm.service +Requisite=aurora-sep-ready.service + +[Service] +Type=oneshot +ExecStart=/usr/local/sbin/aurora-sep-greeter-fingerprint refresh + +[Install] +WantedBy=gdm.service diff --git a/tools/aurora-sep/packaging/arch/aurora-sep/PKGBUILD b/tools/aurora-sep/packaging/arch/aurora-sep/PKGBUILD index b2254d7098fc56..a0b32c4bfad771 100644 --- a/tools/aurora-sep/packaging/arch/aurora-sep/PKGBUILD +++ b/tools/aurora-sep/packaging/arch/aurora-sep/PKGBUILD @@ -29,6 +29,7 @@ source=(load-driver logind-aurora-sep.conf aurora-sep-greeter-fingerprint aurora-sep-greeter-fingerprint.service + aurora-sep-greeter-refresh.service README.md XART-SAFETY.md) sha256sums=('abea60bb264ced349f7cf671d8d26e1609a81a60ea4c34d66ec6f7f73b847dbb' @@ -38,9 +39,10 @@ sha256sums=('abea60bb264ced349f7cf671d8d26e1609a81a60ea4c34d66ec6f7f73b847dbb' 'f38421360c2f885bb102bc5076d81006d352d03d12b5fb35b4da8a5132f4ccc0' '8d8df0ba2a6861b2edb2110e606906d84ca4848617621ad3cb48493a1522971d' '0695bd9ce4c207241db13c3ea07819a032d8213417021378f5015ab9317cde12' - '5936eb76db666496a8700dade7ac6bcb3785b517958dcea10685690f1822c86f' - 'ffab97b20bfd5f0eb1ab641179a131843349cf16890fff0cf2d893f0b5681b37' - 'dbcf59cecd62c0245cf39c3c8ee41e3088e2890da89288e91d1c53ee3f02cba4' + '6b51052c2df5f54f477ccace5ebb268ccc4bf77923cc0499fc3dd996810c22cf' + '3d1c9c0cab1b090bd6b7d3c4bacaec8719e264afba6b565ada80b1e7914f203a' + 'fb58f07738b7654b15173fe0ffce2dff2f14b588d8edd24545e6c2c739605026' + '7f68294f1fd9544625228bfc863f69f4962e7cabb18a9e7620816737f4f76c6b' '393bd394471e33706253027c48c19d9c1c8a4f6c0d9891bad1bd1364f7081a16') # A unit and the helper it runs ($1, installed as $3), pointed at the @@ -61,6 +63,10 @@ package() { _unit aurora-sep-ready aurora-sep-ready.service aurora-sep-ready _unit aurora-sep-greeter-fingerprint aurora-sep-greeter-fingerprint.service \ aurora-sep-greeter-fingerprint + install -Dm644 aurora-sep-greeter-refresh.service \ + "$pkgdir/usr/lib/systemd/system/aurora-sep-greeter-refresh.service" + sed -i "s|^\(Exec[A-Za-z]*=\)/usr/local/sbin/|\1/usr/lib/aurora-sep/|" \ + "$pkgdir/usr/lib/systemd/system/aurora-sep-greeter-refresh.service" install -Dm644 fprintd-aurora.conf \ "$pkgdir/usr/lib/systemd/system/fprintd.service.d/aurora-sep.conf" diff --git a/tools/aurora-sep/packaging/fedora/aurora-sep.spec b/tools/aurora-sep/packaging/fedora/aurora-sep.spec index c32d5363130473..ae57df751cf3f5 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 @@ -24,6 +24,7 @@ Source7: fprintd-no-timeout.conf.in Source8: logind-aurora-sep.conf Source9: aurora-sep-greeter-fingerprint Source10: aurora-sep-greeter-fingerprint.service +Source14: aurora-sep-greeter-refresh.service Source11: aurora_sep.te Source12: aurora_sep.fc @@ -83,6 +84,8 @@ unit() { unit %{SOURCE0} %{SOURCE1} aurora-sep-load unit %{SOURCE5} %{SOURCE6} aurora-sep-ready unit %{SOURCE9} %{SOURCE10} aurora-sep-greeter-fingerprint +install -Dpm 0644 %{SOURCE14} %{buildroot}%{_unitdir}/aurora-sep-greeter-refresh.service +sed -i "s|^\(Exec[A-Za-z]*=\)/usr/local/sbin/aurora-sep-greeter-fingerprint|\1%{_libexecdir}/aurora-sep-greeter-fingerprint|" %{buildroot}%{_unitdir}/aurora-sep-greeter-refresh.service install -Dpm 0644 %{SOURCE2} \ %{buildroot}%{_unitdir}/fprintd.service.d/aurora-sep.conf grep -qx 'ExecStart=%{_libexecdir}/fprintd' %{_unitdir}/fprintd.service @@ -97,14 +100,14 @@ install -Dpm 0644 %{modulename}.pp.bz2 \ %{buildroot}%{_datadir}/selinux/packages/%{selinuxtype}/%{modulename}.pp.bz2 %post -%systemd_post aurora-sep.service aurora-sep-ready.service aurora-sep-greeter-fingerprint.service +%systemd_post aurora-sep.service aurora-sep-ready.service aurora-sep-greeter-fingerprint.service aurora-sep-greeter-refresh.service %preun -%systemd_preun aurora-sep.service aurora-sep-ready.service aurora-sep-greeter-fingerprint.service +%systemd_preun aurora-sep.service aurora-sep-ready.service aurora-sep-greeter-fingerprint.service aurora-sep-greeter-refresh.service %postun # Never restart them: the driver attaches to the enclave once per boot. -%systemd_postun aurora-sep.service aurora-sep-ready.service aurora-sep-greeter-fingerprint.service +%systemd_postun aurora-sep.service aurora-sep-ready.service aurora-sep-greeter-fingerprint.service aurora-sep-greeter-refresh.service %pre selinux %selinux_relabel_pre -s %{selinuxtype} @@ -133,6 +136,7 @@ fi %{_unitdir}/aurora-sep.service %{_unitdir}/aurora-sep-ready.service %{_unitdir}/aurora-sep-greeter-fingerprint.service +%{_unitdir}/aurora-sep-greeter-refresh.service %dir %{_unitdir}/fprintd.service.d %{_unitdir}/fprintd.service.d/aurora-sep.conf %{_unitdir}/fprintd.service.d/50-aurora-sep-no-timeout.conf @@ -144,6 +148,10 @@ fi %ghost %verify(not md5 size mode mtime) %{_sharedstatedir}/selinux/%{selinuxtype}/active/modules/200/%{modulename} %changelog +* Wed Oct 28 2026 Ryan Murray - 1-8 +- Start the login screen without waiting for Touch ID, and show it again + once Touch ID is ready if nobody has logged in yet + * 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 From 03e7d56849ed2dd702f5386b19602fb6050fa761 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Wed, 28 Oct 2026 22:07:27 +1100 Subject: [PATCH 3/4] soc: apple: sep: let a boot policy change update its xART record A new Stage 1 changes the boot policy the Mac keeps for Linux. The first time Linux's identity keybag is unlocked under the new policy, the enclave rewrites one session record that already existed. Linux did not create it, so the xART guard refuses the write. The enclave then never answers CHANGE_LOCK_STATE, the machine ref-key stays down and every trusted-key seal fails with EIO, so Touch ID is gone until the policy changes back. On a J616s (T6040) this happened after a Stage 1 reinstall that changed only the kernel collection hash. Under an unchanged policy that first unlock rewrites no session record at all, so a rewrite inside it is the policy change. Let exactly one through: during the first unlock of an identity keybag that already existed, once per boot, one kind-4 session record, a rewrite and never a delete, and only once the record's previous value is durable in a host file. The record is not added to Linux's list. A ref-key created this boot closes the window. For a change the window does not cover, aurora-sep-policy-change leaves a one-time allowance in /var/lib/aurora-sep-xart-allow-once.bin naming the refused record, or before a planned change the first existing kind-4 record asked for. The driver empties the file at probe before it uses it, so an allowance lasts one boot, on the same terms. Name refused records by their session id. Linux's list of records already holds session ids, so this reveals nothing new. On the J616s the allowance restored Touch ID with the existing enrolment: one kind-4 record and one shared root were rewritten, the other seven session records kept their revisions, and the enrolled finger matched. Assisted-by: LLM Signed-off-by: Ryan Murray --- drivers/soc/apple/refkey.rs | 46 +++-- drivers/soc/apple/xart_guard.rs | 321 ++++++++++++++++++++++++++++++-- drivers/soc/apple/xart_store.rs | 30 +++ 3 files changed, 369 insertions(+), 28 deletions(-) diff --git a/drivers/soc/apple/refkey.rs b/drivers/soc/apple/refkey.rs index e380dfd9ecfb05..73c6b22468ea06 100644 --- a/drivers/soc/apple/refkey.rs +++ b/drivers/soc/apple/refkey.rs @@ -98,6 +98,8 @@ impl SepData { profile::KeyStore::Variant5 => (9, 5), }; + // A ref-key created this boot belongs to the current boot policy. + crate::xart_guard::close_policy_window(); if self.profile.key_store == profile::KeyStore::Variant5 { // On variant 5 the ref-key is bound to the unlocked identity bag. if let Some(healthy) = self.sks_health_check(c"ref-key create") { @@ -280,16 +282,24 @@ impl SepData { return Err(ENODEV); }; let (handle, _uuid) = self.sks_recover(&stored).ok_or(EIO)?; - if self.profile.key_store == profile::KeyStore::Variant5 { - if let Some(healthy) = self.sks_health_check(c"trusted-key unseal") { - let _ = self.sks_send(self.sks_req_change_lock_state( - handle, - LockState::Unlocked, - stored.secret(), - healthy, - )); + // The first unlock under a changed boot policy rewrites one session + // record; see crate::xart_guard. + let unlocked = crate::xart_guard::policy_window(|| { + if self.profile.key_store == profile::KeyStore::Variant5 { + if let Some(healthy) = self.sks_health_check(c"trusted-key unseal") { + let _ = self.sks_send(self.sks_req_change_lock_state( + handle, + LockState::Unlocked, + stored.secret(), + healthy, + )); + } + true + } else { + self.sks_prepare_identity_refkey(handle, stored.secret()) } - } else if !self.sks_prepare_identity_refkey(handle, stored.secret()) { + }); + if !unlocked { let _ = self.sks_send(self.sks_req_unload_keybag(handle)); return Err(EIO); } @@ -349,14 +359,16 @@ impl SepData { return Err(ENODEV); }; let (handle, _uuid) = self.sks_recover(&stored).ok_or(EIO)?; - if let Some(healthy) = self.sks_health_check(c"ref-key attest") { - let _ = self.sks_send(self.sks_req_change_lock_state( - handle, - LockState::Unlocked, - stored.secret(), - healthy, - )); - } + crate::xart_guard::policy_window(|| { + if let Some(healthy) = self.sks_health_check(c"ref-key attest") { + let _ = self.sks_send(self.sks_req_change_lock_state( + handle, + LockState::Unlocked, + stored.secret(), + healthy, + )); + } + }); let sig = self.sks_refkey_sign(handle, &blob, challenge); let _ = self.sks_send(self.sks_req_unload_keybag(handle)); Ok((sig.ok_or(EIO)?, pubk)) diff --git a/drivers/soc/apple/xart_guard.rs b/drivers/soc/apple/xart_guard.rs index 6efb2a8609330f..1f9f802038e40c 100644 --- a/drivers/soc/apple/xart_guard.rs +++ b/drivers/soc/apple/xart_guard.rs @@ -44,16 +44,85 @@ //! nothing identifies that locker as the pending one. It does not list the //! locker as Linux's, and the list records the window as consumed before it //! opens, so no later create on this install gets it again. +//! +//! A boot policy change (a new Stage 1, a different boot object) makes the +//! enclave rewrite one existing session record the first time Linux's +//! identity keybag is unlocked under the new policy. Linux did not create +//! that record. On a boot under an unchanged policy that unlock rewrites no +//! session record at all, so a rewrite inside it is the sign of a policy +//! change. The guard lets exactly one kind-4 rewrite through in that window +//! ([`policy_window`]): the first unlock of an identity keybag that already +//! existed, at most once per boot, never a delete, and only once the +//! record's previous value is saved in a host file ([`PREVIOUS_PATH`]). +//! The record is not added to Linux's list. +//! +//! For a policy change the window did not cover, `aurora-sep-policy-change` +//! backs up the gigalocker and leaves a one-time allowance in a host file +//! ([`ALLOW_PATH`]): one record, named or the first of its kind, that the +//! enclave may rewrite during the next boot only, on the same terms. The +//! driver empties the file before it uses the allowance. use crate::shim::StoreFile; use crate::xart_store::{crc32_ieee, Key}; use kernel::prelude::*; +use kernel::sync::atomic::{Atomic, Relaxed}; /// Host file listing the session records Linux created. pub(crate) const OWNED_PATH: &CStr = c"/var/lib/aurora-sep-xart-owned.bin"; +/// Host file holding the one-time allowance for a boot policy change. +pub(crate) const ALLOW_PATH: &CStr = c"/var/lib/aurora-sep-xart-allow-once.bin"; +/// Host file keeping the previous value of every record rewritten for a +/// boot policy change. +pub(crate) const PREVIOUS_PATH: &CStr = c"/var/lib/aurora-sep-xart-policy-previous.bin"; +const PREVIOUS_MAGIC: &[u8; 4] = b"AXGP"; +/// The kind of session record a boot policy change rewrites. +const POLICY_KIND: u8 = 4; + +/// Whether the first unlock of an existing identity keybag has started this +/// boot, and whether it is running now. +static WINDOW_STARTED: Atomic = Atomic::new(false); +static WINDOW_OPEN: Atomic = Atomic::new(false); + +/// Runs `unlock`, the unlock of an identity keybag that already existed, +/// with the boot policy window open if it is this boot's first. Later +/// unlocks run with it closed. +pub(crate) fn policy_window(unlock: impl FnOnce() -> T) -> T { + if WINDOW_STARTED.xchg(true, Relaxed) { + return unlock(); + } + WINDOW_OPEN.store(true, Relaxed); + let result = unlock(); + WINDOW_OPEN.store(false, Relaxed); + result +} + +/// Keeps the window shut for the rest of the boot: a keybag or ref-key +/// created this boot is not unlocked under an older policy. +pub(crate) fn close_policy_window() { + WINDOW_STARTED.store(true, Relaxed); +} + +/// Saves `value`, the current value of `key`, before it is rewritten for a +/// boot policy change. The rewrite goes ahead only once this is durable. +pub(crate) fn save_previous(key: &Key, value: &[u8]) -> Result<()> { + let (file, _created) = StoreFile::open_host(PREVIOUS_PATH)?; + file.sync_parent()?; + let end = file.size()?; + let mut head = [0u8; 32]; + head[..4].copy_from_slice(PREVIOUS_MAGIC); + head[4] = key.kind; + head[8..24].copy_from_slice(&key.uuid); + let len = u32::try_from(value.len()).map_err(|_| EINVAL)?; + head[24..28].copy_from_slice(&len.to_le_bytes()); + head[28..32].copy_from_slice(&crc32_ieee(value).to_le_bytes()); + file.write_all(end, &head)?; + file.write_all(end + head.len() as u64, value)?; + file.sync() +} const ENTRY_SIZE: usize = 32; const ENTRY_MAGIC: &[u8; 4] = b"AXGO"; +const ALLOW_MAGIC: &[u8; 4] = b"AXGA"; /// Bounds the file the driver reads at probe, counted in entries the file /// holds, torn and repeated ones included. The gigalocker has at most a few /// hundred slots, so a longer list is damaged. Appending stops at the same @@ -168,9 +237,9 @@ impl MatchFacts { } } -fn entry_bytes(kind: u8, uuid: &[u8; 16]) -> [u8; ENTRY_SIZE] { +fn entry_bytes(magic: &[u8; 4], kind: u8, uuid: &[u8; 16]) -> [u8; ENTRY_SIZE] { let mut entry = [0u8; ENTRY_SIZE]; - entry[..4].copy_from_slice(ENTRY_MAGIC); + entry[..4].copy_from_slice(magic); entry[4] = kind; entry[8..24].copy_from_slice(uuid); let crc = crc32_ieee(&entry[..24]); @@ -180,18 +249,26 @@ fn entry_bytes(kind: u8, uuid: &[u8; 16]) -> [u8; ENTRY_SIZE] { /// Encodes one list entry. pub(crate) fn encode(key: &Key) -> [u8; ENTRY_SIZE] { - entry_bytes(key.kind, &key.uuid) + encode_with(ENTRY_MAGIC, key) +} + +fn encode_with(magic: &[u8; 4], key: &Key) -> [u8; ENTRY_SIZE] { + entry_bytes(magic, key.kind, &key.uuid) } /// The entry that records this install's first-setup window as consumed. /// Kind 0 is no session record's, so it never lists a record as Linux's. pub(crate) fn setup_consumed() -> [u8; ENTRY_SIZE] { - entry_bytes(0, b"first setup used") + entry_bytes(ENTRY_MAGIC, 0, b"first setup used") } /// Decodes one list entry; `None` for a torn or foreign one. pub(crate) fn decode(entry: &[u8]) -> Option { - if entry.len() != ENTRY_SIZE || &entry[..4] != ENTRY_MAGIC || entry[5..8] != [0; 3] { + decode_with(ENTRY_MAGIC, entry) +} + +fn decode_with(magic: &[u8; 4], entry: &[u8]) -> Option { + if entry.len() != ENTRY_SIZE || &entry[..4] != magic || entry[5..8] != [0; 3] { return None; } let crc = u32::from_le_bytes([entry[24], entry[25], entry[26], entry[27]]); @@ -203,6 +280,89 @@ pub(crate) fn decode(entry: &[u8]) -> Option { Some(Key::new(entry[4], uuid)) } +/// A session id, printed the way `aurora-sep-policy-change` takes it. +pub(crate) struct Id<'a>(pub(crate) &'a [u8; 16]); + +impl kernel::fmt::Display for Id<'_> { + fn fmt(&self, f: &mut kernel::fmt::Formatter<'_>) -> kernel::fmt::Result { + for byte in self.0 { + write!(f, "{:02x}", byte)?; + } + Ok(()) + } +} + +/// The one existing session record the enclave may rewrite once this boot, +/// after a boot policy change. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub(crate) enum Allowance { + /// This record, named by an earlier boot's refusal. + Record(Key), + /// The first existing record of this kind the enclave asks to rewrite. + /// An installer that changes the boot policy cannot know the record's + /// session id beforehand; the first identity unlock under the new policy + /// comes before anything else can rewrite a session record. + FirstOfKind(u8), +} + +impl Allowance { + /// Decodes the allowance file; `None` for anything but one valid entry. + /// An all-zero session id stands for [`Allowance::FirstOfKind`]. + pub(crate) fn decode(file: &[u8]) -> Option { + let key = decode_with(ALLOW_MAGIC, file)?; + Some(if key.uuid == [0; 16] { + Allowance::FirstOfKind(key.kind) + } else { + Allowance::Record(key) + }) + } + + fn covers(&self, key: &Key) -> bool { + match self { + Allowance::Record(allowed) => allowed == key, + Allowance::FirstOfKind(kind) => *kind == key.kind, + } + } +} + +/// Reads and empties the allowance file. The allowance is for this boot +/// only: when the file cannot be emptied, it is not used at all. +fn take_allowance() -> Option { + let file = StoreFile::open_readonly(ALLOW_PATH).ok()?; + let size = file.size().ok()?; + if size == 0 { + return None; + } + let mut entry = [0u8; ENTRY_SIZE]; + let read = if size == ENTRY_SIZE as u64 { + file.read_exact(0, &mut entry).is_ok() + } else { + false + }; + drop(file); + if let Err(e) = StoreFile::open_trunc(ALLOW_PATH).and_then(|file| file.sync()) { + pr_warn!( + "xART guard: could not empty the one-time allowance ({:?}); not using it\n", + e + ); + return None; + } + let allowance = if read { Allowance::decode(&entry) } else { None }; + match allowance { + Some(Allowance::Record(key)) => pr_info!( + "xART guard: this boot may rewrite kind-{} record {} once, for a boot policy change\n", + key.kind, + Id(&key.uuid) + ), + Some(Allowance::FirstOfKind(kind)) => pr_info!( + "xART guard: this boot may rewrite the first existing kind-{} record the enclave asks for, once, for a boot policy change\n", + kind + ), + None => pr_warn!("xART guard: ignored a damaged one-time allowance\n"), + } + allowance +} + /// The file that holds Linux's list: the host file, or memory in the tests. pub(crate) trait ListFile { fn size(&self) -> Result; @@ -246,18 +406,29 @@ pub(crate) struct Guard { existed: KVec, refused: usize, first_setup: FirstSetup, + /// The one-time allowance for a boot policy change, until it is used. + allowance: Option, + /// The boot policy window let its one rewrite through. + window_used: bool, + /// The write just allowed is a boot policy change rewrite: its previous + /// value must be saved first ([`Guard::take_save_previous`]). + save_previous: bool, + /// Whether the boot policy window is open; the tests use their own. + window_open: fn() -> bool, } impl Guard { /// Opens Linux's list in the host file and records which keys `existing` - /// holds now. Never fails: a list that cannot be read protects every - /// existing record. + /// holds now, and takes this boot's one-time allowance if there is one. + /// Never fails: a list that cannot be read protects every existing record. pub(crate) fn open(level: u8, existing: KVec) -> Guard { - Guard::with_file( + let mut guard = Guard::with_file( level, existing, StoreFile::open_host(OWNED_PATH).map(|(file, _created)| file), - ) + ); + guard.allowance = take_allowance(); + guard } } @@ -272,6 +443,10 @@ impl Guard { existed: existing, refused: 0, first_setup: FirstSetup::Closed, + allowance: None, + window_used: false, + save_previous: false, + window_open: || WINDOW_OPEN.load(Relaxed), }; // A list created this boot (or by a crashed one) is only safe to adopt // into once its name is durable: fsync() of the file alone does not @@ -430,21 +605,59 @@ impl Guard { ); Ok(()) } + Verdict::Refuse if write && self.take_allowance_for(key) => { + self.save_previous = true; + Ok(()) + } Verdict::Refuse => { crate::diag::xart_guard_refused(); self.refused += 1; if self.refused <= LOGGED_REFUSALS { let action = if write { "rewrite" } else { "delete" }; pr_warn!( - "xART guard: refused to {} a kind-{} record this Linux install did not create\n", + "xART guard: refused to {} kind-{} record {}, which this Linux install did not create\n", action, - key.kind + key.kind, + Id(&key.uuid) ); } Err(EPERM) } } } + + /// Uses up the one-time allowance if it covers `key`, or else the boot + /// policy window's one rewrite. + fn take_allowance_for(&mut self, key: &Key) -> bool { + if self.allowance.is_some_and(|allowance| allowance.covers(key)) { + self.allowance = None; + return true; + } + if key.kind == POLICY_KIND && !self.window_used && (self.window_open)() { + self.window_used = true; + return true; + } + false + } + + /// Whether the write [`Guard::check`] just allowed rewrites a record for + /// a boot policy change, whose previous value must be saved first. + pub(crate) fn take_save_previous(&mut self) -> bool { + core::mem::take(&mut self.save_previous) + } + + /// The previous value could not be saved: the rewrite is refused after + /// all. + pub(crate) fn refuse_unsaved(&mut self, key: &Key, e: Error) { + crate::diag::xart_guard_refused(); + self.refused += 1; + pr_warn!( + "xART guard: could not save kind-{} record {} before its boot policy rewrite ({:?}); refusing it\n", + key.kind, + Id(&key.uuid), + e + ); + } } #[cfg(CONFIG_APPLE_SEP_KUNIT_TEST)] @@ -1016,4 +1229,90 @@ mod tests { assert_eq!(level(2, 1), Some(2)); assert_eq!(level(i8::MAX, 0), Some(2)); } + + /// What `aurora-sep-policy-change` writes. + fn allowance_entry(allowance: &Allowance) -> [u8; ENTRY_SIZE] { + match allowance { + Allowance::Record(key) => encode_with(ALLOW_MAGIC, key), + Allowance::FirstOfKind(kind) => encode_with(ALLOW_MAGIC, &Key::new(*kind, [0; 16])), + } + } + + #[test] + fn allowances_round_trip() { + let named = Allowance::Record(session(9)); + assert_eq!(Allowance::decode(&allowance_entry(&named)), Some(named)); + let first = Allowance::FirstOfKind(4); + assert_eq!(Allowance::decode(&allowance_entry(&first)), Some(first)); + // A list entry is not an allowance, and roots cannot be allowed. + assert_eq!(Allowance::decode(&encode(&session(9))), None); + assert_eq!(Allowance::decode(&encode_with(ALLOW_MAGIC, &Key::root(1))), None); + let mut torn = allowance_entry(&named); + torn[12] ^= 1; + assert_eq!(Allowance::decode(&torn), None); + } + + #[test] + fn a_named_allowance_rewrites_that_record_once() -> Result<()> { + let bytes = RefCell::new(KVec::new()); + let (policy, other) = (session(1), session(2)); + let mut guard = Guard::with_file(1, keys(&[policy, other])?, Ok(mem(&bytes))); + guard.allowance = Some(Allowance::Record(policy)); + // Never a delete, and never another record. + assert_eq!(guard.check(&policy, false), Err(EPERM)); + assert_eq!(guard.check(&other, true), Err(EPERM)); + assert_eq!(guard.check(&policy, true), Ok(())); + assert!(guard.take_save_previous()); + assert_eq!(guard.check(&policy, true), Err(EPERM)); + // The record is not adopted. + assert!(bytes.borrow().is_empty()); + Ok(()) + } + + #[test] + fn a_first_of_kind_allowance_covers_one_record() -> Result<()> { + let bytes = RefCell::new(KVec::new()); + let (a, b) = (session(1), session(2)); + let mut guard = Guard::with_file(1, keys(&[a, b, Key::new(3, [3; 16])])?, Ok(mem(&bytes))); + guard.allowance = Some(Allowance::FirstOfKind(4)); + assert_eq!(guard.check(&Key::new(3, [3; 16]), true), Err(EPERM)); + assert_eq!(guard.check(&b, true), Ok(())); + assert_eq!(guard.check(&a, true), Err(EPERM)); + assert_eq!(guard.check(&b, true), Err(EPERM)); + Ok(()) + } + + #[test] + fn an_allowance_leaves_new_and_listed_records_alone() -> Result<()> { + let bytes = RefCell::new(KVec::new()); + let (old, new) = (session(1), session(2)); + let mut guard = Guard::with_file(1, keys(&[old])?, Ok(mem(&bytes))); + guard.allowance = Some(Allowance::FirstOfKind(4)); + // A new record is adopted as usual and does not use the allowance. + assert_eq!(guard.check(&new, true), Ok(())); + assert_eq!(guard.check(&old, true), Ok(())); + assert_eq!(guard.allowance, None); + Ok(()) + } + + #[test] + fn the_policy_window_lets_one_kind_4_rewrite_through() -> Result<()> { + let bytes = RefCell::new(KVec::new()); + let (a, b, c) = (session(1), session(2), Key::new(3, [3; 16])); + let mut guard = Guard::with_file(1, keys(&[a, b, c])?, Ok(mem(&bytes))); + // Outside the window nothing changes. + guard.window_open = || false; + assert_eq!(guard.check(&a, true), Err(EPERM)); + guard.window_open = || true; + assert_eq!(guard.check(&c, true), Err(EPERM)); + assert_eq!(guard.check(&a, false), Err(EPERM)); + assert_eq!(guard.check(&a, true), Ok(())); + assert!(guard.take_save_previous()); + assert!(!guard.take_save_previous()); + assert_eq!(guard.check(&b, true), Err(EPERM)); + assert_eq!(guard.check(&a, true), Err(EPERM)); + // Not adopted. + assert!(bytes.borrow().is_empty()); + Ok(()) + } } diff --git a/drivers/soc/apple/xart_store.rs b/drivers/soc/apple/xart_store.rs index 9901912d8d4ddd..da46491b34f8ce 100644 --- a/drivers/soc/apple/xart_store.rs +++ b/drivers/soc/apple/xart_store.rs @@ -353,6 +353,9 @@ impl Store { if let Some(guard) = self.guard.as_mut() { guard.check(key, true)?; + if guard.take_save_previous() { + self.save_previous(key)?; + } } let old = self.find(key); @@ -392,6 +395,33 @@ impl Store { Ok(()) } + /// Saves the current value of `key` before the guard's boot policy + /// rewrite of it, and logs the rewrite. Refuses it when that fails. + fn save_previous(&mut self, key: &Key) -> Result<()> { + let saved = match self.read(key) { + Ok(Some(value)) => crate::xart_guard::save_previous(key, &value), + Ok(None) => Err(ENOENT), + Err(e) => Err(e), + }; + match saved { + Ok(()) => { + pr_notice!( + "xART guard: allowed one rewrite of kind-{} record {} for a boot policy change; its previous value is in {}\n", + key.kind, + crate::xart_guard::Id(&key.uuid), + crate::xart_guard::PREVIOUS_PATH + ); + Ok(()) + } + Err(e) => { + if let Some(guard) = self.guard.as_mut() { + guard.refuse_unsaved(key, e); + } + Err(EPERM) + } + } + } + pub(crate) fn delete(&mut self, key: &Key) -> Result { if !valid_key(key) { return Err(EINVAL); From 8ee9bb2ffbdc4e24c0f7f85d54b97a3d9e5bee85 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Wed, 28 Oct 2026 22:07:27 +1100 Subject: [PATCH 4/4] tools/aurora-sep: keep Touch ID across a boot policy change, and never hold the boot for it aurora-sep.service was ordered before multi-user.target, so a boot whose enclave did not come up waited for the loader's full two-minute timeout. On a J616s after a Stage 1 reinstall, userspace took 2 min 1.6 s. It now has no ordering before multi-user.target. fprintd and aurora-sep-ready still wait for it, and the login screen no longer does. aurora-sep-load retried the seal every 100 ms for those two minutes even when the xART guard had refused the enclave's write, which does not go away by waiting. It now stops at the first refusal and says what happened and what to run. The same J616s reached graphical.target in 11.1 s, with one seal failure logged instead of about 1,100. The driver now follows a boot policy change by itself. When it logs that it did, aurora-sep-load notes the m1n1, iBoot and OS firmware versions the boot came up with. For a change it could not follow, aurora-sep-policy-change backs up the gigalocker, the driver's host files and the fingerprints, then arms the driver's one-time allowance: with no arguments for the record this boot refused, or with --expect before a planned change. XART-SAFETY.md describes the event, the automatic update and the allowance. The Arch package also gets the aurora-sep-greeter-refresh.service link that its PKGBUILD already lists. Assisted-by: LLM Signed-off-by: Ryan Murray --- tools/aurora-sep/XART-SAFETY.md | 71 ++++++ tools/aurora-sep/aurora-sep-policy-change | 215 ++++++++++++++++++ tools/aurora-sep/aurora-sep.service | 8 +- tools/aurora-sep/load-driver | 33 +++ .../packaging/arch/aurora-sep/PKGBUILD | 11 +- .../aurora-sep-greeter-refresh.service | 1 + .../arch/aurora-sep/aurora-sep-policy-change | 1 + .../packaging/fedora/aurora-sep.spec | 8 + 8 files changed, 343 insertions(+), 5 deletions(-) create mode 100755 tools/aurora-sep/aurora-sep-policy-change create mode 120000 tools/aurora-sep/packaging/arch/aurora-sep/aurora-sep-greeter-refresh.service create mode 120000 tools/aurora-sep/packaging/arch/aurora-sep/aurora-sep-policy-change diff --git a/tools/aurora-sep/XART-SAFETY.md b/tools/aurora-sep/XART-SAFETY.md index b8282abc5250e6..4bc0acb07fe1b4 100644 --- a/tools/aurora-sep/XART-SAFETY.md +++ b/tools/aurora-sep/XART-SAFETY.md @@ -100,6 +100,8 @@ the kernel log names the refused kind. What to do depends on the case: until it has been checked there. - A warm-attach Mac set up under the guard whose verify is refused: report the log line. `xart_guard=0` restores use at the cost of the protection. +- After a boot policy change (a new Stage 1, another boot object), see + "Boot policy changes" below: one record, one boot, with a backup first. - A list that could not be read: every record that existed at boot is protected and nothing can be adopted, so new records cannot be written either. @@ -110,6 +112,75 @@ the kernel log names the refused kind. What to do depends on the case: Turning the guard back on later does not list the records written while it was off. +### Boot policy changes + +Installing a new Stage 1, changing the boot object, or converting the boot +mode changes the boot policy the Mac keeps for Linux. The first time +Linux's identity keybag is unlocked under the new policy (`CHANGE_LOCK_STATE` +in `refkey.rs`, at the loader's first trusted-key seal), the enclave +rewrites one session record that already existed. Linux did not create it, +so the guard refuses it. The enclave then never answers the unlock, the +machine ref-key stays down, and every trusted-key seal fails with EIO. The +keybag, the ref-key and the enrolled fingerprints are untouched, and since +the write was refused, so is the record. + +This was seen on the MacBook Pro M4 Pro (T6040, J616s) on 2026-10-28, after +a Stage 1 reinstall that changed only the kernel collection hash (`coih`). +The same kernel, under the old policy, unlocked the keybag without any +session record write. Linux had never created a record there: the guard +ran from Linux's first boot and its list stayed empty. + +Under an unchanged policy that first unlock rewrites no session record at +all (every J616s boot before the change). So the driver treats a rewrite +inside it as the policy change and lets exactly one through, by itself, on +the first boot after the change: + +- only during the first unlock of an identity keybag that already existed, + once per boot; a keybag or ref-key created this boot closes the window; +- only one kind-4 session record, only a rewrite, never a delete or a + shared root, and the record is not added to Linux's list; +- only once the record's previous value is durable in + `/var/lib/aurora-sep-xart-policy-previous.bin` (kind, session id, length, + CRC, then the value); if it cannot be saved, the write is refused. + +The kernel log names the record ("allowed one rewrite of kind-4 record +... for a boot policy change"), and `aurora-sep-load` logs the m1n1, iBoot +and OS firmware versions the boot came up with. + +When the driver did not let it through (a kernel from before this, or a +second record), `aurora-sep-policy-change` (root) allows it on the next +boot: + +- After the change, with Touch ID down and the refusal in this boot's log, + run it with no arguments. It takes the session id from the refusal. +- Before a planned change, run it with `--expect`. The record cannot be + named in advance, so the allowance covers the first existing kind-4 + record the enclave asks to rewrite. The identity unlock is the first + thing that asks. + +Either way it first copies the whole 6 MiB gigalocker extent, the driver's +host files and `/var/lib/fprint` to +`/var/lib/aurora-rollback/sep-policy-change-