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 11 commits into
aurora-silicon:mainfrom
cameroncooper:review/sep-m1-userbags
Draft

cameroncooper wants to merge 11 commits into
aurora-silicon:mainfrom
cameroncooper:review/sep-m1-userbags

Conversation

@cameroncooper

@cameroncooper cameroncooper commented Nov 16, 2026 •

Copy link
Copy Markdown

Stacked on #2806: its two commits first, unchanged (the same patches as its head), on today's integration/aurora (which has #2048). Review starts at "keep explicit user bags in 13.5 ref-key requests".

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 with it per_user_keybags() (from #2806) holds on both key stores, false only where the measured unanswered-DESIGNATE defect is set (T8112). 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).
  • a lock the store does not confirm: if a lock request is refused, a reply is unreadable, or the store has not locked the bag after 15 timer fires, the driver holds the bag locked: key creation, signing and unsealing under it get EACCES until an unlock of it succeeds, and the hold survives an unload. The host sends the timer fires because the store locks only on a fire it is sent, and on macOS the kernel sends them.
  • refused replies are logged by length and status only, without their bytes.
  • an import of a bag still held is EBUSY before a second copy is loaded, on both stores, so the login helper unlocks it instead. On variant 5 the import used to designate the second copy, the store refused (the bag was still designated), and the import answered EACCES: a password unlock after a suspend or a bag lock left the bag locked until a logout. The 13.5 store already got EBUSY, but only after loading the copy.
  • user-bag keys on 13.5 (EC type 4), and SEP_KEY_FEATURE_PASSWORD advertised wherever per_user_keybags allows bags.
  • default from the key store: per_user_keybags() is a key-store rule, not a per-SoC flag. Both key stores (Variant5, Sepos13) have the user-bag requests, so it reads !designate_unanswered for either, and a key store added later is refused. T8103, T6000 and the T6020 13.5 profile have per-user bags; T8112 keeps them refused. Only T8103 has run on hardware.

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; per_user_keybags_follow_the_key_store_and_the_designate_defect for every profile; a_held_bag_stays_held_until_its_unlock. 316 of 316 SEP tests pass at the tip.
  • 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.)
  • Every commit of the stack builds (arm64 module); KUnit passes with no new warnings in the SEP files. The SEP source checks host tests pass at every commit.

Hardware

