Skip to content

KEYS: trusted: keep a trusted-key source that registers before init_trusted() - #350

Merged
RyanTheTide merged 2 commits into
aurora-wipfrom
fix/trusted-keys-init-order
Oct 17, 2026
Merged

RyanTheTide merged 2 commits into
aurora-wipfrom
fix/trusted-keys-init-order

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

If apple_sep is built in (CONFIG_APPLE_SEP=y), it registers its trusted-key source from probe at device_initcall. init_trusted() runs later, at late_initcall, finds no built-in source, and resets the static-call dispatch to the absent stubs. It does that without taking the source lock and without checking for a registered source. The source still holds the slot, so add_key trusted "new 32" then fails with -ENODEV, even though "source registered" was logged. The shipped Neo config builds apple_sep as a module (=m), so it isn't affected. A built-in build is: for example, the linux-aurora package's shared config asks for APPLE_SEP=y.

Fix (2 commits)

  1. KEYS: trusted: Test trusted-key sources registered at runtime. This ports the 7.2.10 KUnit suite trusted_source, which uses a synthetic source with no hardware and no real keys.
  2. KEYS: trusted: Keep a source that registers before init_trusted() (Fixes: bac0846c9087).
    • Source selection moves into trusted_key_core_init(), under trusted_key_source_lock.
    • If a source is already active, it keeps the slot and the dispatch. Otherwise mainline's selection is unchanged.
    • Both orders now follow the same rule: the first source up keeps the slot, a later one gets -EBUSY, and trusted.source= / trusted.rng= are checked on both paths.
    • The helper is exported only for KUnit. KUnit adds trusted_source_before_core_init and trusted_source_after_core_init.

Testing

  • Review: independent, PASS (0 BLOCKER/MAJOR). Two MINOR follow-ups.
  • KUnit: trusted_source 7/7 plus 1 skip. The built-in order was also reproduced and checked end to end in QEMU, on both 7.1 and 7.2.10.
  • MacBook Neo, on the SEP fix integration kernel 7.1.12-aurora-sepfix-g598fa89b (aurora-wip 545d7e45 + this + soc: apple: sep: hold hwrng requests across system sleep and recover a timed-out entropy exchange #351's SEP fixes):
    • trusted_key: source 'applesep' registered;
    • a trusted-key smoke test passed: add, pipe and load with an identical blob, update returns EPERM;
    • Touch ID restored on the first attempt;
    • 0 WARN.
  • M1 Pro, on the same tree: the source registered once, and seal and unseal work.
  • Build: the published config builds with 0 warnings, and a KUNIT_ALL_TESTS=m modpost is clean.
  • 7.2.10: the equivalent commit goes into the next 7.2.10 top-up.

🤖 Generated with Claude Code

Add KUnit tests for register_trusted_key_source() and
unregister_trusted_key_source(), with a synthetic source that touches no
hardware and no real key material. They cover dispatch to the source
and back to the absent stubs when it withdraws, the migration policy
that each registration brings (a key update included), a second source
being refused and unable to withdraw the first, a failing init(), and
incomplete sources.

Built in, KUnit runs before mark_readonly(), so one case, which
registers with read-only-after-init data protected, skips there and
says so. Loaded as a module after boot, as apple_sep is, the whole
suite runs that way.

[ryan: on 7.1 'migratable' is still writable, so registration after
 mark_readonly() cannot fault here. The case guards against a backport
 of the v7.2 change that makes it read-only after init.]

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
A trusted-key source module that is built in registers from its probe:
apple_sep with CONFIG_APPLE_SEP=y probes at device_initcall, before
init_trusted() runs at late_initcall. init_trusted() then looks for a
built-in source, finds none, and points the dispatch at the absent
stubs, without taking the source mutex or checking for a registered
source. That source still holds the slot, so nothing can take it again.
Every new trusted key now fails with -ENODEV after registration was
logged as a success, and the key type stays registered. A modular
apple_sep loads after init_trusted() and is not affected.

Mainline chooses the source once, in init_trusted(). Keep it that way,
and have init_trusted() defer: under the source mutex, it leaves the
slot and the dispatch to a source that is already active, and otherwise
chooses as before. Whichever source comes up first keeps the slot, and
a later one still gets -EBUSY; trusted.source= and trusted.rng= are
checked on both paths, as before.

The choice moves into trusted_key_core_init(), which the KUnit tests
call with synthetic sources, in both orders: a source that registers
before the core's init keeps the slot and its migration policy, and one
that registers after it replaces the absent stubs.

Fixes: bac0846 ("soc: apple: add Apple SEP driver (Touch ID and key sealing)")
Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide
RyanTheTide merged commit 46980a4 into aurora-wip Oct 17, 2026
@RyanTheTide
RyanTheTide deleted the fix/trusted-keys-init-order branch October 17, 2026 10:01
RyanTheTide added a commit that referenced this pull request Oct 17, 2026
Bring the 7.2.10 assembly to the tree of the canonical top-up #6
assembly, stacked on top-up #5 f34b5ae so that it is a
fast-forward of the published branch. The second parent is that
canonical assembly; the tree is identical to it.

Ported from aurora-wip, each with cherry-pick -x and its original
author:
- #347 KUNIT_ALL_TESTS=m modpost (3): the xHCI platform tests call the
  interrupt handler through the HC driver (170-usb), and module
  descriptions for the CD321x PM tests (170-usb) and the drm/apple
  KUnit test modules (200-dcp).
- #349 the CD321x IRQ test waits for the resume read before checking
  its retry (170-usb).
- #350 trusted keys keep a source that registers before
  init_trusted() (100-sep). Its test commit is already carried as
  76d70cc and is not duplicated.
- #351 SEP hwrng: recover the entropy exchange after a request times
  out, and hold entropy requests while the system sleeps (100-sep).
- #352 SEP SBIO: take a reply header only once it has landed, and
  poison it again once read and before each host send (100-sep).

Adaptations, each with a [ryan: ...] note in its commit:
- trusted-type.h: context only, the declaration goes above the
  7.2.10 CONFIG_TRUSTED_KEYS_DEBUG block;
- the CD321x IRQ test takes its data from tipd_hw_variants[], and its
  retry loop replaces the 7.2.10-only fix of the same race in
  11e0ce6.

The Co-Authored-By lines of the three #347 commits are dropped.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
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