Repository navigation
soc: apple: sep: report a refused identity unlock, and stop aurora-sep-load on it - #3274
Conversation
Every trusted-key seal and unseal on the 13.5 key store first unlocks the
identity key bag (DEVICE_STATE_TRANSITION on the designated user's special
handle). When the enclave answers that unlock with a non-zero status, the
driver logs "ref-key identity unlock refused (status N)" and the seal or
unseal fails with EIO. Nothing outside the kernel log says so, and a
caller cannot tell this from a key store that is still coming up.
On a J313 running the 27.2.1 sepOS the unlock is refused with status -8
on every boot, while the key-store init, LOAD and DESIGNATE still answer.
aurora-sep-load, which cannot see the refusal, retries the seal at 10 Hz
until its 120 s deadline: about 1200 refused seals and kernel warnings per
run, and the unit is started again on every fprintd activation.
Add diag/trusted, which reads:
unknown no trusted-key unseal has worked and no unlock was refused
ready the latest trusted-key unseal worked (a seal unseals its
new blob before returning it, so a working seal counts)
refused <n> the enclave answered the identity unlock with status <n>
The latest outcome wins, so an unseal that works after a refusal reads
"ready" again, and the value resets to "unknown" when the driver binds.
State and status share one atomic word, so a reader never pairs a state
with another refusal's status. The value comes from the enclave's own
answer: no chip, board or firmware version is consulted, and a Mac whose
enclave unlocks the bag sees only "unknown" and "ready".
Signed-off-by: Erik Bourget <[email protected]>
aurora-sep-load probes trusted keys with a seal and unseal every 0.1 s until AURORA_SEP_READY_TIMEOUT (120 s). Its only early exit is an xART guard refusal. When the enclave refuses the identity key-bag unlock that every seal needs, the probe repeats the same refused request about 1200 times, burns several seconds of CPU and logs a refusal and a "key_seal failed (-5)" line for each attempt. fprintd's drop-in requires aurora-sep.service, so every fprintd activation (a desktop shell polls fprintd-list every few seconds) starts the 120 s run again. Read the driver's diag/trusted after each failed probe and stop at the first "refused <status>", logging the status and that the key bag and ref-key are kept. A run started again in the same boot reads the attribute before it probes, so it sends no seal at all. An xART guard refusal is still checked first and keeps its own message, since it has a way out (aurora-sep-policy-change). Kernels without diag/trusted read nothing there and keep the old probe-until-deadline behaviour, as do enclaves that answer late rather than refuse. The tests run the shipped loader against a synthetic sysfs and a fake keyctl: the first refusal ends the run after one seal, a re-run sends none, a guard refusal keeps its message, a kernel without the attribute still waits for the deadline, and a working enclave still verifies. They also compile the driver's diag/trusted show and setter and check all three values, with negative and positive statuses. Signed-off-by: Erik Bourget <[email protected]>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
sks_prepare_identity_refkey() latches diag/trusted to "refused <status>" when the enclave refuses the identity key-bag unlock, so aurora-sep-load stops without retrying for 120 s. A subsequent successful unlock through /dev/sep-key (with_identity_bag()) calls sks_prepare_identity_refkey() as well, without going through refkey_unseal_trusted(), so diag/trusted stayed "refused <status>" and caused later loader runs to exit before probing. Add sep_diag_clear_trusted_refusal() and call it from sks_prepare_identity_refkey() only when the DEVICE_STATE_TRANSITION reply validates (status 0, 20-byte body with zero header). Using atomic_try_cmpxchg(), it clears SEP_DIAG_TRUSTED_REFUSED back to SEP_DIAG_TRUSTED_UNKNOWN while leaving SEP_DIAG_TRUSTED_READY untouched so "ready" remains tied to a working trusted-key unseal. Update Documentation/ABI/testing/sysfs-driver-apple-sep and extend tools/aurora-sep/tests/test_trusted_refused.py and the apple_sep KUnit tests (apple_sep_refkey_trusted) to cover refusal clearing and recovery. Signed-off-by: Erik Bourget <[email protected]>
|
Addressed the review findings in
Note on prior CI at Local verification at
J313 (M1 Air) at J716c (M5 Max, T6050, variant-5 key store) at |
|
The |
tools/aurora-sep/tests/test_diag_sensor.py compiles diag_shim.c and its
test harnesses against minimal stub kernel headers. In the kernel,
<linux/types.h> defines atomic_t, whereas the test's stub headers
placed the typedef in <linux/atomic.h>. Because drivers/soc/apple/shim.h
includes <linux/types.h> and declares sep_diag_*_atomic(atomic_t *, ...),
harnesses that include "shim.h" without <linux/atomic.h> failed to
compile with "unknown type name 'atomic_t'".
Move `typedef struct { int counter; } atomic_t;` from the stub
linux/atomic.h into the stub linux/types.h so "shim.h" compiles
standalone against the stubs, matching the kernel headers while leaving
all driver and loader files unchanged.
Signed-off-by: Erik Bourget <[email protected]>
|
Fixed the
Moved Verified at
|
RyanTheTide
left a comment
There was a problem hiding this comment.
Verdict at 2cdd990: merge once CI is green.
Blockers: none. The source fix moves the atomic_t typedef into the stub linux/types.h, and the kernel side is byte-identical to the 7711419 J313 row.
Question (please answer here; it does not block): the loader now stops at the first refused <status> instead of retrying for 120 s. Have you ever seen a refusal on this path turn into a success later in the same boot, for example right after first unlock or after resume? If that never happened in your J313 runs, one line saying so in the body would settle it. If it can happen, keep one bounded retry, a few seconds, before refused_exit.
Checked:
diag/trustedis one atomic word: state in the low byte, signed status above it, so a reader never sees a mixed pair. It is reset at bind ("a refusal belongs to the bind that saw it").Readyis set only by a working unseal; a validatedDEVICE_STATE_TRANSITION(20-byte body, zero status) clears only a refusal, through a cmpxchg loop. KUnit covers the short body, a bad status and the clear.- Loader: a kernel without the attribute reads empty and keeps the old loop. A re-run this boot (the fprintd dependency) exits at once on a known refusal. The xART guard message still comes first when both apply. The message tells users not to replace the key bag.
|
On J313 (27.2.1 firmware) a refusal never turned into a success later in the same boot.
A later validated |
What: On the 13.5
DEVICE_STATE_TRANSITIONidentity key-bag unlock path (sks_prepare_identity_refkey(); variant-5 key stores unlock the identity bag viasks_req_change_lock_stateon a separate path), when the enclave refuses the unlock,tools/aurora-sep/load-driver(aurora-sep-load) retried the trusted-key seal 10 times a second for 120 s, andaurora-sep-ready→aurora-touchid-bootheldmulti-user.target(and the desktop session) for 90 s behind it. The driver now reports refusals from thatDEVICE_STATE_TRANSITIONidentity-unlock path in a newdiag/trustedattribute (unknown/ready/refused <status>), clears stale refusals on a later validatedDEVICE_STATE_TRANSITIONidentity unlock, and the loader stops at the first refusal.Tested: At
2cdd990f389e(adds only thetools/aurora-sep/tests/test_diag_sensor.pystub-header fix over77114190bfb4; all kernel, driver, ABI documentation, andtools/aurora-sep/load-driverfiles are byte-for-byte unchanged from77114190bfb4):python3 -m unittest tools/aurora-sep/tests/test_diag_policy.py tools/aurora-sep/tests/test_diag_sensor.py -v(4/4, and 4/4 with-O),tools/aurora-sep/tests/test_trusted_refused.py(8/8),tools/asahi/run-host-tests.py --only sep-suspend(22/22), the remainingsep-source.ymlunit suites (120/120 across normal and-Oruns), andscripts/checkpatch.pl --strict --git 77114190bfb4..HEAD(0 errors, 0 warnings, 0 checks). Driver and loader runtime at77114190bfb4(unchanged in2cdd990f389e): J313 (M1 Air, T8103, 27.2.1 firmware) in fleet candidate5509a254a6bd(mainfcb124279183plus unchanged heads038ab73f52a6(#3220),5c89fbdf4ddc(#3221),2b1bab104938(#3297),4b09f0691c2d(#3300),d3cf4ca61518(#3329),b8530d17c96b(#3332),262e263dae4c(#3333), and77114190bfb4(#3274), merged without conflicts), default command line, J313 device tree built from the candidate on default Stage 2 (1.0.0b17-gf5ddfff2) as a one-shotaura-try, kernel installed next to the default and removed afterwards, Mac docked (Thunderbolt 5 dock with Ethernet and a3840x2160@120external display ondcpext), with this PR'stools/aurora-sep/load-driverinstalled as/usr/libexec/aurora-sep-loadfor the run (packaged loader restored afterwards):diag/protocolreadssepos13anddiag/trustedreadsready;aurora-sep.serviceloggedtrusted keys work after 4 sand/dev/sep-bio is available, with0key_seal failedand0identity unlock refusedlines;graphical.targetat 6.9-7.0 s (systemd-analyze8.5 s); a re-run of the service took 0.6 s and loggedtrusted keys work after 0 s;diag/trustedstayedreadyacross 2 deep sleeps and ans2idle;0failed units,0AppArmor denials (on that boot the enclave unlocked the identity key bag, so therefused <status>branch was not reached at77114190bfb4, covered by the earlier J313 row atd32a863c55ffwherediag/trustedreadrefused -8, 1 refused seal per boot vs 905,graphical.targetat 7.19 s vs 91.9 s, fprintd re-runs sent no seal, and 1 deep sleep resumed); J716c (M5 Max, T6050, variant-5 key store) in candidate3e4078f656d5(mainfcb124279183plus unchanged77114190bfb4and sibling PRs, default command line, with this PR'stools/aurora-sep/load-driverrun):diag/protocolreadsvariant5,diag/trustedreadsready,aurora-sep-loadloggedtrusted keys work after 1 sand/dev/sep-bio is available(rc0),aurora-sep-ready.serviceactive,0new failed units (aurora-peripherals.serviceandsystemd-networkd-wait-online.servicealso fail on default),0LSM denials,0SEP kernel errors (3booterrlines total:2xpre-existingsystemd-gpt-auto-generatorplusauroraGPUEPROBE_DEFERat0.65 s); SEP KUnit (apple_sep*) 319/319 pass.Risk: two-way door · every Mac with the SEP driver (one whose enclave unlocks the bag or uses the variant-5 key store only ever sees
unknownandready, and its loader path is unchanged)Not yet: a J313 run where the enclave refuses the identity unlock at
77114190bfb4/2cdd990f389e(therefused -8row ran atd32a863c55ff; at77114190bfb4the J313 enclave unlocked the bag).Details
Why the desktop waited. On the J313 with 27.2.1 firmware the enclave can answer the 13.5 identity unlock (
DEVICE_STATE_TRANSITION) with status -8 on boot, so no trusted key can be sealed.aurora-sep-loadcould not see that and probed until its 120 s deadline.aurora-sep-ready.service(Requires=/After=aurora-sep.service,JobTimeoutSec=90) waited for it, andaurora-touchid-boot.service(WantedBy=multi-user.target,After=aurora-sep-ready.service) waited for that. Somulti-user.targetandgraphical.targetcame up only at 91.9 s, anduwsmsat on a black screen through its 60 s "graphical.target is queued" countdown.Driver (
soc: apple: sep: report a refused identity unlock in diag/trusted,soc: apple: sep: clear stale diag/trusted refusal on identity unlock).sks_prepare_identity_refkey()recordsrefused <status>when the enclave answers the unlock with a non-zero status (a reply, not a lost one).DEVICE_STATE_TRANSITIONreply validates (mailbox status 0 and 20-byte zero-header response, including via/dev/sep-key'swith_identity_bag()),sep_diag_clear_trusted_refusal()atomically clearsrefused <status>back tounknownwhile leavingreadyuntouched soreadystays tied to a working trusted-key unseal and a subsequent loader run probes again.refkey_unseal_trusted()recordsreadyafter an unseal passes its write-refusal check. A seal unseals its own new blob before returning it, so a working seal also readsready.unknownat bind, andsep_diag_clear_trusted_refusal()usesatomic_try_cmpxchg()so a reader never pairs a state with another refusal's status.sysfs-driver-apple-sep.Loader (
tools/aurora-sep: stop the loader when the enclave refuses the unlock).diag/trusted, and atrefused*it logs the status and exits 1. It says that the key bag and ref-key are kept, and not to replace them.aurora-sep-policy-change).diag/trustedread nothing there and keep the probe-until-deadline behaviour, as do enclaves that answer late rather than refuse.Host test stubs (
tools/aurora-sep: define atomic_t in stub linux/types.h).drivers/soc/apple/shim.hincludes<linux/types.h>(where the kernel definesatomic_t) for itssep_diag_*_atomic(atomic_t *, ...)prototypes.tools/aurora-sep/tests/test_diag_sensor.pynow definestypedef struct { int counter; } atomic_t;in its stublinux/types.hinstead oflinux/atomic.h(which retains theatomic_*operations), so harnesses including"shim.h"without<linux/atomic.h>compile cleanly without modifying any driver header.Left as is.
fprintd.servicestillRequires=aurora-sep.service, so each fprintd activation starts the unit again; each start now exits in milliseconds with no SEP traffic. The packagedpkgrel/Releaseare not bumped here.Evidence
Same Mac, same session, default command line. A = baseline
mainat859e8a29796cwith the packaged loader (aurora-sep 1-25). B = this PR at tested headd32a863c55ff, built with the J313 config, booted once viagrub-reboot, with the PR'sload-driverinstalled as/usr/libexec/aurora-sep-load.d32a863c55ff)systemd-analyzegraphical.targetreacheduwsm"waiting for 60s"aurora-sep.servicefirst runkey_seal failedlines this bootidentity unlock refusedlinesdiag/trustedrefused -8rtcwake -d rtc1 -m mem -s 12)diag/trustedstillrefused -8aurora-sep.serviceaurora-sep.service(expected: the enclave refuses the unlock)errlinesapple-dcp ... AFK[ep:20]: failed to extract init props: -2)Loader line on B:
Resume on B also logged
PS fpwm1: Failed to reach power state 0xf, andUnable to change power state from D3hot to D0for brcmfmac and hci_bcm4377. Both drivers rebound by themselves (wlan0 came back up, ssh kept working). The trial kernel ismain, which lacks the T8103 PCIe sleep handling in open #3221. The lines are the same on the pre-rebase row and do not involve the SEP.Earlier row on the pre-rebase head
12d3f541d9d8(main40e5e29cc915+ these two commits, same Mac):refused -8, 1key_seal failed,graphical.target7.2 s (systemd-analyze7.174 s), re-runs at 10.0 s with no seal, deep sleep 16:10:31.57 → 16:10:46.55. The rebase ontomainresolved one conflict indiag_shim.cnext to #3168's kernfs fields, so the row above was run again atd32a863c55ff.77114190bfb4in fleet candidate5509a254a6bd(default command line, PRtools/aurora-sep/load-driverrun):diag/protocolsepos13,diag/trustedready,aurora-sep.serviceloggedtrusted keys work after 4 sand/dev/sep-bio is available(0key_seal failed,0identity unlock refused),graphical.target6.9-7.0 s (systemd-analyze8.5 s), re-run 0.6 s (trusted keys work after 0 s),diag/trustedstayedreadyacross 2 deep sleeps and 1s2idle,0failed units,0AppArmor denials.77114190bfb4in candidate3e4078f656d5(default command line, PRtools/aurora-sep/load-driverrun):diag/protocolvariant5,diag/trustedready,aurora-sep-load: trusted keys work after 1 s,/dev/sep-bio is available,rc 0,aurora-sep-ready.serviceactive;0new failed units (aurora-peripherals.serviceandsystemd-networkd-wait-online.servicealso fail on default),0LSM denials,0SEP kernel errors (3booterrlines:2xsystemd-gpt-auto-generatorplusauroraGPUEPROBE_DEFERat0.65 sbefore GPU came up).Off-Mac at
2cdd990f389e(host-test-only over77114190bfb4):python3 -m unittest tools/aurora-sep/tests/test_diag_policy.py tools/aurora-sep/tests/test_diag_sensor.py -v: 4/4 passed (and 4/4 withpython3 -O).python3 -m unittest tools/aurora-sep/tests/test_trusted_refused.py -v: 8/8 passed.python3 -I tools/asahi/run-host-tests.py --only sep-suspend: 22/22 passed.tools/aurora-sep/tests/remainingsep-source.ymlunit tests (test_store_open_errors.pynormal and-O,test_identity_preservation.pynormal and-O,test_sep_bio_identities.py,test_orphan_delete.py,test_enrol_admission.py,test_owner_preparation.py,test_policy_window.py,test_log_ratelimit.py,test_key_context_cleanup.py,test_packaging.py,test_sep_writes_always_on.py,test_boot_locks.py,test_kernel_log_anchor.py,test_collect_handover.py,test_touchid_package.py,test_root_staging.py): 120/120 passed.scripts/checkpatch.pl --strict --git 77114190bfb4..HEAD: 0 errors, 0 warnings, 0 checks.Off-Mac at
77114190bfb4(unchanged driver/KUnit code):drivers/soc/apple/sep.kunitconfig, QEMU arm64,'apple_sep*'): 319/319 passed (including 2 newapple_sep_refkey_trustedsubtests, run against a test-owned atomic without modifying livediag/trusted).tools/aurora-sep/tests/test_keystore_only.pypassesKeyStoreCacheTests(7/7) andLoaderTests(1/1) whileMachineRefkeyTestshas the same pre-existingsks_create_refkeyargument-count failure asmain.checkpatch.pl --strict --git d32a863c55ff..77114190bfb4: 0 errors, 0 warnings (859e8a29796c..77114190bfb4: 0 errors, 1 warning for new filetest_trusted_refused.py, MAINTAINERS).d32a863c55ff:trusted_sourceKUnit (security/keys/trusted-keys/tests/.kunitconfig, QEMU arm64) 8/9 passed, 1 skipped (trusted_source_after_mark_readonlywhen built-in).