Repository navigation
ASoC: apple: t8152-aop-audio: check the sense reader's pointer before using it - #3312
Conversation
… using it The speaker sense ring callback works out how many frames the sense front-end's reader has not taken yet as hw_ptr - appl_ptr modulo the boundary. appl_ptr is the reader's: it can write it through the mapped control page at any time, with any value. A value past hw_ptr plus the boundary, such as ULONG_MAX, makes hw_ptr + boundary - appl_ptr underflow, and with Rust overflow checks that panics, which is a BUG() in the DMA callback. Read appl_ptr once, and take both pointers only as positions below a non-zero boundary. Otherwise stop the stream with an XRUN, as when the batch does not fit. Set SNDRV_PCM_INFO_SYNC_APPLPTR on the sense front-end too, so that ALSA gives its reader no writable control page: the reader then moves appl_ptr through ALSA, which checks it. alsa-lib does this on its own when the page is not mapped. Add KUnit tests for the pointer checks (ULONG_MAX, the boundary, past hw_ptr plus the boundary, no boundary, a hardware pointer out of range, and wrap-around), for the XRUN decision, and for the flag. Signed-off-by: DjDeveloperr <[email protected]>
|
Verdict at Blockers: none. Checked:
EvidenceHead
ALSA and ASoC paths read at this head: |
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
J714s (MacBook Pro 14" M5 Pro, T6050) row at
1. Capture device: 2. Playback through speakerguardd: pink noise for 60 s at 5 % sink volume, through
3. Idle probe: speakerguardd stopped, and the sense PCM free (
4. One deep 5. Kernel log: 0 A full power-off wasn't run: this unattended lab Mac has no remote way to power back on. The clean reboot path was exercised. |
RyanTheTide
left a comment
There was a problem hiding this comment.
Verdict at dfc98f5e: code OK. Merge after the J714s Speaker Sense row the body lists, since this touches the speaker-protection data path.
Checked
- The sense reader's pointer is checked before use. With the old arithmetic the new KUnit case panics (subtract overflow), and with this change it passes: 8/8, with overflow checks and debug asserts on.
- T8152 (no sense ring) is unaffected.
Before merge: a J714s row at this head on the Speaker Sense capture PCM, as described in the body: speakerguardd v2 running, quiet start, sense frames flowing, no guard trip.
There was a problem hiding this comment.
Verdict: MERGE at dfc98f5 after hosted checks
Checked bounded pointer arithmetic, invalid pointers taking the XRUN path, and the Sense-only synchronized application pointer flag. The J714s receipt covers protected playback, Sense capture and deep resume on the reviewed source.
|
code-owner ping @DjDeveloperr: closeout merge of your PR at |
|
Merging under the 6-point rule (Ryan 09:29, permanent), at |
What: The speaker sense ring callback now checks the sense reader's
appl_ptrbefore computing how many frames are unread. Before, a value pasthw_ptrplus the boundary (for exampleULONG_MAXwritten through the mapped control page) underflowedhw_ptr + boundary - appl_ptr. With Rust overflow checks that panics, aBUG()in the DMA callback. An out-of-range pointer now stops the stream with an XRUN. The sense front-end also setsSNDRV_PCM_INFO_SYNC_APPLPTR, so its reader movesappl_ptrthrough ALSA's checked path instead of a writable control page.Tested: KUnit at dfc98f5 (arm64 QEMU,
SND_SOC_APPLE_T8152_AOP_AUDIO=y,RUST_OVERFLOW_CHECKS=y,RUST_DEBUG_ASSERTIONS=y):snd_soc_apple_t8152_aop_audio8/8 (3 new), the whole run 48 passed and 1 skipped (unrelated). With the old arithmetic restored, the new test panics withattempt to subtract with overflowandkernel BUG at rust/helpers/bug.c:7. Hardware row still owed (below).Risk: two-way door · Macs with the driver-owned sense ring: T6050 (J714s, J716c) and T8142 (J813, J815). T8152 (J873g) has no sense ring and is not affected.
Not yet: J714s row at this head on the Speaker Sense capture PCM: speaker protection running at 5% volume with sense frames flowing, the control page no longer mappable, a malformed
appl_ptrrefused, and 0 Rust panics, BUG or Oops.Details
sense_fe_unread(hw_ptr, appl_ptr, boundary)returns the unread frames, orNoneunless the boundary is non-zero and both pointers are below it. The modular case useschecked_add.sense_fe_takes()combines that with the existingsense_ring_has_fe_space(), which was already checked.deliver()stops the stream with an XRUN when it says no, as it did before for a full buffer.boundary == 0already ended in an XRUN, throughunread = frames; it still does.appl_ptris read once, withread_volatile, since the reader can change it at any time.hw_ptrandboundaryare kernel-owned, but they are range-checked too.SNDRV_PCM_INFO_SYNC_APPLPTRis set only on the sense front-end (sense_pcm_hw()).pcm_control_mmap_allowed()). The status page stays mappable for alsa-lib 2.0.14 and later.SNDRV_PCM_IOCTL_SYNC_PTRon its own.pcm_lib_apply_appl_ptr()refuses anappl_ptrat or past the boundary there.aop_lpai.rsandaop_t8140.rskeep driver-ownedhw_ptr_bytesand never readappl_ptr.mca.cuses dmaengine PCM. None has this pattern.appl_ptr = usize::MAX, thenappl_ptr > hw_ptr + boundary. They also coverappl_ptr == boundary, boundaries of 1, 4096, 2^30,usize::MAX / 2andusize::MAX,boundary == 0,hw_ptrat or past the boundary, and both sides of the wrap.Evidence
Head
dfc98f5efa461c4c78aca946c8aa7611e815daac, basemainef26a43be753.snd_soc_apple_t8152_aop_audio8/8; run total 49: 48 passed, 1 skipped (apple_g17_rx_util_min_test, needsCONFIG_UCLAMP_TASK)sense_fe_unread()doing the old arithmeticrust_kernel: panicked at sound/soc/apple/t8152_aop_audio.rs:395:9: attempt to subtract with overflow,kernel BUG at rust/helpers/bug.c:7!,Internal error: Oops - BUG; both new pointer tests failedDMADEVICESandAPPLE_ADMACare in the config because the driver callsdma_request_chan(), which only exists withDMA_ENGINE. Production configs already have it.checkpatch.pl: clean.rustfmt: the changed hunks are clean; the file has older formatting drift that this change doesn't touch.