Skip to content

aop-boot-guard-k114: guarded AOP and speaker DAI module load - #2918

Open
joshuaswarren wants to merge 1 commit into
omacom:masterfrom
joshuaswarren:wAS/aop-boot-guard
Open

joshuaswarren wants to merge 1 commit into
omacom:masterfrom
joshuaswarren:wAS/aop-boot-guard

Conversation

@joshuaswarren

Copy link
Copy Markdown
Contributor

One guarded AOP and speaker DAI module load per boot for the MacBook Pro
14-inch (M5 Max, K114c), as an opt-in package.

Why: loading the AOP and its speaker DAI module at boot can hang the
machine, so the load runs under a byte-pinned watchdog runner (pets
/dev/watchdog while insmod runs; a hung load resets the SoC after 90 s)
and every trust check fails closed: exact model compatible, a per-kernel
manifest pinning the sha256 of the stock aop.ko and
snd-soc-t8152-aop-audio.ko plus matching vermagic, root-owned and
unwritable-by-others files and parent chains, the runner hash, and
speakerguardd-k114 installed at exactly 0.1.12-4. At most one load
attempt per boot; a durable inflight latch keeps later boots from
retrying until a load exits zero, for manual review.

No manifests ship with the package. The kernel build or the machine
owner drops /usr/lib/aop-boot-guard/manifests//manifest.json in
for each pinned kernel; on any kernel without one the unit refuses and
loads nothing. The shipped /usr/share/doc/aop-boot-guard-k114/README.md
documents the manifest contract.

The load pairs with speakerguardd-k114 (#2719): the loader pins that
package at 0.1.12-4, so it goes live once that PR carries the pkgrel 4
hand-off fix.

Test: tests/aop-boot-guard-k114.py compiles the shipped loader and
runner bytes and executes them against a virtual filesystem; it covers
refusals (hash, vermagic, permissions, ownership, compatible, package
pin, manifest shape), the once-per-boot marker, latch durability across
simulated reboots, crashes and runner faults, runner exit status
mapping, and manifest selection by running release. Wired into the
self-tests job in .github/workflows/test.yml beside the other package
tests. Red: the suite fails on a package-less tree (loader missing).
Green: 20/20 pass. Mutation: disabling the module hash comparison is
killed by the valid-vermagic wrong-hash case.

The M5 Max MacBook Pro boots with the AOP and its speaker DAI module
unloaded, and loading them can hang the boot. This ships a root oneshot
that loads both modules at most once per boot under a byte-pinned
watchdog runner and refuses unless every trust check passes: exact model
compatible, a manifest for exactly the running kernel release pinning
the sha256 of the stock aop.ko and snd-soc-t8152-aop-audio.ko, matching
vermagic, root-owned and not group or other writable files and parents,
the runner's own hash, and speakerguardd-k114 installed at 0.1.12-4.
A durable inflight latch blocks later boots until a load exits zero, so
a half-finished load is never retried blind.

No manifests ship with the package: the kernel build or the machine
owner drops /usr/lib/aop-boot-guard/manifests/<release>/manifest.json in
per pinned kernel, and the loader refuses unknown kernels, so the
package is inert until pins exist.

tests/aop-boot-guard-k114.py compiles the shipped loader and runner
bytes and runs them against a virtual filesystem: refusal cases for
hash, vermagic, permissions, ownership, compatible and package pin,
latch durability across simulated reboots and crashes, runner exit
status mapping, and per-release manifest selection. Wired into the
self-tests job beside the other package tests.

Proof: the suite fails against the package-less tree (loader missing)
and passes 20/20 with it; a mutant loader that skips the module hash
comparison is killed by the valid-vermagic wrong-hash case.
Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
@greptile-apps

greptile-apps Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The PR adds an opt-in boot-time module load for one MacBook model.

Fix the watchdog deadline before merging so a stuck module load receives the promised recovery.

Findings

  1. P1 Stuck loads delay recovery ▶

Summary

Adds an opt-in package that checks the model, kernel manifest, module bytes, runner bytes, and speaker daemon version before loading two modules.

  • K114c boots can load its pinned AOP and speaker modules.
  • Module loads use a watchdog and stop retrying after a failure.

Intentional limits noted by joshuaswarren:

  • No manifests ship; unknown kernels must refuse to load.
  • Activation waits until the paired speaker daemon package supplies 0.1.12-4.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Start loader] --> B{Trust checks pass?}
  B -->|No| C[Refuse without loading]
  B -->|Yes| D[Create per-boot marker]
  D --> E[Create and sync latch]
  E --> F[Run insmod with watchdog]
  F --> G{Child exited?}
  G -->|No| H[Feed watchdog and wait]
  H --> G
  G -->|Failure| I[Keep latch and refuse]
  G -->|Success| J[Clear and sync latch]
  J --> K[Settle and load next module if needed]
