Repository navigation
soc: apple: sep: return -EAGAIN from trusted-key callbacks before ready - #3237
Conversation
Trusted-key instantiation in security/keys/trusted-keys/trusted_core.c runs inside __key_instantiate_and_link(), which holds the global key_construction_mutex. Calling SepData::wait_for_trusted_ready() from tk_get_random(), refkey_seal_trusted(), and refkey_unseal_cached() slept for up to EXCHANGE_TIMEOUT_MS (90 s) while holding that mutex, stalling every other key instantiation on the system (including systemd service startup) whenever an early trusted-key operation raced SEP bring-up. Replace those blocking waits in the trusted-key callbacks with a non-blocking SepData::check_trusted_ready() check backed by a pure trusted::ready_state() decision helper: - Return -EAGAIN immediately (zero wait) while SEP bring-up is still in progress (phase != PHASE_READY) or while the enclave is transiently gated for system sleep (SleepGate::Draining / SleepGate::Told). - Return terminal errors instead of spinning on -EAGAIN when the driver is shutting down (-ENODEV), when bring-up completed without an SKS endpoint (-ENODEV) or failed SKS initialisation (-EIO), or when the enclave failed to return from sleep (SleepGate::Lost -> -EIO). - Check readiness at the start of tk_unseal() before inspecting the blob so not-ready and terminal readiness states return -EAGAIN/-ENODEV/-EIO without creating a blob oracle, while preserving opaque -EBADMSG for every post-readiness unseal rejection. - Suppress the one-shot seal failure warning in tk_seal() for expected -EAGAIN retries so early retries do not spam or exhaust the warning. - Keep wait_for_trusted_ready() for callers outside key_construction_mutex (sysfs complete_attach and /dev/sep-key ioctls). - Publish PHASE_READY (with Release/Acquire ordering) inside finish_bringup() before diag::keystore_open(), diag::keystore_ended(), and diag::bringup_ended() transition diag/keystore out of "unknown" and emit kernfs_notify(), so userspace waiting on diag/keystore never races into a spurious -EAGAIN. Add KUnit tests (apple_sep_trusted) and host tests (tools/aurora-sep/tests/test_trusted_readiness.py, plus updated test_refkey_seal_admission.py) covering readiness transitions, terminal errors, sleep-gate handling, error masking, and call-site invariants. Relates to: aurora-silicon#2313 Signed-off-by: AxxzyWasTaken <[email protected]>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
Hardware verification row on J813 (M5 MacBook Air 13-inch, T8142,
|
There was a problem hiding this comment.
Verdict: MERGE at fffee85c
Blockers: none in code (note before merge: cancelled CI jobs apple-build, rust-build, and kunit must rerun green; second-family regression smoke is needed for blast:all; .github/workflows/sep-source.yml requires Owner approval).
Checked: no Apple material, no AI attribution, no chip/board/firmware gates, no cmdline hacks, human Signed-off-by, non-blocking trusted-key callbacks under key_construction_mutex, Release/Acquire publication ordering in finish_bringup() before diag::keystore_open()/bringup_ended()/keystore_ended(), all callers of run_bringup()/run_keystore_bringup() verified, opaque -EBADMSG preservation post-readiness with transient -EAGAIN passthrough, KUnit and host tests added, exact-head J813 hardware row PASS.
Evidence
- Code inspection across all 8 touched files:
- Verified every caller of
run_bringup()andrun_keystore_bringup()indrivers/soc/apple/is insidesep.rsand flows directly intofinish_bringup(keystore_open, keystore_only), so movingdiag::keystore_open()intofinish_bringup()afterself.phase.store(PHASE_READY, Release)underself.endpoints.lock()cannot drop keystore-open notifications on any path. tk_get_random(),tk_seal()(viarefkey_seal_trusted()), andtk_unseal()(directly and viarefkey_unseal_cached()) all callcheck_trusted_ready()and never sleep onwait_for_trusted_ready()underkey_construction_mutex.complete_attachand/dev/sep-keyioctls (with_identity_bag) retainwait_for_trusted_ready().tk_unseal()checks readiness before readingp->blob(avoiding a blob oracle) andunseal_failure_errno()preserves-EAGAINwhile collapsing all other post-readiness failures to-EBADMSG.seal_should_warn()prevents expected-EAGAINretries from consuming the one-shot warning intk_seal().
- Verified every caller of
- Hardware row at exact head
fffee85c5489: J813 (sithglan, 86/86 earlyadd_key("trusted", ...)calls returned-EAGAINimmediately, median 0.064 ms, no stall, succeeded once keystore opened). - CI at
fffee85c:host-tests,source,pr-text,readinessPASS;apple-build,rust-build, and KUnit jobs were cancelled and must rerun green before merge.
|
Row (J616s, M4 Pro) at exact head fffee85 in combined candidate cedaeff9ee2fe5396733351bb571d0a6049bd7fc on main aa76613: 3x keyctl trusted new 32 -> pipe -> load (SEP ref-key seal/unseal) + tampered-blob control -> PASS (3/3 seal+unseal, 3/3 tampered refused EBADMSG, diag trusted=ready, aurora-sep 22 pass/0 fail before and after 2 s2idle; 0 failed units, Enforcing, 0 WARN/BUG). Evidence: traces/kernel/20261129-closeout-j616s-combo/. Saved boot restored. |
|
code-owner ping @DjDeveloperr: closeout merge at |
|
Merging under the 6-point rule (Ryan 09:29, permanent), at |
|
Merged. Thanks @AxxzyWasTaken: trusted keys now return -EAGAIN before the SEP is ready, and we verified it on the J616s as well as your J813. |
#3237 made finish_bringup() take the key-store outcome and end the keystore/bringup diagnostics after the PHASE_READY store, so trusted-key callbacks see -EAGAIN until bring-up has finished on every exit. This branch moved finish_bringup() behind ready::Bringup so ready::publish() can recheck the attach-only endpoints after the store. Keep both: Bringup::finish_bringup() and ready::publish() carry keystore_open/keystore_only through to #3237's finish_bringup(), the early-failure exits pass false/false as main does, and the summary line follows publish() because it reads the key-store state set there. A new apple_sep_ready case checks the outcome reaches finish_bringup(). Signed-off-by: Ryan Murray <[email protected]>
What: Trusted-key callbacks (
tk_get_random,tk_seal,tk_unseal) run insidetrusted_instantiate(), which is called from__key_instantiate_and_link()while holding the globalkey_construction_mutex. Previously, those paths calledSepData::wait_for_trusted_ready(), sleeping up to 90 s (EXCHANGE_TIMEOUT_MS) under that mutex and stalling every other key instantiation on the system (including systemd service startup) whenever an early trusted-key operation raced SEP bring-up. (PR #3168 implemented thediag/keystorekernfs_notify()half and auto-closed #2313; this completes the non-blocking trusted-key half.)SepData::check_trusted_ready()backed bytrusted::ready_state()and switchtk_get_random(),tk_unseal(),refkey_seal_trusted(), andrefkey_unseal_cached()to it:-EAGAINimmediately (zero wait) while SEP bring-up is still running (phase != PHASE_READY) or while the enclave is transiently gated for system sleep (SleepGate::Draining/SleepGate::Told).-ENODEVon driver shutdown or missing SKS endpoint;-EIOon failed SKS initialization orSleepGate::Lost) so callers do not spin indefinitely on-EAGAIN.tk_unseal()before inspecting the blob so readiness errors return-EAGAIN/-ENODEV/-EIOwithout creating a blob oracle, while preserving opaque-EBADMSGfor post-readiness unseal rejections.tk_seal()for expected-EAGAINretries.wait_for_trusted_ready()for callers outsidekey_construction_mutex(complete_attachsysfs completion and/dev/sep-keyioctls).PHASE_READY(Release/Acquire, underendpoints.lock()) insidefinish_bringup()beforediag::keystore_open(),diag::keystore_ended(), anddiag::bringup_ended()transitiondiag/keystoreout of"unknown"and emitkernfs_notify(), preventing a race where userspace waiting ondiag/keystoreimmediately callsadd_key()and gets a spurious-EAGAIN.apple_sep_trustedKUnit tests indrivers/soc/apple/trusted.rs, add host tests intools/aurora-sep/tests/test_trusted_readiness.py, updatetools/aurora-sep/tests/test_refkey_seal_admission.py, and wire both into.github/workflows/sep-source.yml.Relates to #2313.
Tested: Cross-compiled
ARCH=arm64 LLVM=1(defconfig+asahi.config)drivers/soc/apple/apple-sep.owith bothCONFIG_APPLE_SEP_KUNIT_TEST=y(all 7apple_sep_trustedKUnit wrappers verified viallvm-nm) andCONFIG_APPLE_SEP_KUNIT_TEST=n, plussecurity/keys/trusted-keys/tests/trusted_source_kunit.o(0 new warnings).tools/aurora-sep/tests/test_trusted_readiness.py,test_refkey_seal_admission.py, and all 18 CIsep-source.ymlPython unit tests pass under bothpython3andpython3 -O;tools/asahi/run-host-tests.py --only seppasses 23/23.git diff --checkclean;scripts/checkpatch.pl --strict --git HEAD~1..HEADreports 0 errors / 0 code warnings.Not yet: Live boot and early-probe hardware rows on Apple Silicon Macs (including
aurora-sep-loadand LUKS initrdkeystore_onlyattach) and arm64 KUnit execution (covered by CIsep-source.yml).Risk: two-way · all Macs with Apple SEP (
apple-sep)