Repository navigation
dmaengine: apple-admac, ASoC: apple: aop_lpai: keep no client pointer across a restore; bound the low-power microphone's periods and ring by its format - #2934
Conversation
…inter admac_device_config() saves the whole dma_slave_config so that a channel can be set up again after a system sleep took its registers. The copy includes peripheral_config, a pointer to memory the client only guarantees for the duration of the call: the AOP audio driver passes the address of a local variable. admac_restore_chan() then calls admac_device_config() on the saved copy and reads the realign frame size through that pointer again, long after the client returned. Split the register programming out into admac_program_config(), which the restore calls on the saved copy. admac_device_config() takes the frame size from the client's config once (it was assigned twice) and stores the copy with peripheral_config cleared, so a restore keeps the frame size the client configured and never touches the client's memory. Add a KUnit case that configures a capture channel, overwrites the client's frame size, marks the channel lost and restores it. Fixes: d9b438c ("arm64: apple: support coordinated suspend-to-RAM on T8140") Signed-off-by: Ryan Murray <[email protected]>
…format The low-power microphone takes its stream format and, on T6041, its ring geometry from properties of the AOP's audio service. The PCM limits are computed from the rate: the shortest period is PERIOD_MS_MIN of frames, and the most periods is the buffer limit divided by it. A rate that gives no whole frame in that time made the shortest period zero and the division one by zero, and a rate large enough overflowed the product; both stop the kernel when the PCM is opened. Compute the shortest period with checked arithmetic when the format is read, and refuse a format whose shortest period is empty or longer than the longest period the PCM offers. Such a format leaves the PCM out, as the other unusable formats do. The host ring was sized as frames times frame bytes with only a 4 GiB limit, and was allocated before the binding. Bound it by the ring's own format: at most RING_SECONDS_MAX (16) seconds of that format, four times the four seconds the firmware describes at any rate and channel count, and at most a fixed 64 MiB ceiling, which is above four seconds of the fastest format the PCM offers. Refuse a larger ring before anything is allocated, together with the report-interval checks that were already there, in one helper. Add KUnit cases for formats with and without a valid period range and for ring geometries on both sides of the time and byte limits, and for four seconds of every rate and channel count the ring takes. Signed-off-by: Ryan Murray <[email protected]>
|
Review at 85730ab.
Rows owed at this head (none posted): an lpai microphone open on J616s and J713 with the dev_dbg geometry line (aop_lpai.rs:688) captured; s2r MCA playback on J616s or M2 (exercises the restore). The realign_sense s2r V/I capture (J813, J815 or J714s) is still open, as the body says. |
There was a problem hiding this comment.
Formal §1–§6 pre-PR checklist review at 85730ab049e3fa178ab7618c1095aa09688c43f8.
Checklist Summary
- §1 No model gating: Pass —
apple-admacpreserves client-supplied realign frame size without chip checks;aop_lpaibounds the ring from the stream's own format (RING_SECONDS_MAX = 16 s) plus a64 MiBceiling well above 4 s of the fastest offered PCM format. - §2 Production-ready: Pass — no new parameters or hacks.
- §3 Safety: Pass —
apple-admac.c: splits register programming intoadmac_program_config()(which never touchesperipheral_config/peripheral_size), readsadchan->realign_bytesonce inadmac_device_config()(dropping the duplicate assignment), clearsadchan->cfg.peripheral_config = NULLandperipheral_size = 0, and leavesadchan->realign_bytes/adchan->cfguntouched on programming failure.admac_restore_chan()callsadmac_program_config()only, closing the dangling stack-pointer UAF on S2R restore.aop_lpai.rs:StreamFormat::period_bytes_min()uses checkedu64arithmetic and enforces1..=PERIOD_BYTES_MAX(65536), guaranteeinghw()never divides by zero andBUFFER_BYTES_MAX / period_min >= 8 >= PERIODS_MIN (2).ring_geometry()uses checked arithmetic to reject empty rings,frames > rate * 16,bytes > 64 MiB,quantum == 0, andquantum > frames / 2; every valid 4 s format (up to204899 Hz x 8 ch x 4 B = 26.2 MiB) passes comfortably under the 64 MiB ceiling.
- §4 Clean-room & attribution: Pass — both commits (
fa152b667f91,85730ab049e3) carry human author/committer (Ryan Murray <[email protected]>) and humanSigned-off-by:, zero AI trailers in commits. - §5 Evidence: Pending — KUnit C + Rust suites pass (
admac_restore_keeps_the_frame_size,a_format_without_a_valid_period_range_is_refused,the_ring_geometry_is_bounded_by_its_format), but hardware rows are still owed (lpai open +dev_dbggeometry on J616s/J713, s2r MCA restore, andrealign_senses2r V/I capture on J813/J815/J714s). - §6 Naming: Pass.
- CI (at review time):
host-testsqueued.
Verdict
COMMENT — 0 code/policy blockers; waiting on queued host-tests CI to complete green and the owed §5 hardware rows.
RyanTheTide
left a comment
There was a problem hiding this comment.
Independent source review at 85730ab049e3. The low-power capture path now derives period and ring limits from the firmware-reported format, and the ADMAC resume path stops using saved client state. Please verify on the J413 that a silent mic capture stopped at suspend can reopen at the advertised format after wake, with no stale samples, xrun or DMA error.
There was a problem hiding this comment.
Formal §1–§6 pre-PR re-review at 85730ab049e3fa178ab7618c1095aa09688c43f8 against live integration/aurora (70a00e583b03).
Status & Code Assessment (0 code, CI, or attribution blockers)
- Not superseded: Live
integration/aurorastill retainsperipheral_configacross S2R restore indrivers/dma/apple-admac.c:839-840,1523-1553and lacks checked period/ring-geometry bounds insound/soc/apple/aop_lpai.rs:627-634,788. - §1 No model gating: Pass — no chip/SoC/board/firmware gates;
aop_lpaiderives ring limits from the firmware-reported stream format (RING_SECONDS_MAX = 16 s) plus a 64 MiB upper cap well above 4 s of the fastest valid PCM format (204899 Hz x 8 ch x 4 B = 26.2 MiB). - §2 Production-ready & §3 Safety: Pass —
apple-admac.c: splits register programming intoadmac_program_config()(non-sleeping, safe underadchan->lockduringadmac_restore_chan()), readsrealign_bytesonce inadmac_device_config()(removing the duplicate assignment), clearsadchan->cfg.peripheral_config = NULLandperipheral_size = 0, and preserves state on failure — closing the dangling stack-pointer UAF on S2R restore.aop_lpai.rs:StreamFormat::period_bytes_min()enforces1..=PERIOD_BYTES_MAXwith checkedu64arithmetic sohw()cannot divide by zero or invert bounds;ring_geometry()validatesframes,bytes, andquantumwith checked arithmetic beforeadata.bound_ring()allocates anything.
- §4 Clean-room & attribution: Pass — both commits (
fa152b667f91,85730ab049e3) carry human author/committer (Ryan Murray <[email protected]>) and humanSigned-off-by:only, zero AI trailers;Assisted-by:is in the PR body. - §6 Naming & Live CI: Pass —
host-testsis COMPLETED / SUCCESS on85730ab049e3, and QEMU arm64 KUnit C + Rust suites pass.
Blocker Holding APPROVE / MERGETRAIN-LINUX4
- §5 Hardware test & regression rows missing: Zero hardware rows have been posted yet (
### Hardware rowsstill lists fleet82 one-shot boots on M1 Pro, M2, J616s, J473 asPending). Please post exact-head hardware evidence on the default cmdline covering:aop_lpailow-power microphone open/capture (includingdev_dbgring/format geometry on J616s / J713 or affected AOP Macs);- ADMAC restore path across suspend/resume (e.g., audio playback/capture across S2R on J616s/M2/J413, confirming clean reopen with no stale samples, xruns, or DMA errors);
- §5 regression numbers (0 SELinux 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 85730ab049e3: the code is ready; it needs only a row at this head.
Blockers: none in the code. Missing row: one boot at this head with the aop_lpai low-power mic opening and capturing, and an ADMAC audio stream across a restore (an s2idle), on one of the pending Macs (M1 Pro, M2 or J616s).
Checked: no Apple material, no gates. No client pointer is kept across a restore. CI green.
Superseded by the review at 85730ab
|
|
Two fixes in the Apple audio DMA and low-power microphone paths.
Problem and change
peripheral_configpointer, and the restore read the realign frame size through it again. A client only guarantees that memory for the duration of the call (the AOP audio driver passes the address of a local). The frame size is now taken once when the client configures, the saved copy carries no pointer, and the restore only programs the registers (admac_program_config()).RING_SECONDS_MAX(16 s) of it, four times the 4 s the firmware describes at any rate and channel count, plus a fixed 64 MiB ceiling that is above 4 s of the fastest format the PCM offers. The first version's fixed 1 MiB cap is gone.No parameters, no chip/board/firmware gates.
Testing
integration/auroraa7638d5 + this series:CONFIG_UCLAMP_TASK);admac_restore_keeps_the_frame_sizepasses and FAILS without the admac fix.a_format_without_a_valid_period_range_is_refusedandthe_ring_geometry_is_bounded_by_its_formatpass. The ring test covers 4 s of every rate (8 to 192 kHz) and 1 to 8 channels, 16 s at the time limit, the byte ceiling, and the old interval checks. With the first version's 1 MiB cap put back it FAILS.Still to run
realign_senseboard (J813, J815 or J714s); we have none in our lab.Hardware rows
Pending: one-shot boots of fleet82 + this series on the default cmdline (M1 Pro, M2, J616s, J473), compared with the same rows on the production kernel. They will be added here.
Reviewer detail
admac_device_config()callsadmac_program_config(), then setsrealign_bytesonce from the client's config (the duplicate assignment is gone) and saves the copy withperipheral_config = NULL,peripheral_size = 0.admac_restore_chan()callsadmac_program_config()on the saved copy, sorealign_bytesstays as the client set it. MCA clients pass noperipheral_configand behave as before.ring_geometry(format, frames, quantum)refuses an empty ring,frames > rate * RING_SECONDS_MAX,bytes > RING_BYTES_MAXand the existing quantum checks, all with checked arithmetic.period_bytes_min()returnsNoneoutside1..=PERIOD_BYTES_MAX;hw()uses the checked value.ring_step()is untouched.