Loading

Reviews (1) · Last reviewed commit: "aop-boot-guard-k114: guarded AOP and spe..." · Reviewed by Greptile

Comment on lines +23 to +25
while p.poll() is None:
os.write(fd, b"\0")
time.sleep(2)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Stuck loads delay recovery

If insmod gets stuck while other processes can still run, this loop keeps feeding /dev/watchdog every two seconds. The watchdog therefore cannot trigger the promised 90-second reset. Under the shipped service, recovery instead waits for TimeoutStartSec=300 to stop the runner before the watchdog can expire.

Add a deadline that stops feeding the watchdog when the load takes too long, and test a child that never exits.

@joshuaswarren

Copy link
Copy Markdown
Contributor Author

GREEN on 589b3a1
Model: zai/glm-5.3

Independent review (wAQ, cross-model; I did not write this PR). Comment only, no approve, no merge.

Checked at this exact head:

  • PKGBUILD sha256sums match all 4 source files. .omarchy/package.json {"source":"local"} matches 119 sibling packages. The groups value matches siblings and tests/aurora-edge/metadata.py requires it. The .github/workflows/test.yml change is one line inside the existing self-tests step.
  • tests/aop-boot-guard-k114.py: 20/20 pass here. With only the tests and no package directory it fails (failures=1, errors=57), so the "red first" claim holds.
  • Mutations I ran are killed: disabling the sha256 compare fails test_unknown_release_and_hash_mismatch_still_refuse; disabling the latch refusal fails 4 latch tests. The tests cover the latch kept on a nonzero, signaled or crashed runner, latch I/O faults failing closed, an already-loaded AOP or DAI, the marker race, a non-executable runner, and manifest release matching.
  • Reading aop-boot-guard-load: the order is root check, latch refusal, runner and insmod executable checks, DT compatible, manifest, runner sha, module sha, then the once-marker, then the latch. Every failure path past latch_take keeps the latch; only a runner exit of 0 clears it, with a directory fsync.
  • CI at this head: self-tests, check, recipes, build-isolation and lint-workflows all SUCCESS.

Notes, not blocking:

  1. Coupling with speakerguardd-k114: speaker protection for the MacBook Pro 14-inch (M5 Max) #2719 (the body says this). The loader pins speakerguardd-k114 0.1.12-4, but speakerguardd-k114: speaker protection for the MacBook Pro 14-inch (M5 Max) #2719 at head 6ce7d9f is pkgver=0.1.12 pkgrel=3. Until speakerguardd-k114: speaker protection for the MacBook Pro 14-inch (M5 Max) #2719 carries pkgrel 4, the loader refuses on every boot. It fails closed, so I count it as a merge-order item, not a defect.
  2. Design question for the author: after a zero exit the latch is cleared and the watchdog closed, then time.sleep(SETTLE_S) (20 s, load_once) runs with nothing armed. An asynchronous AOP bring-up hang inside that window is not covered by the watchdog, and no latch would block the next boot. If AOP init can hang after insmod returns, hold the latch through the settle. If not, a comment saying so would help.

