Skip to content

soc: apple: sep: per-user key bags and user-bag keys on the 13.5 key store (M1) - #2049

Draft
cameroncooper wants to merge 7 commits into
aurora-silicon:integration/aurorafrom
cameroncooper:review/sep-m1-userbags
Draft

cameroncooper wants to merge 7 commits into
aurora-silicon:integration/aurorafrom
cameroncooper:review/sep-m1-userbags

Conversation

@cameroncooper

@cameroncooper cameroncooper commented Nov 16, 2026 •

Copy link
Copy Markdown

Stacked on #1824 (its commit is the first one here; review starts at the second).

Per-user key bags and user-bag keys are refused on the 13.5 key store of M1/M2-generation Macs. This adds that store's backend and turns per_user_keybags (from #1824) on for T8103, where it has run on hardware. The ABI is unchanged: the same SEP_BIO_KEYBAG_* and SEP_KEY_* requests, so userspace written for variant 5 works as is.

  • ref-key targets: on the 13.5 store sks_req_refkey substituted the identity bag for an explicitly designated user bag. refkey_target() keeps explicit user designations.
  • designate: one sks::designate_variant() shared by the identity-bag and user-bag paths (variant 0 on 13.5, without the flags word).
  • bags on 13.5: create (DeviceBag constructor, version 1), unlock (loaded-bag CHANGE_LOCK_STATE version 0, then the designated-session transition), lock (transition, loaded-bag lock, then grace-timer fires until the store names the bag locked, about 10 s on M1, with user_bags not held while waiting), logout (lock and unload), and import of a bag its designation already names. A screen lock with a grace period is refused with EOPNOTSUPP: not captured on this store.
  • password change on 13.5 (change-secret version 1).
  • user-bag keys on 13.5 (EC type 4), and SEP_KEY_FEATURE_PASSWORD advertised wherever per_user_keybags allows bags.
  • T8103: per_user_keybags: true. T6000 and the 13.5 J414s profile are unchanged.

Tests

  • KUnit golden layouts for the 13.5 create and reply, loaded-bag unlock and lock, timer fire, designate (both stores), change-secret version 1, and the loaded-bag registry; ref-key target selection.
  • test_log_ratelimit.py, test_policy_window.py, test_enrol_admission.py, test_sep_bio_identities.py, test_refkey_seal_admission.py pass. (test_keystore_only.py fails the same way on integration/aurora today; it is not in CI.)
  • arm64 module and KUnit builds pass with no new warnings.

Hardware

  • J293 (MacBook Pro 13-inch, M1, cold-boot SEP), with a PAM module that creates, imports, unlocks and locks a user's bag at login, logout and suspend: create, export, import, unlock, lock at logout and at suspend all worked; keys under the bag signed with an enclave-checked password.
  • On a kernel built from this stack (with soc: apple: sep: Touch ID in each user's own domain #2050 and soc: apple: sep: authorization contexts for user-bag keys #2051, 2026-11-16): the lock screen's password unlocked the bag; a 9 s suspend locked it (the sleep hook), keys under it were then refused, and the next password opened it again. SEP_KEYBAG_STATE is refused on 13.5 with EOPNOTSUPP, as intended.
  • Not yet run: password change on 13.5; logout and a grace-period screen lock on this build; anything on T6000 or J414s.

🤖 Generated with Claude Code

…he create variant

userbag_ioctl refused per-user key bags unless profile.key_store was the
variant-5 create encoding. That encoding describes how the identity key bag
is created, not whether the enclave can create a NEW per-user bag. T8112 (M2)
and T8122 (M3) are warm-register platforms whose SEP is handed over running
and shared with macOS; their identity bag uses the variant-5 form, so they
passed the Variant5 check, yet their enclave never replies to a user-bag
DESIGNATE_KEYBAG. A single unanswered DESIGNATE condemns the SKS endpoint for
the rest of the boot (sks_wedged), taking the whole key store down: the log
shows "DESIGNATE_KEYBAG got no reply" followed by every later SKS request
reporting "endpoint gone for this boot".

Per-user bag create and designate are proven only on T8140 (J700) and the
T6040 (J616s / M4 Pro) enclave family. Add an explicit PlatformProfile
capability, per_user_keybags, true only on those, and gate userbag_ioctl and
the per-user-bag ref-key / FDE paths on it instead of on the create-encoding
variant. The unsupported platforms now return EOPNOTSUPP before any enclave
request, so the SKS endpoint is never wedged. Touch ID and the identity bag
are unaffected: neither uses userbag_ioctl.

The sep KUnit suite passes (598 run, 596 passed, 2 skipped, 0 failed).

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
On the 13.5 key store, sks_req_refkey always substituted the configured
Linux user's designation for the target handle. That is right for the
identity bag's source handles, but it also redirected an explicitly
designated user bag, so a key meant for a per-user bag was made and
used under the identity bag instead.

Factor the choice into refkey_target(): source handles keep the
identity mapping, and an explicit user designation keeps its own bag.
Variant 5 is unchanged.

The KUnit cases cover the identity fallback, the user-designation
boundaries and variant 5.

Assisted-by: LLM [Claude Code, claude-opus-5-5]
Signed-off-by: Cameron Cooper <c@meron.cc>
The per-user bag path hard-coded designate variant 1 and its flags
trailer, the variant-5 form. The 13.5 key store takes variant 0 with
the body ending after the empty blob, as the identity-bag path already
sends it.

Move the variant choice into sks::designate_variant(), shared by both
paths, and encode and decode the user-bag designation with it. The
variant-5 layout is unchanged; the user-bag ioctls stay gated by
per_user_keybags.

The KUnit golden test gains a 13.5 case for the shorter body and its
reply, and checks that each store rejects the other's form.

Assisted-by: LLM [Claude Code, claude-opus-5-5]
Signed-off-by: Cameron Cooper <c@meron.cc>
The user-bag ioctls refused every request on the 13.5 key store of
M1/M2-generation Macs. Add that store's backend for create, import,
export, unlock and lock:

- create uses the generic DeviceBag constructor (version 1);
- unlock first unlocks the loaded bag with the version-0
  CHANGE_LOCK_STATE, which has no flags trailer, then runs the
  designated-session device-state transition. Neither alone lets a key
  under the bag run;
- lock runs the transition with state Locked and the loaded-bag lock,
  then sends grace-timer fires, as the Mac's kernel does, until the
  store names the bag locked. The store locks only on a fire, about
  10 s after an immediate lock on M1. The bag lock is not held while
  it waits. A screen lock with a grace period is not captured on this
  store and is refused with EOPNOTSUPP;
- import of a bag the user's designation already names (a repeated
  login) keeps that bag rather than designating it twice.