From review

  • Default per_user_keybags() from the key store, false only with a cited measured failure (T8112's unanswered DESIGNATE).
  • userbag_lock_13(): on ETIMEDOUT or any lock error the driver holds the bag locked, and the comment says why the host drives the timer.
  • userbag_refused() logs length and status only.
  • Hardware: password change, logout and re-login in one boot, a user-bag key refused after resume.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown

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.

@RyanTheTide

Copy link
Copy Markdown

None of the 13.5 key store user-bag backend is on 110861f. The series applies cleanly on 110861f. Its base commit came from #1824, which was replaced by #2806. #2806 derives per_user_keybags() from the key store variant and the measured DESIGNATE defect, so the 13.5 store reads false there. @cameroncooper, please restack onto #2806 and turn the T8103 enable into a key-store rule that admits the 13.5 store (review point 1), rather than a per-SoC flag. The lock-timeout handling and the info-level reply dump from the review are still open, as are the J293 rows (password change, logout and re-login, a user-bag key refused after resume).

Build check of 110861f plus this change (arm64, LLVM=1, Image, dtbs and every directory it touches, Fedora config plus asahi.config): builds, no warnings in the files it touches.

@cameroncooper

Copy link
Copy Markdown
Author

Thanks. Everything from both of your comments is in this push: the review points, the J293 rows and the restack.

Restack onto #2806. The stack now starts with #2806's two commits, unchanged (the same patches as its head), on today's integration/aurora; they are the same patches the stack carried as #1824's.

  1. Default from the key store. The 13.5 commit ("per-user key bags on the 13.5 key store") turns the enable into a key-store rule, not a per-SoC flag. per_user_keybags() now matches the key store: both Variant5 and Sepos13 have the user-bag requests, so it is !designate_unanswered for either, and a key store added later is refused until its requests are written. So T8103, T6000 and the T6020 13.5 profile have per-user bags, and only T8112 (DESIGNATE never answered) keeps them off. Your KUnit case keeps its name and covers every profile. Only T8103 has run on hardware, so yes please to the J316s create/unlock/lock/sign row. I'd like to cite it in the commit once you have it.

  2. userbag_lock_13() on a timeout or lock error ("hold a bag locked when the store does not confirm its lock"). On any failure (a refused request, an unreadable reply, or no lock after 15 fires) the driver holds the bag locked. Key creation, signing and unsealing under it get EACCES until an unlock of it succeeds, and the hold survives an unload, so a bag a logout couldn't lock stays refused if it's loaded again before its password. I chose this over unloading, because unloading would leave the userspace helper's record of loaded bags out of step. The comment now says why the host sends the fires: the store locks only on a fire it is sent, and on macOS the kernel sends them. KUnit: a_held_bag_stays_held_until_its_unlock. The failure path itself hasn't happened on hardware.

Nit ("log a refused reply's length and status only"): done. The 96-byte print was in the base, but the 13.5 create and change-secret replies now reach it.

Rows on J293 (this stack with #2050 and #2051, 2026-11-19), with a .userPresence key made under the bag through SEP_KEY_CREATE_USER and signed through SEP_KEY_SIGN:

  • Password change: the old password was refused at the lock screen, the new one unlocked the bag, and the key made before the change still signed. Changed back the same way.
  • Logout and re-login in one boot: the logout locked and unloaded the bag, and after logging in again the key signed with a touch. This needed a fix to our PAM helper, which counted systemd's user-manager session and so never saw the last real session close.
  • Key straight after resume: after an s2idle suspend (the sleep hook locked the bag), the sign was refused at once with EACCES, without a capture.
  • Also: after an explicit bag lock the sign was refused the same way, and it worked again after the password.

As you asked on #2048, the commits in this stack no longer carry the Assisted-by trailer. It's the last line of the description and of this reply instead.

Assisted-by: LLM (Claude:Opus 5.5)

RyanTheTide and others added 11 commits November 23, 2026 15:13
…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>
Signed-off-by: Cameron Cooper <c@meron.cc>
per_user_keybags was a list of the enclaves where a user-bag create and
designate had been run: true on T8140 and the T6040 family, false
everywhere else. That makes every enclave nobody has tried refuse, and
says nothing about why the one measured failure fails.

The user-bag requests are part of the variant-5 key store; the 13.5 key
store has no such requests. The one measured defect is the T8112 (J415)
enclave, which returns a handle for CREATE_KEYBAG and then never answers
DESIGNATE_KEYBAG, condemning the SKS endpoint for the boot. Name that
defect, designate_unanswered, set it on T8112 only, and derive
per_user_keybags() from the key store variant and that flag.

T8122 no longer inherits the flag from the T8112 profile it extends:
the unanswered DESIGNATE was measured on J415, not on an M3. T6020 on
current firmware, T8122, T8132 and T8142 therefore offer per-user key
bags; none of them has run a user-bag DESIGNATE yet. T8103, T6000 and
T6020 on the 13.5 key store keep refusing, as does T8112.

Add a KUnit case covering per_user_keybags() for every profile.

Signed-off-by: Ryan <ryan@aurorasilicon.org>
Signed-off-by: Cameron Cooper <c@meron.cc>
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.

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.

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.

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.

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.

Signed-off-by: Cameron Cooper <c@meron.cc>
per_user_keybags() refuses the 13.5 key store because that store had no
user-bag requests. It has them now: create, designate, import/export,
unlock, lock and password change in its own shapes (userbag_sepos13),
and user-bag keys under them. Derive the capability from the measured
DESIGNATE defect alone, so T8112 stays the only enclave that refuses.

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. T6000 and T6020 on the 13.5 store send the same requests and
now offer per-user bags too; no M1 Pro/Max or 13.5-store M2 Pro/Max has
run them yet.

Signed-off-by: Cameron Cooper <c@meron.cc>
…onfirm its lock

On the 13.5 store a lock is two requests the store accepts with the bag
still usable, then grace-timer fires until the store reports the bag
locked. When that failed (a refused request, an unreadable reply, or
no lock after 15 fires), userbag_lock_13() returned an error with the
bag still unlocked in the store, and the suspend and logout locks rely
on it.

On any such failure the driver now holds the bag locked: key creation,
signing and unsealing under it are refused with EACCES until an unlock
of it succeeds. The hold outlives an unload, so a bag the logout could
not lock stays refused if it is loaded again before its password.

Also say why the host sends the timer fires: the store locks the bag
only on a fire it is sent, and on macOS the kernel sends them; nothing
else on Linux does.

Signed-off-by: Cameron Cooper <c@meron.cc>
userbag_refused() printed up to 96 bytes of a refused reply at info
level. The 13.5 store's create and change-secret replies now reach it,
and those can carry key-bag material. Print the length and the
operation status instead.

Signed-off-by: Cameron Cooper <c@meron.cc>
The login helper imports the saved bag at every password login and
takes EBUSY as "already loaded: unlock it". A bag locked for a suspend
(or open for another session) stays in user_bags, so a password unlock
after the lock imports it again.

The 13.5 store got EBUSY from LoadedBags::insert() once the second
copy was loaded. Variant 5 never got there: it designated the second
copy, the store refused (the bag was still designated), and the import
answered EACCES. On J716c (M5 Max) the password at the lock screen
then left the bag locked, and the user's Touch ID keys refused until a
logout.

Answer EBUSY before loading a copy when the driver still holds the
user's bag, on both stores. The helper then unlocks it as before.

Signed-off-by: Cameron Cooper <c@meron.cc>
@cameroncooper

Copy link
Copy Markdown
Author

One more commit at the end of this PR, from running #2051's rows on the M5 Max: "an import of a bag still held is EBUSY".

The login helper imports the saved bag at every password login and takes EBUSY as "already loaded: unlock it". A bag locked for a suspend (or open for another session) is still held, so the next password imports it again. On the 13.5 store that got EBUSY from LoadedBags::insert() once the second copy was loaded. On variant 5 the import designated the second copy and the store refused it, because the bag was still designated, so the import answered EACCES. On J716c the lock screen's password then left the bag locked, and the user's Touch ID keys were refused until a logout. The import now answers EBUSY before loading a copy, on both stores.

On J716c (variant 5) with the fix, the password reopened the bag after a bag lock and after an s2idle suspend. The variant-5 import path is from the base (before #2806), so the bug was there before this stack. I put the fix here, with the rest of the bag lifecycle.

Assisted-by: LLM (Claude:Opus 5.5)

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