Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 38 additions & 15 deletions Documentation/ABI/testing/sysfs-driver-apple-sep
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ Date: October 2026
KernelVersion: 7.1
Contact: Chris Kearney <chris@kearneymail.com>
Description:
(RO) Version of the diag interface: "2" for the attributes
and values described in this file. Version 2 added
sensor_attach and restore; version 1 had neither.
(RO) Version of the diag interface. Version 3 distinguishes
older pin lists with matching="legacy" and can report
"usable" after a successful, persisted guarded verification.
It also exposes the effective xart_guard_pins policy.
Version 2 added sensor_attach and restore. Version 1 had
neither.

Within a version, attributes are only added, and an existing
attribute keeps its values and their meaning. A reader tests
Expand Down Expand Up @@ -294,6 +297,19 @@ Description:
refused too.
== ================================================

What: /sys/bus/platform/devices/<unit>.sep/diag/xart_guard_pins
Date: November 2026
KernelVersion: 7.2
Contact: Ryan Murray <ryan@aurorasilicon.org>
Description:
(RO) The effective pin policy at probe. 1 means that xART
writes are enabled, the guard runs at level 1, its list
loaded within the board's pin limit, and xart_guard_pins=1
enables pin use on this board. Otherwise 0. A fresh, empty
list qualifies on J313, J314s, J316s and J316c. J293 only
qualifies with previously recorded pins. This attribute does
not grant a new pin or indicate a keybag was created.

What: /sys/bus/platform/devices/<unit>.sep/diag/xart_guard_list
Date: October 2026
KernelVersion: 7.2
Expand Down Expand Up @@ -326,7 +342,7 @@ Description:
guard has refused since probe, as an unsigned decimal. A
new record that could not be added to Linux's list counts
too, since its write is refused. Only the first few
refusals are logged; this counts them all.
refusals are logged. The count saturates at 4294967295.

What: /sys/bus/platform/devices/<unit>.sep/diag/matching
Date: October 2026
Expand All @@ -340,12 +356,20 @@ Description:
the fingerprints were restored.

========== ==========================================
usable xART writes are enabled and no guard runs.
usable xART writes are enabled without a guard, or
this boot's legacy installation has saved
and returned a successful guarded match.
legacy A valid persisted keybag and a complete
older list with its spent marker and one
or more usable pins exist. Their creation
provenance is unknown. A real verification
can establish usability for this boot.
unverified A guard runs with its list loaded and has
refused nothing yet, on a warm-attach Mac
(boot "warm") or on a cold-boot Mac (boot
"cold") whose keybag was created under the
guard with xart_guard_pins=1. Whether every
"cold") whose validated keybag UUID matches
a guarded completion entry with pins enabled.
Whether every
record a match rewrites is on the list, or
is a pinned locker, is not known until a
match is tried.
Expand All @@ -355,12 +379,10 @@ Description:
(xart_guard_refusals above 0), the guard
has no list (xart_guard_list
"unavailable"), or a guard runs on a
cold-boot Mac (boot "cold") whose keybag
was not created under it. Creating the
keybag there needs xart_guard=0, which
leaves the records a match rewrites off the
list, or xart_guard_pins=1 (run on a J313
only).
cold-boot Mac (boot "cold") without proof
that its persisted keybag was committed
under the active pin policy. Legacy spent
markers alone cannot prove this.
========== ==========================================

For the guard cases the documented opt-out is xart_guard=0,
Expand All @@ -369,5 +391,6 @@ Description:
tools/aurora-sep/XART-SAFETY.md. During a boot the value
moves from "unverified" to "blocked" once the guard refuses
a write. On a cold-boot Mac with xart_guard_pins=1 it also
moves from "blocked" to "unverified" when the first keybag
creation is sent under the guard, and nowhere else.
moves from "blocked" to "unverified" after the guarded keybag
and its completion entry have been committed. A refusal
always takes precedence over that update or a later verify.
92 changes: 32 additions & 60 deletions drivers/soc/apple/diag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@
//! can block a bring-up step, and a sysfs read never reaches back into the
//! driver or the SEP.

use kernel::{
device,
prelude::*,
sync::atomic::{Atomic, Relaxed}, //
};
use kernel::{device, prelude::*};

use crate::{
profile,
registration,
xart_guard::MatchFacts, //
xart_guard::{KeybagEvidence, MatchFacts}, //
};

extern "C" {
Expand All @@ -40,9 +36,10 @@ 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_guard(level: c_uint, list_loaded: bool, matching: c_int);
fn sep_diag_set_xart_guard(level: c_uint, list_loaded: bool, pins: bool, matching: c_int);
fn sep_diag_set_matching(matching: c_int);
fn sep_diag_xart_guard_refused(matching: c_int);
fn sep_diag_xart_guard_refused();
fn sep_diag_verified_match();
fn sep_diag_bringup_ended();
}