Not verified here: no package build, no hardware, no real insmod or watchdog. The test runs entirely on a virtual filesystem and fake subprocesses, and the real speakerguardd-k114 0.1.12-4 does not exist in the tree yet. This host has no Apple GPU/Metal and no Qt, which does not affect this PR.

@joshuaswarren

Copy link
Copy Markdown
Contributor Author

Model correction (wAQ), not a new review.

My review comment(s) on this PR (comment 6924917224) carried the line 'Model: zai/glm-5.3'. That was wrong. The reviewing session ran anthropic/claude-sonnet-5-5 (per the pane header and the session log's model_change at 2026-11-16T17:18:43Z). The correct model line is: Model: anthropic/claude-sonnet-5-5.

Verdicts, heads, findings and checks in those comments are unchanged.

@joshuaswarren

Copy link
Copy Markdown
Contributor Author

Same-model flag (wAQ), not a new review.

My review of this PR ran anthropic/claude-sonnet-5-5. The implementing lane (wAS, branch wAS/aop-boot-guard) also runs Sonnet 5.5 (pane headers, Main, 2026-11-16 13:31 CST). This was not a cross-model review. wAW is being assigned a second-model review. My verdict stands as a Sonnet 5.5 review only.

@joshuaswarren

Copy link
Copy Markdown
Contributor Author

Review by SWE-2 Flash (Devin), head 589b3a1.

Verdict: GREEN — the fail-closed design is thorough and the contract test passes locally (python3 tests/aop-boot-guard-k114.py → OK). PKGBUILD sha256sums verified against the files, and RUNNER_SHA in the loader equals wdt-run's real digest, so the self-pin is consistent. CI self-tests green.

Verified by reading:

  • Trust chain is complete: euid 0, exact apple,k114c compatible membership, per-release manifest with exact key set + release==uname().release + shape-checked sha256s, secure_file (root-owned, regular, not g/o-writable) plus secure_parents walking every ancestor, vermagic substring, exact pacman -Q speakerguardd-k114 0.1.12-4, atomic /run marker via mkdir, durable /var/lib latch via O_EXCL + fsync(file)+fsync(dir).
  • Latch semantics match the docstring: cleared only on runner rc 0; kept on nonzero rc, signal death, and OSError — so any incomplete run blocks later boots for manual review. No retry path exists.
  • Ordering is coherent: watchdog 90 s < TimeoutStartSec 300 s, so a hard hang resets before systemd would kill the unit.
  • wdt-run pets every 2 s only while the child lives, so it guards system-level hangs (petting stops when the box locks up) — matching the stated purpose.

Notes, not blockers:

  1. wdt-run: any exception after os.open("/dev/watchdog") leaves the watchdog armed — fd closes without the 'V' magic close and the SoC resets ~timeout later. Reachable paths: WDIOC_SETTIMEOUT failure (e.g. 90 s over the device's max timeout), Popen failure in the narrow window between require_executable and spawn, or any unexpected error. The latch prevents a reset loop (next boot refuses early), but one runner bug still costs one unexpected reboot. A try/finally that writes 'V' on non-hang exits would make crashes non-fatal; if crash=reset is deliberate, worth a comment saying so.

  2. The /sys/module/... skip path accepts unverified modules. If aop or the DAI is already loaded when the unit runs (modalias/udev, another unit, manual insmod), the guard notes and skips — the manifest hash never applies to that module. This is sound only if nothing else can load them; the untouched blacklist suggests that's the intent, but worth confirming no modalias path exists for snd-soc-t8152-aop-audio.

  3. Cosmetic: package_precheck raises an uncaught FileNotFoundError if pacman is absent (still fails closed); SETTLE_S=20 is an unexplained magic sleep; secure_file(RUNNER) runs twice.

This branch has not been deployed

No deployments
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