Variant 5 keeps a designation after its temporary handle is unloaded.
The 13.5 loaded-bag unlock needs the handle, so the bag stays loaded
from import or create until logout, which locks and unloads it.

Password change, state query and FDE sealing stay EOPNOTSUPP on the
13.5 store.

KUnit golden layouts cover the 13.5 create and its reply, the
loaded-bag unlock and lock, the timer fire, and the loaded-bag registry.

Assisted-by: LLM [Claude Code, claude-opus-5-5]
Signed-off-by: Cameron Cooper <c@meron.cc>
The 13.5 key store refused CHANGE with EOPNOTSUPP, so a user's bag
could not follow a password change.

Its change-secret request is version 1 of the variant-5 one, as macOS
13 sends it: client, handle, the old and new secrets, two further blobs
and two words (a u8 flag and the generation option), without variant
5's last word. Send it with the two blobs empty, the flag 0xff and the
generation option 0, as the variant-5 path does, and accept the
version-1 reply.

KUnit adds the golden layout. Not yet run on hardware.

Assisted-by: LLM [Claude Code, claude-opus-5-5]
Signed-off-by: Cameron Cooper <c@meron.cc>
CREATE_USER refused on the 13.5 key store because user_key_create_in_bag
made only variant 5's EC key type 5. The 13.5 store makes EC type 4
ref-keys, as it already does under the identity bag.

Choose the key type from the key store, and advertise
SEP_KEY_FEATURE_PASSWORD wherever per_user_keybags allows user bags.
Sign and unseal under a user bag already address the designation's
special handle on either store.

On J293, keys created under a user's bag signed with an enclave-checked
password.

Assisted-by: LLM [Claude Code, claude-opus-5-5]
Signed-off-by: Cameron Cooper <c@meron.cc>
The 13.5 key store paths for per-user bags (create, designate,
import/export, unlock, lock, password change) and for user-bag keys
are in place, so turn the per_user_keybags capability on for T8103.

On J293 (MacBook Pro 13-inch, M1, cold-boot SEP) the userbag ioctls
created, exported, imported, unlocked and locked (logout and suspend)
a user's bag, and user-bag keys signed with an enclave-checked
password. Password change is implemented but not yet run on hardware;
a screen lock with a grace period stays refused on this store. T6000
and the 13.5 J414s profile are unchanged: nothing has run there.

Assisted-by: LLM [Claude Code, claude-opus-5-5]
Signed-off-by: Cameron Cooper <c@meron.cc>
@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks for the 13.5 store backend and the J293 results. Two points:

  1. drivers/soc/apple/profile.rs: per_user_keybags is false on T6000 and T6020 only because it is not yet proven there. T6000 cold-boots the same 13.5 store as T8103. Could the default come from the key store, with false kept only where a measured failure is cited in the comment, as you already do for T8112 (DESIGNATE never answered)? We have an M1 Pro (J316s) and can run the create/unlock/lock/sign row there.

  2. userbag.rs userbag_lock_13(): after 15 timer fires it returns ETIMEDOUT with the bag still unlocked in the store, and the suspend lock depends on it. On a timeout or any lock error, please unload the bag, or mark it locked in the driver so key requests under it fail until the next successful unlock. A comment on why the host drives the timer would help.

Small one: userbag_refused() now prints up to 96 bytes of the create and change-secret replies at info level. Could that be dev_dbg, or just length and status?

Rows we would like on J293: a password change (old refused, new accepted, keys still sign), logout and re-login in one boot, and a user-bag key refused straight after resume.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants