Skip to content

soc: apple: sep: bio refcount; KEYS: trusted: gate "import" behind Kconfig and lockdown - #2994

Draft
Alyx-ML wants to merge 3 commits into
aurora-silicon:mainfrom
Alyx-ML:aurora/sep-fixes
Draft

Alyx-ML wants to merge 3 commits into
aurora-silicon:mainfrom
Alyx-ML:aurora/sep-fixes

Conversation

@Alyx-ML

@Alyx-ML Alyx-ML commented Nov 23, 2026

Copy link
Copy Markdown

Part of the #2755 split. Draft until it has a run on a Mac (the last Evidence line says which). This carries RyanTheTide's two requests on the trusted-keys commit.

Summary

 bio_shim: free the character device by reference count   # not while a release is inside mutex_unlock()
 datablob_parse()  case Opt_import:
+  if (!IS_ENABLED(CONFIG_TRUSTED_KEYS_IMPORT) || !source importable) return -EINVAL;
+  ret = security_locked_down(LOCKDOWN_INTEGRITY_MAX); if (ret) return ret;
+config TRUSTED_KEYS_IMPORT   (default n, like USER_DECRYPTED_DATA)
 SEP source: refuse keyhandle=, keyauth=, blobauth=, pcrinfo= ... with -EINVAL

No Aurora tool sends import, and asahi.config leaves the option off.

Evidence

  • After: KUnit trusted_source on arm64 QEMU, with CONFIG_TRUSTED_KEYS_IMPORT off and on:
    passed, Apple build and KUnit. trusted_source_import checks that a source without the flag never seals,
    that a source with it seals only when the option is set, and that a withdrawn source leaves
    nothing behind. Each run: 9 of 10 passed and 1 skipped (trusted_source_after_mark_readonly,
    which cannot run in a built-in kernel). SEP source checks: passed, SEP source checks.
  • The lockdown check has no KUnit case, because a test cannot lock the kernel down and undo it.
  • Needed before merging: on a Mac, opening and closing the SEP bio device while another
    process releases it, and creating and loading a trusted key with the SEP source.

Merge Danger

Door: two-way

Blast Radius: trusted keys

import stops working unless the kernel is built with the new option. Nothing in the tree uses it.

Assisted-by: LLM (Claude:Opus 5.5)

sep_bio_unregister() and the release of the last open file each decide,
under d->lock, whether they are the last user, and the one that is frees
d right after its own mutex_unlock(). But the other side may still be
inside mutex_unlock(&d->lock): the unlock slow path takes the wait lock
and wakes waiters after the lock has been handed over, and a spinning
waiter can take the mutex, finish, and free d in that window. The
mutex documentation forbids freeing the memory a mutex lives in while
another task may still be in its unlock.

Count one reference for the registration and one per open file, and
drop it after each side's unlock has returned. The side that drops the
last reference frees d, so nobody can still be inside d's mutex then.
misc_deregister() runs before the registration reference is dropped, so
no open can race with the final put.

Checked by reading the open, release, ioctl, poll and unregister paths.
Not built as a kernel module or run on hardware; the race itself is too
narrow to show on this host.

Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
The "import <hex-key>" command was added for the Apple SEP source, but
the trusted-key core accepts it for every source: TPM, TEE, CAAM, DCP
and PKWM. Upstream has no such command. With it, root can make a TPM-
or TEE-sealed "trusted" key whose plaintext was chosen and seen in
userspace, which breaks what consumers of trusted keys (encrypted keys'
"trusted:" master key, dm-crypt key descriptions) expect: that the
plaintext was made in the kernel.

Refuse "import" before the source is called unless all of these hold:

- The kernel is built with the new CONFIG_TRUSTED_KEYS_IMPORT. It is
  off by default, like CONFIG_USER_DECRYPTED_DATA for encrypted keys.
  Without it, "import" fails with -EINVAL.
- The active source sets the new "importable" flag in struct
  trusted_key_ops, next to "migratable". The core records the flag when
  a source becomes active (built in or registered at runtime) and
  clears it when the source withdraws. The upstream sources leave it at
  0, so for them "import" is refused as upstream refuses an unknown
  command. The SEP source sets it.
- The kernel is not locked down for integrity:
  security_locked_down(LOCKDOWN_INTEGRITY_MAX) is checked, and its error
  (-EPERM) returned.

No Aurora tool uses "import", and arch/arm64/configs/asahi.config does
not turn the option on.

The KUnit case trusted_source_import checks that import fails with
-EINVAL and seals nothing for a source without the flag, that a source
with the flag seals exactly when CONFIG_TRUSTED_KEYS_IMPORT is set, and
that import fails again once that source has withdrawn. The lockdown
check has no KUnit case: a test cannot lock the kernel down and undo
it.

Verified: a host copy of the command parse shows "import" refused
without the flag and accepted with it. The kernel C code and the KUnit
case were not compiled or run here.

Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
The SEP trusted-key source ignored everything after the command:
"new 32 blobauth=..." or "load <blob> pcrinfo=..." made or loaded a key
as if the option were absent. A caller who asks for a blob password or a
PCR binding gets a key without that protection and no error. The TPM
source would have applied the option.

Refuse any option after the command with -EINVAL in the shim's seal and
unseal trampolines, before the Rust callback runs. Trailing white space
still passes, so "new 32 " and a blob with a trailing newline work as
before. The in-tree users (tools/aurora-sep/load-driver and the
coordinator runtime check) pass no options.

Verified: a host C harness (clang, ASan and UBSan) that mirrors the
core's strsep() parse gives 0 for "new 32", "new 32 \t\n" and
"load abcd\n", and -EINVAL for blobauth=, keyauth=, pcrinfo= and
migratable= after new, load or import. The kernel code was not compiled
here.

Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
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.

1 participant