Skip to content

soc: apple: sep: latch only a key context's failed delete - #3001

Open
cameroncooper wants to merge 2 commits into
aurora-silicon:integration/aurorafrom
cameroncooper:review/sep-key-latch-scope
Open

cameroncooper wants to merge 2 commits into
aurora-silicon:integration/aurorafrom
cameroncooper:review/sep-key-latch-scope

Conversation

@cameroncooper

@cameroncooper cameroncooper commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #2048, for the blocker in #2048 (comment): one failed delete of a Touch ID unlock evaluation turned off /dev/sep-key until reboot, while the verify that hit it still reported its match.

This takes the first option you gave: key_context_failed is set only where a key operation's context is deleted, and close_unlock_evaluation() only logs.

  • SepData's ContextDelete (used by OwnedContext::dispose()) sets the latch on a failed delete. That includes the context a touch-gated key operation hands to the prompt (sbio.rs drops it as an OwnedContext), so that path is still covered, and the check after the job (key.rs) is unchanged.
  • The key.rs paths that deleted a key context through close_unlock_evaluation() (password context setup, the self-tests) now call delete_context(), so they keep latching.
  • delete_unlock_evaluation() and close_unlock_evaluation() no longer touch the latch. Every /dev/sep-bio verify path (sbio.rs and the preflight in sep.rs) only logs a failed delete.

Second commit

key_context_for() (the password-gated key paths and the self-tests) deleted a tracked context whose externalize was refused, but returned EIO with the context still alive when the externalize got no reply. It now deletes it on both, and a delete that then fails latches /dev/sep-key like any other key context. The no-reply path has not happened on hardware; a reply takes the same path as before.

Tests

  • KUnit: only_a_failed_key_context_delete_latches drives OwnedContexts through a deleter that latches as SepData does: a confirmed delete (finished or dropped) leaves the latch clear, a failed one sets it, and a later confirmed one leaves it set. 309 of 309 SEP tests pass on arm64 QEMU, at each of the two commits.
  • Host: every SEP source checks / source test passes, including test_key_context_cleanup.py.
  • Hardware (J293, M1), 2026-11-23, the previous revision of the first commit (1a969ee7; since then only the helper and its test have moved, and the second commit is new) on today's integration/aurora (with the soc: apple: sep: per-user key bags and user-bag keys on the 13.5 key store (M1) #2049–soc: apple: sep: authorization contexts for user-bag keys #2051 stack): password sign and unseal of a user-bag key (SEP_KEY_SIGN_PASSWORD, SEP_KEY_SEAL then SEP_KEY_UNSEAL_PASSWORD, the secret back unchanged), then 10 Touch ID screen unlocks (10 satisfied matches), then the same password sign and unseal again: all passed. SEP_KEY_GET_INFO worked before and after; no "private key operations disabled" and no failed delete in the journal. Regression: 0 failed units; SELinux is not enabled on this install, so 0 denials; no new kernel errors (the only error lines, audit: backlog limit exceeded at login, appear on earlier boots too). The failure path itself has not been forced on hardware.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formal §1–§6 pre-PR checklist review at 1a969ee78e2a9677533a4dc58b21e650dbf586c6.

The latch-scoping logic itself is sound and resolves the #2048 blocker cleanly:

  • delete_unlock_evaluation() (drivers/soc/apple/sep.rs:2778) now only logs and returns Err(EIO), so /dev/sep-bio verify paths through close_unlock_evaluation() (sbio.rs:723, 1282, 2754, 2867; sep.rs:2747) no longer quarantine /dev/sep-key.
  • impl ContextDelete for SepData (drivers/soc/apple/key.rs:974) sets key_context_failed on delete failure and logs the quarantine warning; OwnedContext::dispose() (key.rs:1007) routes password-gated (key.rs:2139/2146), touch-gated (sbio.rs:2772/2866 + key.rs:1679), and self-test OwnedContext paths through it, and the direct context cleanups in key.rs now call self.delete_context().
  • §1–§6 checks pass: no model gating (§1), no hacks/params (§2), fail-closed safety semantics preserved (§3), clean human commit attribution and Signed-off-by with Assisted-by: in PR body (§4), KUnit + J293 hardware/regression evidence (§5), and naming (§6).

