Repository navigation
ASoC: apple: macaudio: lock only the driver's own speaker volumes - #2893
Conversation
The legacy "Speaker Volume Unlock" interface found the speaker volume controls at run time by matching the card's control list against a name pattern. User-defined elements (SNDRV_CTL_IOCTL_ELEM_ADD) are on the same list and may carry any name. They are not ASoC controls: they have no soc_mixer_control in private_value, so snd_soc_limit_volume() must not be handed one, and they must not take part in the lock's ownership check or in the volumes kept across a system sleep. Make snd_soc_control_matches() never match a user-defined element, so snd_soc_limit_volume(), snd_soc_deactivate_kctl() and snd_soc_set_enum_kctl() only see driver controls. In macaudio, have macaudio_vlimit_unlock(), macaudio_vlimit_update() and macaudio_pm_volumes_save() walk ma->spk_vols, the driver's own volume controls taken before the card registers, as the "Speaker Protection" lease already does. The same controls as before are locked, checked, kept and restored. Add a KUnit case with a user-defined element named like a speaker volume, and the define the userspace harness of macaudio-fixed-controls.py now needs. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
|
Review at f1d4416. The set of controls the legacy lock clamps is unchanged for driver controls:
Rows owed at this head (silent only): |
There was a problem hiding this comment.
Formal §1–§6 pre-PR checklist review at f1d4416384adaedfe886591df581b289212db134 (host-tests: green).
The direction is right: ignoring SNDRV_CTL_ELEM_ACCESS_USER elements in snd_soc_control_matches() closes a real NULL-dereference path in soc_limit_volume() from user-added elements, and walking ma->spk_vols avoids runtime name matching on the legacy lock/PM paths. However, there are two blockers preventing APPROVE / MERGETRAIN-LINUX4:
Blockers
- §2 / §3 Safety — Unbind/rebind OOB write and NULL dereference on
ma->spk_vols(sound/soc/apple/macaudio.c:2188-2216,:3536-3568):macaudio_spk_take_volumes()allocates a freshdevm_kcalloc(dev, nr, ...)array and populates it withma->spk_vols[ma->spk_nr_vols++] = kctl;without resettingma->spk_nr_vols = 0, andmacaudio_card_remove()never resetsspk_nr_vols(norspk_nr_hpfsorspk_nr_amp_gains, which share the same pattern at:2252and:2340).- If a codec/amp driver unbinds and rebinds while the
macaudioplatform device persists, ASoC runscard->removethencard->late_probeon the samema: the secondmacaudio_spk_take_volumes()writesnrpointers past the end of the newly allocatednr-element array and leavesma->spk_vols[0..nr-1]NULL, which immediately crashes whenmacaudio_vlimit_unlock()dereferenceskctl->id.nameat:566during the samelate_probe(). - Previously only the lease path read
ma->spk_vols; this PR moves all legacy speaker safety clamp, ownership check, and sleep-save paths onto it. Please resetspk_nr_vols,spk_nr_hpfs, andspk_nr_amp_gains(and clear the pointers) inmacaudio_card_remove()/ at the start of eachmacaudio_spk_take_*()helper, and add a KUnit regression test covering take → remove → re-take.
- §5 Evidence — Missing hardware test rows:
- Zero hardware runs have been executed yet (explicitly listed under
## Still to run). Because this changes speaker volume locking, ownership checks, and PM save/restore across all protected speaker backends, please add silent hardware rows on the default cmdline (reading back volume values and max limits at boot-locked, daemon-unlocked, and post-s2idle re-lock/restore, plus 0 SELinux denials / 0 failed units / 0 new kernel errors) covering SN012776, TAS5770, and MAX98360A (J700 software gain).
- Zero hardware runs have been executed yet (explicitly listed under
Non-blocking Nits
sound/soc/soc-ops.c:411-415: User-defined elements do have aprivate_valuefield (initialized to0); the issue is that it is not astruct soc_mixer_control *. Tightening the comment will make that precise. Also consider splitting the core ASoCsoc-ops.cchange into its own commit for cleaner upstreaming, since it affects allsnd_soc_limit_volume()/snd_soc_deactivate_kctl()/snd_soc_set_enum_kctl()callers.sound/soc/apple/macaudio.c:565-578:hitsis now always equal toma->spk_nr_vols(whichmacaudio_spk_take_volumes()guarantees non-zero atlate_probe). Either drop the dead!hitsbranch or add a brief comment if retained defensively forsw_gain_limit_failed.
Checklist Summary
- §1 No model gating: Pass.
- §2 Production-ready: Fail — unbind/rebind
spk_nr_volsOOB/NULL-deref bug above. - §3 Safety: Fail — directly impacts the speaker volume clamp lifecycle on card rebind.
- §4 Clean-room & attribution: Pass — human author/committer (
Ryan Murray <ryan@aurorasilicon.org>) + humanSigned-off-by:only, zero AI trailers in commit,Assisted-by:in PR body. - §5 Evidence: Fail — KUnit (
apple-speaker-pm-volumes) andW=1compile pass, but zero hardware rows run yet. - §6 Naming: Pass.
…bind macaudio_spk_take_volumes(), macaudio_spk_take_amp_gains() and macaudio_spk_take_hpfs() allocate a new array sized for the controls they find and append to it from the kept count, which nothing resets. When the card is bound again, after a codec was unbound and bound, the count still holds the previous binding's controls: the appends run past the end of the new array, and its first entries stay unset. The old entries also keep pointing at the controls of the card that went away. Forget the kept speaker volumes, amp gains and tweeter high-pass controls when the card is removed, and have each take helper drop what it kept before it allocates again. The legacy lock leaves the volumes failed closed when none is kept; say so where it reports that. Add a KUnit case that takes the volumes again after they were dropped, as a second bind does, and checks the lock and system-sleep paths still cover exactly the speaker volumes. Also make the comment in snd_soc_control_matches() precise about a user-defined element's private_value. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
|
Thanks for the review; both points taken. New commit 0f62162 (no history rewrite):
Assisted-by: LLM (Claude:Opus 5.5) |
|
Review at 0f62162. New commit 0f62162 on top of f1d4416, with no rewrite. It adds
No new issues. There are no gates or new parameters, and the commits carry only the human Signed-off-by. Verdict: NITS. The code is ready. Merging waits on the silent hardware rows, which RyanTheTide said are being built. Owed, all silent and on the default cmdline: |
There was a problem hiding this comment.
Formal §1–§6 pre-PR checklist re-review at 0f62162c634912537e17b15ea4468b4a0277a8b5 (host-tests: green; mergeStateStatus: CLEAN).
Code & Safety Assessment — Prior Blocker 1 Resolved (0 code blockers)
- Prior Blocker 1 (unbind/rebind OOB write & NULL dereference on
spk_vols/spk_amp_gains/spk_hpfs) — Resolved: Commit0f62162c6349addsmacaudio_spk_drop_{volumes,amp_gains,hpfs,controls}(), drops the kept control arrays undervolume_lock_mutexinmacaudio_card_remove()(afterspk_dead = trueunderspk_mutexand after cancelling all lease/lock timers and works), and drops prior state before reallocating in all threemacaudio_spk_take_*()helpers. New KUnit testmacaudio_pm_volumes_taken_againverifies take → drop → take and subsequent lock/PM behavior (apple-speaker-*62/62,W=1clean). - Prior nits — Resolved:
sound/soc/soc-ops.ccomment accurately states that a user-defined element'sprivate_valueis not astruct soc_mixer_control, and the!hitsbranch inmacaudio_vlimit_unlock()is documented as fail-closed. - Non-blocking observation: In
macaudio_vlimit_unlock()(sound/soc/apple/macaudio.c:576-590),!hitssetssw_gain_limit_failedforAMP_MAX98360Aand logs an error, but does not setspeaker_lock_failedfor other amps (if (failed && !unlock)). Unreachable on a bound card becausemacaudio_late_probe()requiresnr > 0, so non-blocking.
Remaining §5 Blocker Holding APPROVE / MERGETRAIN-LINUX4
- Prior Blocker 2 — Silent hardware rows still pending: As noted in the latest comment, silent hardware rows on the default cmdline (SN012776, TAS5770, and MAX98360A/J700 software gain: volume/max readback at boot-locked, daemon-unlocked, and post-s2idle re-lock/restore + 0 SELinux denials / 0 failed units / 0 new kernel errors) are still being built/run and have not been posted yet. Holding
APPROVE(priorCHANGES_REQUESTEDremains active) until those rows land.
Checklist Summary
- §1 No model gating: Pass.
- §2 Production-ready: Pass.
- §3 Safety: Pass (unbind/rebind OOB/NULL-deref bug resolved).
- §4 Clean-room & attribution: Pass — both commits carry human author/committer (
Ryan Murray <ryan@aurorasilicon.org>) + humanSigned-off-by:only, zero AI trailers in commits;Assisted-by:in PR body. - §5 Evidence: KUnit (
apple-speaker-*62/62) +W=1+host-testsgreen; withholdingAPPROVEstrictly pending posted silent hardware rows for SN012776, TAS5770, and MAX98360A. - §6 Naming: Pass.
There was a problem hiding this comment.
Formal §1–§6 pre-PR checklist review at 0f62162c634912537e17b15ea4468b4a0277a8b5 (REQUEST_CHANGES — 0 code/policy/attribution/CI blockers; holding formally on missing §5 hardware rows).
Verified Clean
- §1 No model gating: Pass.
- §2 Production-ready / no hacks: Pass — commit
0f62162c6349resolves the prior unbind/rebindspk_nr_*OOB/NULL-deref blocker by droppingspk_vols,spk_amp_gains, andspk_hpfsinmacaudio_card_remove()undervolume_lock_mutex(afterspk_dead = trueand cancelling lease/lock timers and works) and before reallocating in all threemacaudio_spk_take_*()helpers, with KUnit coverage (macaudio_pm_volumes_taken_again). - §3 Safety: Pass —
snd_soc_control_matches()rejectsSNDRV_CTL_ELEM_ACCESS_USER, andmacaudio_vlimit_unlock(),macaudio_vlimit_update(), andmacaudio_pm_volumes_save()walkma->spk_volstaken beforesnd_card_register(). Checked against liveintegration/aurora(70a00e583b03, including226c7903c9forspk_ceiling_level): orthogonal and not superseded. - §4 Clean-room & attribution: Pass — both commits (
f1d44163,0f62162c) carry human author/committer + humanSigned-off-by:only; PR body includesAssisted-by:. - §6 Naming & CI: Pass —
host-testsgreen (1/1).
Remaining Blocker Before Approval (§5 Evidence)
- Zero hardware rows posted at
0f62162c6349: Please post the pending silent hardware rows on the default cmdline covering each protected speaker amp family (SN012776, TAS5770, and MAX98360A / J700 software gain): volume values and max limits read back at boot (locked), after daemon unlock, and after s2idle re-lock/restore, with explicit regression counts (0 SELinux AVC denials, 0 failed units, 0 new kernel errors).
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge at 0f62162c6349: the code looks right, but this is the speaker volume lock, so it needs silent rows before it merges. I'm leaving this as a comment, not an approval, until they're in.
Blockers:
- Missing rows (speaker safety, no playback): one Mac per protected amp family (SN012776, TAS5770, and the J700's MAX98360A software gain). On each: the volume values and limits read back locked at boot, unlocked only after speakerguardd takes over, and locked again after an s2idle.
Checked: no Apple material, no gates. The lock now covers only the driver's own speaker volumes. CI green.
Superseded by the review at 0f62162
satchlj
left a comment
There was a problem hiding this comment.
Gemini 4 Neon on @satchlj's behalf:
Verdict: COMMENT at 0f62162c6349 (code audited clean; holding approval for speaker-safety hardware rows)
Code Audit
Audited both commits (f1d44163 + 0f62162c6349, both with Signed-off-by: Ryan Murray) and sound/soc/apple/macaudio.c:
snd_soc_control_matches()(sound/soc/soc-ops.c) rejectsSNDRV_CTL_ELEM_ACCESS_USERviakctl->vd[0].accessbefore pattern matching, preventing spoofed userspace ALSA controls from matchingsnd_soc_limit_volume()or the driver's take helpers.macaudio_vlimit_unlock()andmacaudio_pm_volumes_save()walkma->spk_vols[]instead of the card's live control list, and fail closed (sw_gain_limit_failed/ error log) when!hits.0f62162c6349cleanly fixes the re-bind lifetime gap:macaudio_spk_drop_{volumes,amp_gains,hpfs}()drop/free thedevm_*arrays inmacaudio_card_remove()(undervolume_lock_mutex, afterspk_deadand cancelling lease timer/work) and before reallocating in eachmacaudio_spk_take_*()helper.- KUnit coverage (
macaudio_pm_volumes_ignore_user_elementsandmacaudio_pm_volumes_taken_again) directly verifies both invariants, and CI is green.
Minor Non-Blocking Note
macaudio_is_amp_gain()(sound/soc/apple/macaudio.c:2271-2272) usessnd_soc_control_matches(kctl, "* Amp Gain Volume") || !strcmp(kctl->id.name, "Amp Gain Volume"). Sincesnd_soc_control_matches()handles exact non-wildcard names too, usingsnd_soc_control_matches(kctl, "Amp Gain Volume")for the second clause would consistently rejectSNDRV_CTL_ELEM_ACCESS_USEReven if ever invoked post-registration (safe today becausemacaudio_spk_take_amp_gains()runs inmacaudio_late_probe()before card registration).
Merge Readiness
Concurring with @DjDeveloperr: leaving a comment rather than an approval until silent speaker-safety hardware rows (SN012776, TAS5770, and J700 MAX98360A software gain) are attached at head 0f62162c6349.
There was a problem hiding this comment.
Verdict: Changes requested at 0f62162c6349.
The exact-head no-device fixture fails to compile. It extracts macaudio_spk_take_hpfs() but does not include the new macaudio_spk_drop_hpfs() it calls. Please bring the fixture boundary up to date, including its allocation shim as needed, and rerun both validation modes. Hosted host-tests is green, so please retain the standalone fixture run in the evidence. The silent v2 speaker-family rows and restore checks remain open.
…pfs() macaudio_spk_take_hpfs() now calls macaudio_spk_drop_hpfs() first, but the no-device fixture only extracted the take helper, so the standalone fixture stopped compiling. Extract the drop helper too, shim devm_kfree(), and release each HPF capture through the real drop helper instead of free() so the next capture does not free the same arrays twice. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
…device
macaudio_pmt_pm_card() now registers a KUnit device named
"macaudio-pmt-test", and the vlimit cases from main build several cards
in one case. The second kunit_device_register() then fails ("Driver
'macaudio-pmt-test' is already registered") and
macaudio_vlimit_needs_every_volume aborts. Number the device name per
card. Test-only; no driver change.
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
|
Pushed fixes for the fixture finding, plus a forward merge. New head is 64b0e48.
|
There was a problem hiding this comment.
Verdict: FINISH at 64b0e48
Checked: The follow-up extracts the real HPF drop helper with a matching allocation shim, verifies the cleared capture, and gives each KUnit card a distinct name. The reported fixture rerun addresses the build finding. Keep the silent v2 family lock/unlock/relock and restoration evidence before landing.
Forward-merge main. Main (d64ac37, v2-only speaker ownership) resets spk_nr_vols/spk_nr_hpfs before taking the controls again on a rebind; this branch's macaudio_spk_drop_volumes()/drop_hpfs() already free the arrays and zero those counts there, so the take helpers keep the drop calls. The no-device fixture keeps main's dynamic HPF safe item selection and still extracts macaudio_spk_drop_hpfs(). No speaker protection behaviour changes. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
|
Forward-merged current main (2fd49a6) into this branch; new head acabd40 (no force push). This is a conflict resolution only: no speaker protection behaviour changes. |
There was a problem hiding this comment.
Verdict: HOLD — acabd40638e6 forward-merge and driver/fixture fixes are clean; awaiting queued CI and exact-head silent hardware rows per amp family
Blockers:
- Exact-head silent hardware rows at
acabd40638e6: One Mac per amp family (SN012776,TAS5770, andJ700MAX98360A) confirming speaker volumes and limits stay locked at boot, unlock only afterspeakerguarddtakes over, relock and restore cleanly acrosss2idle, with 0 AVC denials, 0 failed units, and 0 new kernel errors. - Hosted CI at
acabd40638e6: Wait for the queued CI checks (includingreadiness, build, host-tests, andapple-speaker-*KUnit) to finish green.
Checked:
- Forward-merge
acabd40638e6(main2fd49a614f3d): Cleanly resolves conflicts againstmain'sd64ac3782ae9(macaudio.ckeepsmacaudio_spk_drop_volumes()/macaudio_spk_drop_hpfs(), which already free thedevm_*arrays and zerospk_nr_vols/spk_nr_hpfs;macaudio-fixed-controls.pykeepsmain's dynamic HPF safe-item selection alongsidemacaudio_spk_drop_hpfs()extraction anddevm_kfree()shim). - Driver & core changes (
sound/soc/soc-ops.c,sound/soc/apple/macaudio.c):snd_soc_control_matches()rejectsSNDRV_CTL_ELEM_ACCESS_USERbefore pattern matching, preventing spoofed user-defined ALSA controls from matching any ASoC pattern walker.macaudio_vlimit_unlock(),macaudio_pm_volumes_save(), andmacaudio_vlimit_update()walkma->spk_vols[0..ma->spk_nr_vols]rather than rescanningcard->controls, failing closed when!hits.macaudio_spk_drop_controls()clears all three cached arrays inmacaudio_card_remove()undervolume_lock_mutex(after cancellinglock_timeout_work), preventing stale pointers or appended duplicates on ASoC card rebind.
- Tests (
macaudio-pm-volumes-test.h,macaudio-fixed-controls.py): Unique per-card KUnit device names (macaudio-pmt-test-%u),macaudio_pm_volumes_ignore_user_elements,macaudio_pm_volumes_taken_again,apple-speaker-*KUnit 80/80 PASS,macaudio-fixed-controls.py678/678 in both validation modes, andW=1LLVM build 0 warnings. - Checked for Apple material, tool attribution, private serials, and gating: clean.
Evidence
- Head:
acabd40638e6(base: main,mergeable: MERGEABLE,+190/-20across 4 files). - Hosted CI at
acabd40638e6:2P/0 real failures/3Q(priorreadinesscancelled; current checks queued).
|
acabd40 3-Mac SILENT PASS (J316s TAS5770 + J615 SN012776 + J700 Neo): combined guarded one-shot |
|
Merging at |
Problem
The legacy "Speaker Volume Unlock" interface in macaudio finds the speaker volume controls at run time by matching the card's control list against name patterns (
snd_soc_control_matches(), e.g."* Speaker Volume"). User-defined elements (SNDRV_CTL_IOCTL_ELEM_ADD) live on the same list and can carry any name. Such an element is not an ASoC control: it has nosoc_mixer_controlinprivate_value, sosnd_soc_limit_volume()must never be handed one, and it must not take part in the lock's ownership check or in the volumes kept across system sleep.Change
snd_soc_control_matches()never matches a user-defined element (SNDRV_CTL_ELEM_ACCESS_USER). Every pattern walker built on it (snd_soc_limit_volume(),snd_soc_deactivate_kctl(),snd_soc_set_enum_kctl()) now only sees driver controls.macaudio_vlimit_unlock()), its ownership check (macaudio_vlimit_update()) and the system-sleep save (macaudio_pm_volumes_save()) walk the driver's own speaker volume controls, taken once before the card registers (ma->spk_vols, as the "Speaker Protection" lease already does), instead of rediscovering them by name.SNDRV_CTL_ELEM_ACCESS_USERdefine it now needs.No change for the driver's own controls: the same controls are locked, checked, kept and restored.
macaudio_card_remove()forgets them, and eachmacaudio_spk_take_*()helper drops what it kept before it allocates again, so a second bind (a codec unbound and bound) no longer appends past the new array or keeps pointers to the old card's controls. The!hitsbranch of the legacy lock is kept as the fail-closed case for "none kept" and now says so; thesnd_soc_control_matches()comment is precise aboutprivate_value.Testing
KUnit (arm64 under QEMU): new case
macaudio_pm_volumes_ignore_user_elementsinapple-speaker-pm-volumes: a user element named like a speaker volume does not match the pattern, does not hold the volumes locked, is not clipped, kept or restored over a system sleep; fails without the change. Allapple-speaker-*suites pass.W=1 build of sound/soc/soc-ops.o and sound/soc/apple/macaudio.o with no new warnings.
Follow-up: new KUnit case
macaudio_pm_volumes_taken_again(take, drop as card remove does, take again; the lock and the system-sleep save still cover exactly the speaker volumes). It fails without the follow-up (the second take keeps 8 entries in a 4-entry array). Allapple-speaker-*suites pass, 62/62. One run hadmacaudio_spk_withdrawal_rampsfail its 20 ms wall-clock bound at 22.4 ms on the emulated arm64 QEMU on a loaded build machine; the rerun passed, and that test does not touch this code. W=1 build ofmacaudio.oandsoc-ops.ogives no new warnings.Still to run