Skip to content

ASoC: apple: require speaker protection and lock fixed controls - #510

Merged
RyanTheTide merged 2 commits into
aurora-wipfrom
fix/macaudio-refuse-unprotected-speakers
Oct 27, 2026
Merged

RyanTheTide merged 2 commits into
aurora-wipfrom
fix/macaudio-refuse-unprotected-speakers

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

A generic apple,macaudio card with a Speaker backend could bypass speaker admission when please_blow_up_my_speakers=2, then register with neither a safe volume lock nor an energy gate. Require an enabled supported amplifier/layout and a negative configured safe volume before adding a Speaker/Speakers backend. Generic and unsupported SSM3515 backends stay disabled for every parameter value, and protection setup failures are fatal.

Fixed speaker transforms must also reject direct ALSA writes. snd_soc_deactivate_kctl() sets INACTIVE, which hides controls but leaves WRITE intact. Set each fixed enum during the existing control fixup, deactivate it and remove WRITE from every matched element before the card is published. This covers ASI1 selection, HPF corner, OCE handling and the dormant SSM3515 DAC analog gain setup. Supported dynamic volume/gain controls keep their existing protection and ownership path. No new parameter or energy-gate dependency is introduced; the deprecated parameter cannot weaken these checks.

Inherited impact: the same writable HPF behavior exists at parameter 0 in aurora-wip source, including remote base 927a4a4480cf90ce8e3b4ab1d1ce58d84bf32fd4 and locally tracked 04a63b11701363386e3691b7ffa7e64eef477fa7. Their speaker-setup functions are identical. Kernels deployed from this code inherit the gap; it is not conditional on an unsafe fleet parameter. A source-composed host witness confirms that a valid direct write reaches the enum callback after deactivation. This task did not issue a live-device ioctl or perform playback.

Validation:

  • Standalone admission KUnit passes 1/1 on the exact corrected driver/header with retained UML dependencies. It covers the generic fallback, unsupported SSM3515, missing safe volume/layout/amplifier, supported TAS/software-gain configurations and parameter values 0, 1, 2, 3 and -1. This focused compile/test is not a full bootable aurora-wip build.
  • The new no-device host regression extracts the actual speaker setup, ALSA pattern matcher, enum setter/put, activation and element-write functions. Both input-validation settings pass: 590 attempted writes each, 1,180 total, including every fixed element, mono/stereo prefixes and unrelated jack controls. Fixed writes return -EPERM without invoking the register callback; unrelated controls remain writable.
  • The identical final regression fails against pre-fix ASoC: apple: require speaker protection and lock fixed controls #510 and aurora-wip source in both validation settings, including at parameter 0. Those failures are retained as before-fix evidence.
  • git diff --check passes. No hardware access, playback or deployment. Keep draft for the independent re-check.

Host reproduction, from a kernel source tree with a C compiler:

python3 tools/testing/selftests/alsa/macaudio-fixed-controls.py

For standalone KUnit, enable CONFIG_KUNIT, CONFIG_COMPILE_TEST, CONFIG_SOUND, CONFIG_SND, CONFIG_SND_SOC, CONFIG_OF, CONFIG_I2C, CONFIG_DMADEVICES and CONFIG_SND_SOC_APPLE_MACAUDIO, then select apple-speaker-admission* with tools/testing/kunit/kunit.py run --kunitconfig=<config> --jobs=8. This PR targets aurora-wip independently of #495 so it can be reviewed ahead of the playback-energy series.

Do not let the legacy unsafe parameter admit an unsupported backend, skip
safe-volume setup failures or expose fixed protection controls. Generic
apple,macaudio and SSM3515 backends remain disabled. Require a supported
amplifier, speaker layout and negative safe volume before adding a Speaker
link. Keep the parameter accepted for compatibility, without unsafe overrides.

Add a hardware-free KUnit regression covering generic fallback, unsupported
and missing-protection configurations with parameter 2 and other values,
plus the supported TAS and software-gain paths.

Signed-off-by: Ryan Murray <[email protected]>

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Independent re-review of f0f840c6cef1c7eb8a3f8b3f962d8540f4b846f2.

P1: the HPF remains writable; this head should stay blocked. macaudio_set_speaker() now unconditionally calls snd_soc_deactivate_kctl(..., "HPF Corner Frequency", 0), but that helper only sets INACTIVE. The pinned snd_ctl_elem_write() checks WRITE and ownership, not INACTIVE. TAS2764's normal SOC_ENUM retains WRITE and includes item 0 (Disabled). A process with access to the card's control device can therefore issue ELEM_WRITE to disable the tweeter's configured 800 Hz HPF while the daemon continues holding its usual protection controls. This needs no unsafe parameter. It is an inherited gap, not a newly introduced parameter branch.

