From 38e5ee6851454216667b33b1cc9c8f799bc17927 Mon Sep 17 00:00:00 2001 From: Audrey Tang Date: Sat, 24 Oct 2026 11:29:40 +0800 Subject: [PATCH 1/8] dt-bindings: apple: Add T8132 SEP DART and ASC mailbox compatibles The M4 (T8132) SEP DART and SEP mailbox are the same parts as on T8122. Add apple,t8132-dart, with the apple,t8110-dart fallback, and apple,t8132-asc-mailbox, with the apple,asc-mailbox-v4 fallback. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Audrey Tang --- Documentation/devicetree/bindings/iommu/apple,dart.yaml | 1 + Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml | 1 + 2 files changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/iommu/apple,dart.yaml b/Documentation/devicetree/bindings/iommu/apple,dart.yaml index 44a0499ada2cbc..ad3f8e90338618 100644 --- a/Documentation/devicetree/bindings/iommu/apple,dart.yaml +++ b/Documentation/devicetree/bindings/iommu/apple,dart.yaml @@ -37,6 +37,7 @@ properties: - enum: - apple,t6020-dart - apple,t8122-dart + - apple,t8132-dart - apple,t8140-dart - apple,t8142-dart - const: apple,t8110-dart diff --git a/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml b/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml index 8d66dc77c0a54e..7e7644c1732e34 100644 --- a/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml +++ b/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml @@ -31,6 +31,7 @@ properties: - apple,t8103-asc-mailbox - apple,t8112-asc-mailbox - apple,t8122-asc-mailbox + - apple,t8132-asc-mailbox - apple,t8140-asc-mailbox - apple,t8142-asc-mailbox - apple,t6000-asc-mailbox From 8728d41365f251f359e9d11ad39ab04daf935ac7 Mon Sep 17 00:00:00 2001 From: Audrey Tang Date: Sat, 24 Oct 2026 11:29:42 +0800 Subject: [PATCH 2/8] arm64: dts: apple: t8132: Add the SEP, its DART and its mailbox Describe the M4 SEP the way t8122.dtsi does: the SEP and its DART disabled, the DART carrying the SEP's own IOVA window from the J715 ADT (dart-sep vm-base-0 0x10000004000, vm-size-0 0xffff0000) with no offset, and the ASC mailbox inside the SEP wrapper at +0x8000. The ADT lists the mailbox interrupts as 390 389 392 391. In that order the recv-not-empty slot holds the line that is asserted while the receive FIFO is empty; the ASC v4 mailbox has no IRQ acknowledge, so starting the channel polls an empty FIFO in hard IRQ context and the machine freezes. Use 389 390 391 392, the order the T8122 SEP mailbox and the other T8132 ASC mailboxes use. No board adds the sep alias yet. With the alias, m1n1 hands the SEP its firmware region and manifests, but current m1n1 keeps a pointer from fdt_get_alias() across inserting memory-region, and on T8132 its SEP ROM random request leaves the running sepOS no longer reading its mailbox. Both are fixed in Kb2uka/Omarchy-M4-Native#168; the alias can follow once the bootloader carries them. Tested on a 15-inch M4 MacBook Air (J715) with equivalent nodes in the Omarchy M4 kit tree: the mailbox starts without freezing and the SEP answers. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Audrey Tang --- arch/arm64/boot/dts/apple/t8132.dtsi | 44 ++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8132.dtsi b/arch/arm64/boot/dts/apple/t8132.dtsi index afec92a0601562..e6d643950d2441 100644 --- a/arch/arm64/boot/dts/apple/t8132.dtsi +++ b/arch/arm64/boot/dts/apple/t8132.dtsi @@ -354,6 +354,50 @@ }; }; + /* + * iBoot hands over a running SEP. Keep Linux off its DART at boot; + * apple_sep enables it at module initialization. The SEP only + * accepts IOVAs in this window, which carries the BIT(40) alias + * the DART translates (ADT vm-base-0 0x10000004000). + */ + sep_dart: iommu@3a8c80000 { + compatible = "apple,t8132-dart", "apple,t8110-dart"; + reg = <0x3 0xa8c80000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = ; + #iommu-cells = <1>; + apple,dma-range = /bits/ 64 <0x10000004000 0xffff0000>; + apple,dma-offset = /bits/ 64 <0x0>; + status = "disabled"; + }; + + sep: sep@3aa600000 { + compatible = "apple,sep"; + reg = <0x3 0xaa600000 0x0 0x88000>; + mboxes = <&sep_mbox>; + mbox-names = "mbox"; + iommus = <&sep_dart 0>; + status = "disabled"; + }; + + /* + * The ADT lists these interrupts as 390 389 392 391. In that order + * the recv-not-empty slot holds the line that is asserted while the + * receive FIFO is empty, and starting the channel never returns. + */ + sep_mbox: mbox@3aa608000 { + compatible = "apple,t8132-asc-mailbox", "apple,asc-mailbox-v4"; + reg = <0x3 0xaa608000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = , + , + , + ; + interrupt-names = "send-empty", "send-not-empty", + "recv-empty", "recv-not-empty"; + #mbox-cells = <0>; + }; + i2c0: i2c@3ad010000 { compatible = "apple,t8132-i2c", "apple,t8103-i2c"; reg = <0x3 0xad010000 0x0 0x4000>; From e80d022ccd9844002dd19241cc3667dbddbbfe94 Mon Sep 17 00:00:00 2001 From: Audrey Tang Date: Sat, 24 Oct 2026 11:29:42 +0800 Subject: [PATCH 3/8] soc: apple: sep: Add a T8132 (MacBook Air M4) platform profile The 15-inch M4 MacBook Air (J715) hands over a running SEP (ADT sepfw-booted), like the M3 Air, so this is T8122's warm registration, shared-memory geometry, variant-5 key store and xART guard default. Its SEP DART window is the ADT's own, 0x100_0000_4000 + 0xffff0000, given as a range with no offset. This matches what t8132.dtsi carries, and unlike the BIT(40) offset window it also reaches the SEP on kernels whose DART driver does not apply apple,dma-offset. The Mesa sensor is on spi2 at 0x3ad108000; its identity is unchecked, so capture stays unqualified. Only J715 selects the profile. Tested on a J715 (macOS 27.0.1) with an earlier port of this driver on the Omarchy M4 kit kernel (7.1.9), the DART window set the same way and the m1n1 fixes from Kb2uka/Omarchy-M4-Native#168: the SEP attaches with 12 endpoints, the identity keybag is provisioned, a P-256 key held by the SEP signs through OpenSSH, and the same key signs after a reboot with the driver loaded at boot. With the 0..4 GiB offset window on that kernel the SEP never answered. Not tested: this tree on hardware, the xART guard on J715 (the tested Mac provisioned before the guard existed), and Touch ID. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Audrey Tang --- drivers/soc/apple/profile.rs | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/drivers/soc/apple/profile.rs b/drivers/soc/apple/profile.rs index 6803c1464652e0..df5482e35ebd03 100644 --- a/drivers/soc/apple/profile.rs +++ b/drivers/soc/apple/profile.rs @@ -152,6 +152,17 @@ const DART_T8112: DartWindow = DartWindow { range: [0x0, 0x4000, 0x0, 0xffff_0000], }; +/// The T8132 SEP DART input aperture is the BIT(40) alias itself, +/// 0x100_0000_4000 + 0xffff0000 (J715 ADT `dart-sep` vm-base-0 and +/// vm-size-0), given as a range with no offset. Unlike [`DART_HIGH_ALIAS`] +/// it reaches the SEP whether or not the DART driver applies +/// `apple,dma-offset`. +const DART_T8132: DartWindow = DartWindow { + name: "no offset, range 0x10000004000..+0xffff0000", + offset: [0x0, 0x0], + range: [0x100, 0x4000, 0x0, 0xffff_0000], +}; + pub(crate) struct PlatformProfile { pub(crate) name: &'static str, /// Capacity of the boot shared-memory window. The layout is still checked @@ -425,6 +436,23 @@ pub(crate) const T8122: PlatformProfile = PlatformProfile { ..T8112 }; +/// MacBook Air 15-inch M4 (J715). The J715 ADT has `sepfw-booted`: iBoot +/// hands over a running SEP, so this is T8122's warm registration, +/// shared-memory geometry and variant-5 key store. The SEP DART window is the +/// ADT's own (see [`DART_T8132`]). The Mesa sensor sits on spi2 at +/// `0x3ad108000`; its identity and wiring are unchecked, so capture stays +/// unqualified. Like the M3, its enclave is shared with macOS. +pub(crate) const T8132: PlatformProfile = PlatformProfile { + name: "T8132/J715", + sensor: SensorProfile { + controller_base: 0x3_ad10_8000, + capture_qualified: false, + ..T8122.sensor + }, + dart_window: &DART_T8132, + ..T8122 +}; + static_assert!(T8103.shmem_capacity == 0x30000); static_assert!(T6020.shmem_capacity == 0x40000); static_assert!(T8140.shmem_capacity == 0x40000); @@ -440,6 +468,8 @@ static_assert!(T8112.sensor.controller_base == T8103.sensor.controller_base); static_assert!(T8122.shmem_capacity == T8112.shmem_capacity); static_assert!(T8122.sensor.controller_base == 0x2a1108000); static_assert!(T8122.wide_dma_mask); +static_assert!(T8132.wide_dma_mask); +static_assert!(T8132.shmem_capacity == T8122.shmem_capacity); /// Whether the machine root declares `compatible`. /// @@ -586,6 +616,10 @@ pub(crate) fn detect() -> Result<&'static PlatformProfile> { if machine_has(b"apple,t8122") && (machine_has(b"apple,j613") || machine_has(b"apple,j615")) { return Ok(&T8122); } + // Only the board whose ADT was read. + if machine_has(b"apple,t8132") && machine_has(b"apple,j715") { + return Ok(&T8132); + } Err(ENODEV) } @@ -630,6 +664,10 @@ mod tests { assert!(T8122.wide_dma_mask); assert!(T8122.shmem_capacity == T8112.shmem_capacity); assert!(T8122.sensor.controller_base == 0x2_a110_8000); + assert!(!T8132.nonce_session); + assert!(T8132.wide_dma_mask); + assert!(T8132.xart_guard == T8122.xart_guard); + assert!(!T8132.sensor.capture_qualified); } } @@ -665,4 +703,16 @@ mod dart_window_tests { assert_eq!(range(profile.dart_window), (0, 1 << 32)); } } + + #[test] + fn t8132_uses_the_adt_window_without_an_offset() { + assert_eq!(offset(T8132.dart_window), 0); + assert_eq!( + range(T8132.dart_window), + (0x100_0000_4000, 0x100_0000_4000 + 0xffff_0000) + ); + // The window sits at the BIT(40) alias, inside a 42-bit DMA mask. + assert!(range(T8132.dart_window).0 >= 1 << 40); + assert!(range(T8132.dart_window).1 <= 1 << 42); + } } From 92492cc33e41d0664bfb7a441ac81a6fabfead70 Mon Sep 17 00:00:00 2001 From: Audrey Tang Date: Mon, 26 Oct 2026 12:13:06 -0700 Subject: [PATCH 4/8] soc: apple: sep: Authenticate J715 Touch ID sessions Co-authored-by: sisyphus-dev-ai --- Documentation/input/devices/j715-touchid.rst | 54 +++++++++ drivers/soc/apple/profile.rs | 118 ++++++++++++++++++- drivers/soc/apple/sbio.rs | 95 +++++++++++---- 3 files changed, 241 insertions(+), 26 deletions(-) create mode 100644 Documentation/input/devices/j715-touchid.rst diff --git a/Documentation/input/devices/j715-touchid.rst b/Documentation/input/devices/j715-touchid.rst new file mode 100644 index 00000000000000..27f3a0c4dfc15a --- /dev/null +++ b/Documentation/input/devices/j715-touchid.rst @@ -0,0 +1,54 @@ +J715 Touch ID session inputs +=========================== + +The T8132/J715 profile uses nonce authentication and source-6 calibration. +It does not change the other boards' session policies, xART guards or +persistence rules. It still requires a successful sensor power cycle before +registration. + +Root-key firmware +----------------- + +``apple/msrk-j715.bin`` must contain this machine's own FDR MSRk data: the +complete, unmodified body supplied to SBIO SET_MSRK_DATA (opcode ``0x86``). +The qualified input is 10,848 bytes, as in the successful J715 candidate. +Do not substitute J700's signed-container file, strip or add a wrapper, pad +another input to this size, or use another machine's data. + +The driver checks the length, not a private identifier or hash. It does not +parse or authenticate the FDR container; a matching length is not evidence +of validity. The enclave must accept the unmodified data. Acquisition and +container verification belong to provisioning, not the kernel driver. +No automatic extraction or alternate-file fallback is provided. + +After SENSOR_NONCE, the driver first requests SESSION_SHARE normally. +Only an explicit status ``0x16`` on J715 triggers the firmware request and +upload. A successful upload permits exactly one further SESSION_SHARE +request within that session attempt. A missing file, wrong length, failed +upload, failed transfer or refused retry stops the attempt. A successful +initial share does not read the firmware file. + +J700 retains ``apple/msrk-j700.bin``, the nonempty signed-container rule, +and its upload before SESSION_SHARE once per enclave lifetime. It does not +use J715's refusal recovery. + +Calibration and validation +-------------------------- + +The existing sensor ``firmware-name`` property, or its existing default +``apple/mesa_calibration.bin``, supplies calibration. J715 requires its own +source-6 FSC2 data from the successful setup, not the older extracted FDR3 +input. The existing calibration encoder prefixes the unchanged body with a +four-byte source word. This patch does not add a calibration fallback. + +With ``CONFIG_APPLE_SEP_KUNIT_TEST=y``, the +``apple_sep_sensor_root_key`` suite tests board selection, input-length +boundaries and refusal classification. Also run ``apple_sep_profile``, +``apple_sep_dart_window`` and ``apple_sep_registration`` to cover the +existing profile and registration behavior. + +The old candidate's successful enrollment and same-boot verification do not +qualify this upstream kernel. Hardware validation must establish sensor +readiness, enrollment, matching and persistence across a cold boot, with +the existing power-cycle and registration guards enabled. Login integration +is userspace work; disk unlock is outside this support. diff --git a/drivers/soc/apple/profile.rs b/drivers/soc/apple/profile.rs index df5482e35ebd03..c7102c6a50fb3b 100644 --- a/drivers/soc/apple/profile.rs +++ b/drivers/soc/apple/profile.rs @@ -55,6 +55,40 @@ pub(crate) enum IdentitySource { HostPersisted, } +/// The root-key input and loading point verified for each nonce-session board. +#[derive(Clone, Copy, PartialEq, Eq)] +pub(crate) enum SensorRootKey { + None, + /// Preserve J700's signed container upload before SESSION_SHARE. + J700, + /// J715's device-specific FDR MSRk body, uploaded only after status 0x16. + J715, +} + +impl SensorRootKey { + pub(crate) const fn firmware(self) -> Option<&'static CStr> { + match self { + Self::None => None, + Self::J700 => Some(c"apple/msrk-j700.bin"), + Self::J715 => Some(c"apple/msrk-j715.bin"), + } + } + + /// Only the observed J715 FDR body size is qualified. The enclave checks + /// its authenticity; a matching length alone does not authenticate it. + pub(crate) const fn accepts_length(self, length: usize) -> bool { + match self { + Self::None => false, + Self::J700 => length != 0, + Self::J715 => length == 10_848, + } + } + + pub(crate) fn recover_share(self, status: Option) -> bool { + self == Self::J715 && status == Some(0x16) + } +} + /// SPI mode as the device tree spells it. Mode 1 is CPOL=0/CPHA=1 (`spi-cpha`); /// mode 2 is CPOL=1/CPHA=0 (`spi-cpol`). #[derive(Clone, Copy, PartialEq, Eq)] @@ -187,6 +221,7 @@ pub(crate) struct PlatformProfile { pub(crate) keybag_create: KeybagCreate, /// Require nonce authentication and signed sensor material before capture. pub(crate) nonce_session: bool, + pub(crate) sensor_root_key: SensorRootKey, /// Key-store protocol generation (see [`KeyStore`]). pub(crate) key_store: KeyStore, /// Platforms with reboot-tested owner export and user-before-master saves. @@ -229,6 +264,7 @@ pub(crate) const T8103: PlatformProfile = PlatformProfile { }, persistent_enrol: true, nonce_session: false, + sensor_root_key: SensorRootKey::None, // macOS shares this enclave: keep Linux to its own xART records. xart_guard: 1, }; @@ -269,6 +305,7 @@ pub(crate) const T6000: PlatformProfile = PlatformProfile { }, persistent_enrol: true, nonce_session: false, + sensor_root_key: SensorRootKey::None, // As T8103. On J316s, creating the identity keybag also rewrites a // session record that predates Linux. The guard refuses that, so the // keybag can only be created there with xart_guard=0. @@ -304,6 +341,7 @@ pub(crate) const T6020: PlatformProfile = PlatformProfile { key_store: KeyStore::Variant5, persistent_enrol: true, nonce_session: false, + sensor_root_key: SensorRootKey::None, // A warm-attach enclave shared with macOS, as on T8112. xart_guard: 1, }; @@ -359,6 +397,7 @@ pub(crate) const T8140: PlatformProfile = PlatformProfile { arg: -1, }, nonce_session: true, + sensor_root_key: SensorRootKey::J700, // Linux records from before the guard's list exist here, and Linux has // left the macOS records unchanged on this platform. xart_guard: 0, @@ -405,6 +444,7 @@ pub(crate) const T8112: PlatformProfile = PlatformProfile { key_store: KeyStore::Variant5, persistent_enrol: true, nonce_session: false, + sensor_root_key: SensorRootKey::None, // Guarded from its first Linux boot (2026-10-16): no record refused. xart_guard: 1, }; @@ -442,8 +482,12 @@ pub(crate) const T8122: PlatformProfile = PlatformProfile { /// ADT's own (see [`DART_T8132`]). The Mesa sensor sits on spi2 at /// `0x3ad108000`; its identity and wiring are unchecked, so capture stays /// unqualified. Like the M3, its enclave is shared with macOS. +/// The successful J715 session uses nonce authentication, FDR MSRk recovery +/// after SESSION_SHARE status 0x16, and source-6 FSC2 calibration. pub(crate) const T8132: PlatformProfile = PlatformProfile { name: "T8132/J715", + nonce_session: true, + sensor_root_key: SensorRootKey::J715, sensor: SensorProfile { controller_base: 0x3_ad10_8000, capture_qualified: false, @@ -664,13 +708,85 @@ mod tests { assert!(T8122.wide_dma_mask); assert!(T8122.shmem_capacity == T8112.shmem_capacity); assert!(T8122.sensor.controller_base == 0x2_a110_8000); - assert!(!T8132.nonce_session); + assert!(T8132.nonce_session); assert!(T8132.wide_dma_mask); assert!(T8132.xart_guard == T8122.xart_guard); assert!(!T8132.sensor.capture_qualified); } } +#[cfg(CONFIG_APPLE_SEP_KUNIT_TEST)] +#[kernel::macros::kunit_tests(apple_sep_sensor_root_key)] +mod root_key_tests { + use super::*; + + #[test] + fn non_nonce_boards_never_load_or_recover_a_root_key() { + // Given the existing non-nonce profiles, including inherited ones. + for profile in [&T8103, &T6000, &T6020, &T6020_SEPOS13, &T8112, &T8122] { + // When selecting their root-key policy. + let policy = profile.sensor_root_key; + // Then no file, upload or recovery is selected. + assert!(!profile.nonce_session); + assert!(policy.firmware().is_none()); + assert!(!policy.accepts_length(10_848)); + assert!(!policy.recover_share(Some(0x16))); + } + } + + #[test] + fn j700_preserves_its_nonempty_container_without_share_recovery() { + // Given J700's existing signed-container policy. + let policy = T8140.sensor_root_key; + // When selecting firmware and handling the observed refusal. + let name = policy.firmware(); + // Then the existing name and nonempty input rule remain in force. + assert!(T8140.nonce_session); + assert!(policy == SensorRootKey::J700); + assert!(name == Some(c"apple/msrk-j700.bin")); + assert!(!policy.accepts_length(0)); + assert!(policy.accepts_length(1)); + assert!(policy.accepts_length(1726)); + assert!(!policy.recover_share(Some(0x16))); + } + + #[test] + fn j715_accepts_only_the_qualified_fdr_body_length() { + // Given J715's nonce-session profile. + let policy = T8132.sensor_root_key; + // When selecting firmware and checking input sizes. + let name = policy.firmware(); + // Then the public board name selects only the qualified FDR size. + assert!(T8132.nonce_session); + assert!(policy == SensorRootKey::J715); + assert!(name == Some(c"apple/msrk-j715.bin")); + assert!(policy.accepts_length(10_848)); + for length in [0, 1, 1726, 10_847, 10_849, usize::MAX] { + assert!(!policy.accepts_length(length)); + } + } + + #[test] + fn j715_recovers_only_an_explicit_share_status_16() { + // Given J715's recovery policy. + let policy = T8132.sensor_root_key; + // When classifying answered and missing statuses. + let recover = policy.recover_share(Some(0x16)); + // Then only the observed refusal selects the single retry path. + assert!(recover); + for status in [ + None, + Some(0), + Some(1), + Some(0x15), + Some(0x17), + Some(u32::MAX), + ] { + assert!(!policy.recover_share(status)); + } + } +} + #[cfg(CONFIG_APPLE_SEP_KUNIT_TEST)] #[kernel::macros::kunit_tests(apple_sep_dart_window)] mod dart_window_tests { diff --git a/drivers/soc/apple/sbio.rs b/drivers/soc/apple/sbio.rs index 9c69ca184c6912..58998082b7678c 100644 --- a/drivers/soc/apple/sbio.rs +++ b/drivers/soc/apple/sbio.rs @@ -2165,7 +2165,42 @@ impl SepData { } } - /// SENSOR_NONCE, the signed root key once a boot, and the session share. + fn load_sensor_root_key(&self) -> bool { + let policy = self.profile.sensor_root_key; + let Some(name) = policy.firmware() else { + return false; + }; + let firmware = match kernel::firmware::Firmware::request(name, &self.dev) { + Ok(firmware) => firmware, + Err(error) => { + dev_err!( + self.dev, + "sensor: root-key firmware {} unavailable: {:?}\n", + name, + error + ); + return false; + } + }; + if !policy.accepts_length(firmware.data().len()) { + dev_err!( + self.dev, + "sensor: root-key firmware {} has unsupported length {}\n", + name, + firmware.data().len() + ); + return false; + } + if !self.sensor_session_request(0x86, c"SENSOR_ROOT_KEY", firmware.data()) { + self.sensor_step_failed(c"SENSOR_ROOT_KEY"); + return false; + } + self.sensor_key_loaded.store(true, Relaxed); + self.sensor_trace(c"SENSOR_ROOT_KEY"); + true + } + + /// SENSOR_NONCE, the board's root-key policy, and the session share. fn sensor_nonce_session(&self, nonce: &[u8; 32]) -> bool { if *module_parameters::sensor_test_fault.value() != 0 && !self.sensor_test_fault_done.xchg(true, Relaxed) @@ -2182,28 +2217,11 @@ impl SepData { } self.sensor_trace(c"SENSOR_NONCE"); - if !self.sensor_key_loaded.load(Relaxed) { - let firmware = match kernel::firmware::Firmware::request( - c"apple/msrk-j700.bin", &self.dev, - ) { - Ok(firmware) => firmware, - Err(error) => { - dev_err!( - self.dev, - "sensor: signed root-key container unavailable: {:?}\n", - error - ); - return false; - } - }; - if firmware.data().is_empty() - || !self.sensor_session_request(0x86, c"SENSOR_ROOT_KEY", firmware.data()) - { - self.sensor_step_failed(c"SENSOR_ROOT_KEY"); - return false; - } - self.sensor_key_loaded.store(true, Relaxed); - self.sensor_trace(c"SENSOR_ROOT_KEY"); + if self.profile.sensor_root_key == profile::SensorRootKey::J700 + && !self.sensor_key_loaded.load(Relaxed) + && !self.load_sensor_root_key() + { + return false; } // Each identification starts a new sensor-side exchange, even though // the signed key remains loaded for the lifetime of the enclave. @@ -2506,8 +2524,35 @@ impl SepData { } fn establish_session(&self) -> bool { - let Some(share) = self.sensor_enclave_step(&crate::sbio::sbio_request_session_share()) - else { + let op = crate::sbio::sbio_request_session_share(); + let done = match self.sbio_transfer(&op) { + Ok(done) => done, + Err(error) => { + dev_warn!(self.dev, "sensor: SESSION_SHARE transfer failed: {:?}\n", error); + self.sensor_step_failed(c"SESSION_SHARE"); + return false; + } + }; + let share = if done.status.is_ok() { + self.sensor_trace(c"SESSION_SHARE"); + done.payload + } else if self + .profile + .sensor_root_key + .recover_share(done.status.answered()) + { + dev_info!(self.dev, "sensor: SESSION_SHARE status 0x16; loading FDR MSRk\n"); + if !self.load_sensor_root_key() { + return false; + } + // One retry only: this step does not enter the recovery path again. + let Some(share) = self.sensor_enclave_step(&op) else { + return false; + }; + share + } else { + dev_warn!(self.dev, "sensor: SESSION_SHARE refused with status {}\n", done.status); + self.sensor_step_failed(c"SESSION_SHARE"); return false; }; From 2526790cdc06336cd2397eb51e347e9889d41c2b Mon Sep 17 00:00:00 2001 From: Audrey Tang Date: Tue, 27 Oct 2026 11:36:53 -0700 Subject: [PATCH 5/8] soc: apple: sep: Report a rejected sensor root-key container load_sensor_root_key returned without sensor_step_failed when the container length was rejected, so an empty msrk-j700.bin lost the SENSOR_ROOT_KEY step failure it reported before the profile rework. Report it again for every rejected length. Co-authored-by: sisyphus-dev-ai --- drivers/soc/apple/sbio.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/soc/apple/sbio.rs b/drivers/soc/apple/sbio.rs index 58998082b7678c..e96a270c4385f3 100644 --- a/drivers/soc/apple/sbio.rs +++ b/drivers/soc/apple/sbio.rs @@ -2189,6 +2189,7 @@ impl SepData { name, firmware.data().len() ); + self.sensor_step_failed(c"SENSOR_ROOT_KEY"); return false; } if !self.sensor_session_request(0x86, c"SENSOR_ROOT_KEY", firmware.data()) { From c39419116343e54acf735a1a8521dddb7efb8545 Mon Sep 17 00:00:00 2001 From: MuBai-He <51275418+MuBai-He@users.noreply.github.com> Date: Wed, 28 Oct 2026 04:46:55 +0800 Subject: [PATCH 6/8] soc: apple: sep: Add a J713 (MacBook Air 13-inch M4) profile The 13-inch M4 MacBook Air (J713) describes the same SEP and sensor wiring as J715 in its ADT: sepfw-booted, the same dart-sep window, and a Mesa sensor on spi2 at 0x3ad108000. Its sensor session uses the same nonce authentication, and SESSION_SHARE answers 0x16 until the machine's own FDR MSRk body is loaded. Add T8132_J713, the J715 profile with SensorRootKey::J713. It names apple/msrk-j713.bin and follows J715's 10,848-byte rule and its single retry after status 0x16. The sensor description records what J713 reads back: ID 0x3356 in mode 2. Select it only on apple,j713. Tested on one J713 with this profile ported to the Omarchy M4 kit kernel 7.1.9 and the default xart_guard of 1. The first SESSION_SHARE returned 0x16, msrk-j713 was loaded and the retry was accepted. One finger was enrolled and matched, and another finger was rejected. After a cold boot the enrolment was restored from the Catacomb files and matched again. The guard refused no write. The identity keybag was created before this run by a development build with the guard off; j713-touchid.rst explains why. KUnit ran on the same J713 at insmod, with this tree's apple_sep suites built into that port and kunit.enable=1: all 11 suites passed, 124 cases including the three J713 ones, with no failures or skips. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: MuBai-He <51275418+MuBai-He@users.noreply.github.com> --- Documentation/input/devices/j713-touchid.rst | 47 +++++++++++ drivers/soc/apple/profile.rs | 89 ++++++++++++++++++-- 2 files changed, 131 insertions(+), 5 deletions(-) create mode 100644 Documentation/input/devices/j713-touchid.rst diff --git a/Documentation/input/devices/j713-touchid.rst b/Documentation/input/devices/j713-touchid.rst new file mode 100644 index 00000000000000..4ce2232a6f4bca --- /dev/null +++ b/Documentation/input/devices/j713-touchid.rst @@ -0,0 +1,47 @@ +J713 Touch ID session inputs +=========================== + +The T8132/J713 profile (MacBook Air 13-inch, M4) is the J715 profile with +J713's own root-key file. Read j715-touchid.rst first: the nonce session, +the single SESSION_SHARE retry after status ``0x16``, the length rule and +the calibration rules are the same, and so are the provisioning limits. + +Root-key firmware +----------------- + +``apple/msrk-j713.bin`` must contain this machine's own FDR MSRk data, the +complete, unmodified body supplied to SBIO SET_MSRK_DATA (opcode ``0x86``). +The observed J713 body is 10,848 bytes, the same length as J715's. The +signed IMG4 payload alone (1,726 bytes on the tested machine) is refused by +the enclave with status ``0x1c``; do not substitute it or J700's container. +J713 never reads ``apple/msrk-j715.bin``. + +Device tree +----------- + +The sensor is on spi2 (``0x3ad108000``), chip select 0, powered by NUB GPIO +28 (active high). It answers in SPI mode 2, so the board node sets +``spi-cpol`` and not ``spi-cpha``; the sensor ID reads back as ``0x3356``. +The data-ready line (AP GPIO 199 in the ADT) is not described, so the +driver polls. Calibration is the machine's own source-6 FSC2 data under +``apple/mesacal-j713.bin`` (130,427 bytes on the tested machine). + +Validation +---------- + +On one J713, with this profile ported to the Omarchy M4 kit kernel 7.1.9 +and the default ``xart_guard`` of 1: + +- the first SESSION_SHARE returned ``0x16``, the J713 body was loaded and + the retry was accepted; +- a fingerprint was enrolled and matched, and another finger was rejected; +- after a cold boot the driver restored the enrolment from the Catacomb + files and the same finger matched again; +- the guard refused no write. The only change in the gigalocker was the + enclave rewriting a shared root record, which guard 1 permits. + +The identity keybag used in that run had been created earlier by a +development build with ``xart_guard=0``. Under guard 1 that creation was +refused: after rewriting the shared root, the enclave rewrote a session +record that predates Linux. A J713 that has never had a keybag has not been +tested with the guard on. Login integration and suspend were not tested. diff --git a/drivers/soc/apple/profile.rs b/drivers/soc/apple/profile.rs index c7102c6a50fb3b..d81a47ee301361 100644 --- a/drivers/soc/apple/profile.rs +++ b/drivers/soc/apple/profile.rs @@ -63,6 +63,8 @@ pub(crate) enum SensorRootKey { J700, /// J715's device-specific FDR MSRk body, uploaded only after status 0x16. J715, + /// J713's device-specific FDR MSRk body, under J715's rules. + J713, } impl SensorRootKey { @@ -71,21 +73,23 @@ impl SensorRootKey { Self::None => None, Self::J700 => Some(c"apple/msrk-j700.bin"), Self::J715 => Some(c"apple/msrk-j715.bin"), + Self::J713 => Some(c"apple/msrk-j713.bin"), } } - /// Only the observed J715 FDR body size is qualified. The enclave checks - /// its authenticity; a matching length alone does not authenticate it. + /// Only the FDR body size observed on J715 and J713 is qualified. The + /// enclave checks its authenticity; a matching length alone does not + /// authenticate it. pub(crate) const fn accepts_length(self, length: usize) -> bool { match self { Self::None => false, Self::J700 => length != 0, - Self::J715 => length == 10_848, + Self::J715 | Self::J713 => length == 10_848, } } pub(crate) fn recover_share(self, status: Option) -> bool { - self == Self::J715 && status == Some(0x16) + matches!(self, Self::J715 | Self::J713) && status == Some(0x16) } } @@ -497,6 +501,23 @@ pub(crate) const T8132: PlatformProfile = PlatformProfile { ..T8122 }; +/// MacBook Air 13-inch M4 (J713). Its ADT matches J715's for the SEP +/// (`sepfw-booted`, the same `dart-sep` window) and for the sensor's spi2 +/// controller, so this is the J715 profile with J713's own FDR MSRk file. +/// The sensor reads back ID 0x3356 in mode 2 (CPOL=1/CPHA=0), which is what +/// the J713 device tree states. Enrolment, matching and a cold-boot restore +/// passed with the default xART guard. +pub(crate) const T8132_J713: PlatformProfile = PlatformProfile { + name: "T8132/J713", + sensor_root_key: SensorRootKey::J713, + sensor: SensorProfile { + mode: SpiMode::Mode2, + expected_id: 0x3356, + ..T8132.sensor + }, + ..T8132 +}; + static_assert!(T8103.shmem_capacity == 0x30000); static_assert!(T6020.shmem_capacity == 0x40000); static_assert!(T8140.shmem_capacity == 0x40000); @@ -660,10 +681,13 @@ pub(crate) fn detect() -> Result<&'static PlatformProfile> { if machine_has(b"apple,t8122") && (machine_has(b"apple,j613") || machine_has(b"apple,j615")) { return Ok(&T8122); } - // Only the board whose ADT was read. + // Only the boards whose ADTs were read. if machine_has(b"apple,t8132") && machine_has(b"apple,j715") { return Ok(&T8132); } + if machine_has(b"apple,t8132") && machine_has(b"apple,j713") { + return Ok(&T8132_J713); + } Err(ENODEV) } @@ -713,6 +737,24 @@ mod tests { assert!(T8132.xart_guard == T8122.xart_guard); assert!(!T8132.sensor.capture_qualified); } + + #[test] + fn j713_differs_from_j715_only_in_its_root_key_and_sensor_description() { + assert!(T8132_J713.nonce_session == T8132.nonce_session); + assert!(T8132_J713.wide_dma_mask == T8132.wide_dma_mask); + assert!(T8132_J713.xart_guard == T8132.xart_guard); + assert!(T8132_J713.persistent_enrol == T8132.persistent_enrol); + assert!(T8132_J713.shmem_capacity == T8132.shmem_capacity); + assert!(core::ptr::eq(T8132_J713.dart_window, T8132.dart_window)); + assert!(T8132_J713.sensor.controller_base == T8132.sensor.controller_base); + assert!(T8132_J713.sensor.chip_select == T8132.sensor.chip_select); + assert!(T8132_J713.sensor.max_hz == T8132.sensor.max_hz); + assert!(T8132_J713.sensor.cs_setup_ns == T8132.sensor.cs_setup_ns); + assert!(T8132_J713.sensor.cs_hold_ns == T8132.sensor.cs_hold_ns); + assert!(T8132_J713.sensor.capture_qualified == T8132.sensor.capture_qualified); + assert!(T8132_J713.sensor.mode == SpiMode::Mode2); + assert!(T8132_J713.sensor.expected_id == 0x3356); + } } #[cfg(CONFIG_APPLE_SEP_KUNIT_TEST)] @@ -785,6 +827,43 @@ mod root_key_tests { assert!(!policy.recover_share(status)); } } + + #[test] + fn j713_names_its_own_fdr_body_with_j715s_length_rule() { + // Given J713's nonce-session profile. + let policy = T8132_J713.sensor_root_key; + // When selecting firmware and checking input sizes. + let name = policy.firmware(); + // Then J713 reads its own file, never J715's, at the same size. + assert!(T8132_J713.nonce_session); + assert!(policy == SensorRootKey::J713); + assert!(name == Some(c"apple/msrk-j713.bin")); + assert!(name != T8132.sensor_root_key.firmware()); + assert!(policy.accepts_length(10_848)); + for length in [0, 1, 1726, 10_847, 10_849, usize::MAX] { + assert!(!policy.accepts_length(length)); + } + } + + #[test] + fn j713_recovers_only_an_explicit_share_status_16() { + // Given J713's recovery policy. + let policy = T8132_J713.sensor_root_key; + // When classifying answered and missing statuses. + let recover = policy.recover_share(Some(0x16)); + // Then it takes J715's single retry path and no other. + assert!(recover); + for status in [ + None, + Some(0), + Some(1), + Some(0x15), + Some(0x17), + Some(u32::MAX), + ] { + assert!(!policy.recover_share(status)); + } + } } #[cfg(CONFIG_APPLE_SEP_KUNIT_TEST)] From 5d47113987e1a08d47bb3dd7aac89e85326a1730 Mon Sep 17 00:00:00 2001 From: MuBai-He <51275418+MuBai-He@users.noreply.github.com> Date: Wed, 28 Oct 2026 04:46:55 +0800 Subject: [PATCH 7/8] dt-bindings: spi: apple: Add the T8132 SPI controller The M4 (T8132) SPI controllers are the T8103 block. Its spi2 carries the Touch ID sensor on the 13-inch MacBook Air (J713). Assisted-by: Claude:claude-opus-5-5 Signed-off-by: MuBai-He <51275418+MuBai-He@users.noreply.github.com> --- Documentation/devicetree/bindings/spi/apple,spi.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/spi/apple,spi.yaml b/Documentation/devicetree/bindings/spi/apple,spi.yaml index 4b30265686fa1f..8553561aaa144c 100644 --- a/Documentation/devicetree/bindings/spi/apple,spi.yaml +++ b/Documentation/devicetree/bindings/spi/apple,spi.yaml @@ -18,6 +18,7 @@ properties: - items: - enum: - apple,t6020-spi + - apple,t8132-spi - apple,t8140-spi - const: apple,t8103-spi - items: From 878c60efa2e5a4eb66e4a1ce47d4e08e6a00498b Mon Sep 17 00:00:00 2001 From: MuBai-He <51275418+MuBai-He@users.noreply.github.com> Date: Wed, 28 Oct 2026 04:46:55 +0800 Subject: [PATCH 8/8] arm64: dts: apple: t8132: Add spi2 and the J713 Touch ID sensor Describe spi2 and its Mesa fingerprint sensor in t8132.dtsi, both disabled, as t8122.dtsi does. Enable them on J713 with the values from its ADT (/arm-io/spi2/mesa): power on NUB GPIO 28, active high, and 20 ns chip-select setup and hold. The sensor answers in mode 2, so the board sets spi-cpol. The data-ready line (AP GPIO 199) is left out, so the driver polls. The calibration file is named per board, as on J613. The controller runs from clkref, which divides to 8 MHz exactly. The hardware run used these properties, applied as an overlay on the Omarchy M4 kit's device tree, with clkref, AIC interrupt 1056 and ps_spi2. The kit kernel's spi-apple lacks hardware chip-select timing, so that run bound a copy of this tree's driver under a private compatible. The SEP nodes stay disabled and the sep alias is not set, as on J715. dtc 1.7.2 builds t8132-j713.dtb and t8132-j715.dtb without warnings. dt_binding_check was not run. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: MuBai-He <51275418+MuBai-He@users.noreply.github.com> --- arch/arm64/boot/dts/apple/t8132-j713.dts | 21 ++++++++++++++++++++ arch/arm64/boot/dts/apple/t8132.dtsi | 25 ++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8132-j713.dts b/arch/arm64/boot/dts/apple/t8132-j713.dts index e1fc5d47f48766..962a572fdecbf3 100644 --- a/arch/arm64/boot/dts/apple/t8132-j713.dts +++ b/arch/arm64/boot/dts/apple/t8132-j713.dts @@ -11,6 +11,7 @@ #include "t8132.dtsi" #include "t8132-jxxx.dtsi" +#include #include / { @@ -33,3 +34,23 @@ &fpwm1 { status = "okay"; }; + +/* + * Mesa fingerprint sensor on spi2 (J713 ADT /arm-io/spi2/mesa): power on + * NUB GPIO 28, active high. It answers in mode 2 (CPOL=1, CPHA=0). The + * data-ready line (AP GPIO 199) is left out, so the driver polls until its + * trigger is confirmed. Native chip select only. + */ +&spi2 { + status = "okay"; +}; + +&mesa { + status = "okay"; + enable-gpios = <&pinctrl_nub 28 GPIO_ACTIVE_HIGH>; + spi-cpol; + spi-cs-setup-delay-ns = <20>; + spi-cs-hold-delay-ns = <20>; + /* Per-device factory data from this Mac's own iBoot system container. */ + firmware-name = "apple/mesacal-j713.bin"; +}; diff --git a/arch/arm64/boot/dts/apple/t8132.dtsi b/arch/arm64/boot/dts/apple/t8132.dtsi index e6d643950d2441..9bc3474ae50a17 100644 --- a/arch/arm64/boot/dts/apple/t8132.dtsi +++ b/arch/arm64/boot/dts/apple/t8132.dtsi @@ -483,6 +483,31 @@ status = "disabled"; }; + /* + * Touch ID. iBoot leaves the pads muxed and the controller uses + * its native chip select, so there is no pinctrl here. clkref + * divides to the sensor's 8 MHz exactly, and is the parent the + * J713 sensor was enrolled and matched with. + */ + spi2: spi@3ad108000 { + compatible = "apple,t8132-spi", "apple,t8103-spi"; + reg = <0x3 0xad108000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = ; + clocks = <&clkref>; + power-domains = <&ps_spi2>; + #address-cells = <1>; + #size-cells = <0>; + status = "disabled"; + + mesa: fingerprint@0 { + compatible = "apple,mesa-fingerprint"; + reg = <0>; + spi-max-frequency = <8000000>; + status = "disabled"; + }; + }; + serial0: serial@3ad200000 { compatible = "apple,s5l-uart"; reg = <0x3 0xad200000 0x0 0x1000>;