Expand Down Expand Up @@ -71,15 +68,15 @@ pub(crate) enum Restore {
/// group goes away when the driver unbinds.
///
/// `guard` is the xART guard as the store opened it: its effective level and
/// whether Linux's list loaded, or `None` when no guard runs. `guarded_setup`
/// is whether that list says this install's first keybag creation was sent
/// under the guard.
/// whether Linux's list loaded and whether its pin policy is effective, or
/// `None` when no guard runs. `keybag` describes the guard's evidence for
/// the validated, persisted identity bag.
pub(crate) fn register(
dev: &device::Device<device::Bound>,
profile: &profile::PlatformProfile,
xart_writable: bool,
guard: Option<(u8, bool)>,
guarded_setup: bool,
guard: Option<(u8, bool, bool)>,
keybag: KeybagEvidence,
) -> Result {
// Exhaustive, so a new bootstrap or key store fails to build here until
// the ABI has a value for it.
Expand All @@ -91,17 +88,16 @@ pub(crate) fn register(
profile::KeyStore::Sepos13 { .. } => true,
profile::KeyStore::Variant5 => false,
};
// The facts `matching` is derived from, kept for the guard's refusals.
// Probe runs before the guard can refuse anything.
XART_WRITABLE.store(xart_writable, Relaxed);
COLD.store(cold, Relaxed);
GUARDED_SETUP.store(guarded_setup, 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: no preconditions; stores three words.
unsafe { sep_diag_set_xart_guard(c_uint::from(level), list_loaded, matching() as c_int) };
let (level, list_loaded, pins) = guard.unwrap_or((0, false, false));
let matching = MatchFacts {
xart_writable,
cold,
keybag,
guard: guard.map(|(level, list_loaded, _)| (level, list_loaded)),
}
.matching();
// SAFETY: no preconditions; caches the probe's fixed facts.
unsafe { sep_diag_set_xart_guard(c_uint::from(level), list_loaded, pins, matching as c_int) };

// SAFETY: `dev` is bound for the duration of the call, which is what devres
// needs. `profile.name` is a `str`, valid for reads of `profile.name.len()`
Expand Down Expand Up @@ -181,46 +177,22 @@ pub(crate) fn restore(state: Restore) {
unsafe { sep_diag_set_restore(state as c_int) };
}

static XART_WRITABLE: Atomic<bool> = Atomic::new(false);
static COLD: Atomic<bool> = Atomic::new(false);
static GUARDED_SETUP: Atomic<bool> = Atomic::new(false);
static GUARD_LEVEL: Atomic<u32> = Atomic::new(0);
static GUARD_LIST: Atomic<bool> = Atomic::new(false);
static REFUSALS: Atomic<u32> = Atomic::new(0);

/// What a fingerprint match can expect of the xART guard, from the facts
/// [`register`] stored and the refusals since.
fn matching() -> crate::xart_guard::Matching {
let level = GUARD_LEVEL.load(Relaxed);
MatchFacts {
xart_writable: XART_WRITABLE.load(Relaxed),
cold: COLD.load(Relaxed),
guarded_setup: GUARDED_SETUP.load(Relaxed),
guard: (level != 0).then(|| {
(
u8::try_from(level).unwrap_or(u8::MAX),
GUARD_LIST.load(Relaxed),
)
}),
refusals: REFUSALS.load(Relaxed),
}
.matching()
}

/// The xART guard opened this install's first-setup window and recorded it in
/// its list, so the keybag creation about to be sent runs under the guard.
pub(crate) fn xart_guard_setup_recorded() {
GUARDED_SETUP.store(true, Relaxed);
// SAFETY: no preconditions; stores one word. The refusals counted since
// probe stand, which `sep_diag_set_xart_guard` would clear.
unsafe { sep_diag_set_matching(matching() as c_int) };
/// The caller verified the guarded identity after the keybag commit.
pub(crate) fn xart_guard_keybag_committed() {
// SAFETY: stores the base status. A refusal takes precedence at readout.
unsafe { sep_diag_set_matching(crate::xart_guard::Matching::Unverified as c_int) };
}

/// The xART guard refused one of the enclave's writes or deletes.
pub(crate) fn xart_guard_refused() {
REFUSALS.fetch_add(1, Relaxed);
// SAFETY: no preconditions; updates two words.
unsafe { sep_diag_xart_guard_refused(matching() as c_int) };
// SAFETY: no preconditions; increments one counter.
unsafe { sep_diag_xart_guard_refused() };
}

/// The current userspace verification completed with a durably saved match.
pub(crate) fn verified_match() {
// SAFETY: promotes the base status only for a legacy pin list.
unsafe { sep_diag_verified_match() };
}

/// The boot-time bring-up is over, however far it got.
Expand Down
51 changes: 33 additions & 18 deletions drivers/soc/apple/diag_shim.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@
#include <linux/atomic.h>
#include <linux/device.h>
#include <linux/minmax.h>
#include <linux/module.h>
#include <linux/string.h>
#include <linux/sysfs.h>

#include "shim.h"

/* Loaders check the on-disk driver before enabling writes. */
MODULE_INFO(xart_guard_pins_abi, "1");

/* The contract version; see Documentation/ABI/testing/sysfs-driver-apple-sep. */
#define SEP_DIAG_ABI 2
#define SEP_DIAG_ABI 3

#define SEP_DIAG_ATTACH_PENDING 0
#define SEP_DIAG_ATTACH_ATTACHED 1
Expand Down Expand Up @@ -67,6 +71,7 @@ static struct {
/* The xART guard's effective level (0: none runs), and its list. */
unsigned int xart_guard;
bool xart_guard_list;
bool xart_guard_pins;

atomic_t attach;
atomic_t endpoints;
Expand Down Expand Up @@ -293,6 +298,13 @@ static ssize_t xart_guard_show(struct device *dev,
}
static DEVICE_ATTR_RO(xart_guard);

static ssize_t xart_guard_pins_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
return sysfs_emit(buf, "%u\n", sep_diag.xart_guard_pins);
}
static DEVICE_ATTR_RO(xart_guard_pins);

static ssize_t xart_guard_list_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
Expand Down Expand Up @@ -322,13 +334,20 @@ static ssize_t matching_show(struct device *dev, struct device_attribute *attr,
{
const char *state;

/* Once the guard refuses, a later keybag commit cannot clear it. */
if (atomic_read(&sep_diag.xart_refusals))
return sysfs_emit(buf, "blocked\n");

switch (atomic_read(&sep_diag.matching)) {
case SEP_DIAG_MATCHING_USABLE:
state = "usable";
break;
case SEP_DIAG_MATCHING_UNVERIFIED:
state = "unverified";
break;
case SEP_DIAG_MATCHING_LEGACY:
state = "legacy";
break;
case SEP_DIAG_MATCHING_BLOCKED:
state = "blocked";
break;
Expand Down Expand Up @@ -356,6 +375,7 @@ static struct attribute *sep_diag_attrs[] = {
&dev_attr_restore.attr,
&dev_attr_xart_guard.attr,
&dev_attr_xart_guard_list.attr,
&dev_attr_xart_guard_pins.attr,
&dev_attr_xart_guard_refusals.attr,
&dev_attr_matching.attr,
NULL
Expand Down Expand Up @@ -479,36 +499,31 @@ void sep_diag_set_restore(int state)
* derived in xart_guard.rs (MatchFacts), which has KUnit tests for each case.
*/
void sep_diag_set_xart_guard(unsigned int level, bool list_loaded,
int matching)
bool pins, int matching)
{
sep_diag.xart_guard = level;
sep_diag.xart_guard_list = list_loaded;
sep_diag.xart_guard_pins = pins;
atomic_set(&sep_diag.xart_refusals, 0);
atomic_set(&sep_diag.matching, matching);
}

/*
* After probe, when a fact matching is derived from changes without a
* refusal: the guard recorded this install's first-setup window. The level,
* the list and the refusals counted so far stand.
*
* The caller derived matching before this call, and a refusal may have
* landed since. A refusal always leaves "blocked", so the count is read
* after the store: either this sees the refusal and restores "blocked", or
* the refusal's own store comes later.
*/
/* A guarded keybag was committed after probe. */
void sep_diag_set_matching(int matching)
{
atomic_set(&sep_diag.matching, matching);
if (atomic_read(&sep_diag.xart_refusals))
atomic_set(&sep_diag.matching, SEP_DIAG_MATCHING_BLOCKED);
}

/* With matching as the refusal leaves it. */
void sep_diag_xart_guard_refused(int matching)
/* A legacy installation can prove present-day usability by a real verify. */
void sep_diag_verified_match(void)
{
atomic_inc(&sep_diag.xart_refusals);
atomic_set(&sep_diag.matching, matching);
atomic_cmpxchg(&sep_diag.matching, SEP_DIAG_MATCHING_LEGACY,
SEP_DIAG_MATCHING_USABLE);
}

void sep_diag_xart_guard_refused(void)
{
atomic_add_unless(&sep_diag.xart_refusals, 1, -1);
}

/*
Expand Down
Loading