Blockers (1)

  1. CI failure in SEP source checks / source (tools/aurora-sep/tests/test_key_context_cleanup.py):
    • test_key_context_cleanup.py extracts two slices from drivers/soc/apple/key.rs and compiles them standalone with host rustc:
      • pub(crate) trait ContextDelete .. impl ContextDelete for SepData (lines 959–973), which now pulls in latch_failed_delete(failed: &kernel::sync::atomic::Atomic<bool>, ...) (key.rs:967-972).
      • struct Deleter { .. // Production kernels do not build (lines 2544–2645), which now pulls in only_a_failed_key_context_delete_latches() (key.rs:2636-2644).
    • Standalone host rustc has neither kernel::sync::atomic::Atomic nor Relaxed, so test_production_context_disposal fails to compile (E0433 / E0425), breaking SEP source checks / source (https://github.com/aurora-silicon/linux/actions/runs/45216423162/job/137838678293).
    • Fix: Move latch_failed_delete() outside the ContextDelete..impl ContextDelete for SepData slice (e.g., below OwnedContext or inline in impl ContextDelete for SepData) and move only_a_failed_key_context_delete_latches() below // Production kernels do not build (or update test_key_context_cleanup.py if you want the host harness to exercise the latch helper with an atomic shim).

Non-blocking notes

  • only_a_failed_key_context_delete_latches() currently tests only the 4-line latch_failed_delete() helper in isolation rather than testing OwnedContext + ContextDelete latching vs. close_unlock_evaluation() not latching.
  • Pre-existing: key_context_for() (key.rs:1732) still returns early via .ok_or(EIO)? on a None transport reply from scrd_context_externalize(&ctx) without calling delete_context(&ctx).

Assisted-by: LLM (Gemini 4 Neon)

delete_unlock_evaluation() set key_context_failed on any failed delete,
and every /dev/sep-bio verify closes its unlock evaluation through it.
One failed delete at the end of a Touch ID prompt therefore turned off
/dev/sep-key until reboot, while the verify that hit it still reported
its match. That evaluation authorizes no key operation.

Set the latch only where a key operation's context is deleted: in
SepData's ContextDelete, which OwnedContext uses (including the context
a touch-gated key operation hands to the prompt), and in the key.rs
paths that delete a context directly. close_unlock_evaluation() and
delete_unlock_evaluation() now only log a failed delete.

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

key_context_for() creates a tracked context and then externalizes it.
A refused externalize deleted the context, but one that got no reply
returned EIO with the context still alive in the enclave, and nothing
deleted it until the enclave restarted.

Delete it on both: the context exists once it is created. A delete
that then fails latches /dev/sep-key, as for any key context.

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

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Fixed in the push:

Blocker (test_key_context_cleanup.py): latch_failed_delete() now sits after impl ContextDelete for SepData and only_a_failed_key_context_delete_latches after the // Production kernels do not build marker, so neither is in the host harness's slices. Every SEP source checks / source test passes locally, and KUnit is 309 of 309 at each commit.

Non-blocking notes:

  • The KUnit case now drives OwnedContext::finish() and drop through a deleter that latches with latch_failed_delete(), as SepData's does: a confirmed delete leaves the latch clear, a failed one sets it, and a later confirmed one leaves it set. That close_unlock_evaluation() doesn't latch is still checked only by reading it, since it needs a live SepData.
  • key_context_for(): fixed in a second commit. An externalize that gets no reply now deletes the context too, instead of returning EIO with it alive. The no-reply path hasn't happened on hardware.

The J293 row in the description ran on the previous revision; only the move and the no-reply delete have changed since.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formal §1–§6 pre-PR checklist re-review at 4fbabf61e49dcdbe732231f545705ad79db7af6b.

Verdict: APPROVE — the prior CI blocker and both non-blocking notes from 1a969ee7 are cleanly resolved.

Verification of Fixes Since 1a969ee7

  • CI blocker (SEP source checks / source — tools/aurora-sep/tests/test_key_context_cleanup.py): Resolved. latch_failed_delete() now sits after impl ContextDelete for SepData (drivers/soc/apple/key.rs:977) and only_a_failed_key_context_delete_latches() sits below // Production kernels do not build (key.rs:2641), keeping kernel atomics out of the standalone host rustc slices. SEP source checks / source is now success (alongside host-tests, DWC3/ATC builtin-no-atc, and DWC3/ATC modular-no-atc; remaining kunit, rust-build, and DWC3/ATC builtin-modular-atc jobs are still running/queued and must finish green before merge).
  • KUnit coverage: only_a_failed_key_context_delete_latches() now drives both OwnedContext::finish() and drop(OwnedContext) through a latching ContextDelete implementation, verifying confirmed delete leaves the latch clear, failed finish/drop sets it, and a later confirmed delete preserves the latched state.
  • Commit 2 (4fbabf61e49d — key_context_for() no-reply externalize cleanup): Sound. If scrd_context_externalize(&ctx) is refused or returns None (no reply), key_context_for() now deletes the already-created tracked context via self.delete_context(&ctx) (latching if that delete fails) before returning Err(EIO), matching passcode_context().

Checklist Summary (§1–§6)

  • §1 (No model gating): Pass — generic SEP driver change.
  • §2 (Production-ready / default cmdline): Pass — no cmdline params, retries, or hacks.
  • §3 (Safety): Pass — fail-closed /dev/sep-key quarantine is strictly preserved for all key contexts (password-gated, touch-gated OwnedContext, self-tests, and key_context_for() externalize failures), while non-key /dev/sep-bio unlock evaluations (close_unlock_evaluation() / delete_unlock_evaluation() and failed preflight in open_unlock_evaluation()) log without bricking /dev/sep-key.
  • §4 (Clean-room & attribution): Pass — both commits (791ebdb9fad8, 4fbabf61e49d) carry human author/committer (Cameron Cooper <c@meron.cc>) and human Signed-off-by: only (zero AI trailers in commits); PR body includes Assisted-by:.
  • §5 (Evidence): Pass — 309/309 SEP KUnit tests pass on arm64 QEMU at each commit, SEP source checks / source passes, and J293 (M1) live hardware + regression run (1a969ee7, with only helper/test placement and the key_context_for() None-reply error path changed since) verified password sign/unseal, 10 Touch ID unlocks, SEP_KEY_GET_INFO, 0 failed units, and 0 new kernel errors.
  • §6 (Naming): Pass.

Assisted-by: LLM (Gemini 4 Neon)

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