Source: machine setup, deactivation, activation flags, write authorization, codec enum.

A host-only witness executes those exact ALSA activation/write/enum functions with one control and an in-memory register. With input validation both disabled and enabled it reports access=0x103 old_hpf=6 new_hpf=0 write_rc=0. Clearing WRITE makes the same call return -EPERM; foreign ownership also blocks it. The harness uses valid-value info/validation shims; I separately read the real info/range validators and found no INACTIVE rejection. This tests the permission/callback composition, with no device or playback, and makes no measured-damage claim.

Remove userspace WRITE from fixed speaker transforms before publication, covering existing protected routes independently of the energy-gate feature. #495 already has the missing read-only-control step. Audit ASI1/OCE as well and test that a direct HPF write fails, rather than testing only the admission predicate.

The original unsafe-admission defect is fixed: no production branch in this head reads please_blow_up_my_speakers; generic/SSM/NONE/zero-safe-level configurations cannot enter the speaker route. Exact production predicates and fleet initializers were compiled independently: J316, J413, J700 and J616 remain admitted at parameter 0. This confirms admission, not a boot qualification.

The associated #495/#21 fixes were also re-reviewed: both delivered windows and the joint background bound pass the targeted independent checks. The exact daemon suite retains its two known listening failures (324 passed, 2 failed, 1 ignored); these are not waived.

Verdict for this exact head: BLOCK — HPF deactivation is not write exclusion. Comment-only review; no hardware, playback, source changes or pushes.

INACTIVE hides a control but does not reject direct ALSA element writes.
Set each fixed speaker enum during control fixup, deactivate it, and
remove WRITE access from every element before publishing the card.
Cover ASI1 selection, HPF corner, OCE handling and the dormant DAC gain
setup independently of the deprecated unsafe parameter.

Add a no-device host regression composing the actual speaker setup and
ALSA matcher, enum setter, activation and element-write functions with
in-memory registers. Require EPERM for direct writes to fixed controls,
while unrelated jack controls remain writable. Cover both input-validation
settings, mono and stereo prefixes, all elements and parameter values.

Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide RyanTheTide changed the title ASoC: apple: refuse unprotected speaker backends regardless of unsafe parameter ASoC: apple: require speaker protection and lock fixed controls Oct 27, 2026

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Independent re-check of #510 at 0f830f8c816a489f0aef7b6432b3b99ff181fa97 against aurora-wip 927a4a4480cf90ce8e3b4ab1d1ce58d84bf32fd4. I read the full diff and the ALSA/ASoC permission, registration, codec and fleet configuration paths. No blocking finding in the fixed-control/admission change.

  • All fixed enum families use the new helper: ASI1, HPF Corner Frequency, OCE Handling and the dormant/refused SSM3515 DAC analog gain. It clears WRITE on every matched element before card publication. Direct ALSA element writes return -EPERM before the callback; required setup errors remain fatal.
  • Fresh unchanged macaudio-fixed-controls.py: the pinned aurora-wip fails (exit 1; 480 violations per validation mode); the PR passes (exit 0; 1,180 attempts across both validation modes, zero violations).
  • Additional independent full-fixup scenarios pass 3,500 access/write checks, using the actual fleet initializers and J316/J616 numbered-woofer prefixes. J316, J413, J700 and J616 retain admission at parameter zero. Ordinary volume, gain, mute/pin, route and unlock controls retain WRITE; fixed transforms retain READ and reject writes. Generic/unprotected configurations remain refused. The deprecated parameter has no production data dependency, so no integer value bypasses admission or protection.
  • Fresh exact-head UML KUnit: admission 1/1 PASS. ARM64 macaudio W=1 compile: PASS. Fresh full ARM64 aurora_j700_defconfig build (Image modules dtbs, Clang 22.1.6/Rust 1.96.0, committed CONFIG_WERROR=y retained): PASS, exit 0, Image + 2,543 modules + fleet DTBs. The exact-head source checkout remains clean.

The exploratory full W=1 build fails with CONFIG_WERROR=y in unchanged ARM64 syscall initialization, BPF format annotation and FUSE comparison; that failure is retained and is not counted as a pass. No source/configuration relaxation is used for the standard build.

These are source, host-regression and build conclusions. Host fixtures use serialized-lock/topology/valid-input/register shims; ordinary callback stand-ins test access, not live volume/route behavior. No hardware, playback, recording, deployment, pushes or merge. This re-check does not qualify a physical transfer certificate or the separate energy-gate PRs.

MERGE-OK — fixed speaker transforms reject direct writes; fleet admission and ordinary controls are preserved; KUnit and the standard ARM64 build pass.

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