Repository navigation
audio: aria: fix over-read of the internal ring buffer - #11499
Shrusti-pk wants to merge 1 commit into
Conversation
|
Can one of the admins verify this patch?
|
|
test this please |
lgirdwood
left a comment
There was a problem hiding this comment.
Also missing a SoB - pls add this to your Agents workflow.
| /* ensures buffer size is aligned to 8 bytes */ | ||
| cd->buff_size = ALIGN_UP(cd->chan_cnt * cd->smpl_group_cnt, 2); | ||
| cd->offset = (cd->chan_cnt * cd->smpl_group_cnt) & 1; | ||
| /* The ring holds exactly one chunk, a whole number of frames, so a |
There was a problem hiding this comment.
Pls check as the buffers need to work on SIMD vector size alignment not just frame alignments/sizes
There was a problem hiding this comment.
Checked. The ring is only an odd number of samples when the channel count is odd, and the odd channel paths in both aria_hifi3.c and aria_hifi5.c access it with 32-bit scalar loads and stores (AE_L32_XP and AE_L32_XC), so 4-byte alignment is all they need. The even channel paths are the ones doing 64-bit vector loads, and there the ring is always a multiple of 8 bytes: the allocation comes from mod_balloc, which is cache line aligned, and the pointers only ever advance by whole frames, so they stay 8-byte aligned. The old ALIGN_UP only padded the ring end anyway; with an odd sample count data_ptr started one sample in and changed alignment every period, so it didn't give vector alignment either. The allocation size in get_required_memory() is unchanged. I've expanded the comment here to spell that out.
aria keeps the last smpl_group_cnt frames of input in an internal ring and outputs them delayed by that amount. aria_algo_get_data() bounds each chunk by the distance from cd->data_ptr to the ring end, but when the sink buffer wraps first the read pointer has already moved past data_ptr, and the next chunk is still bounded by the old distance, so it reads past data_end. This happens once a short period has moved data_ptr away from the ring start and the sink buffer is not a multiple of the ring size, for example when the host sets obs different from ibs in the module init payload. Both HiFi3 variants have the same code. aria_algo_init() also rounded the ring up to an even number of samples and started it one sample in. With an odd channel count and an odd number of frames per chunk the ring then does not hold whole frames, so the frame loop reads up to channels - 1 samples past the end and the output channels rotate by one sample every period. Take the wrap distance from the read pointer, and size the ring to exactly chan_cnt * smpl_group_cnt samples from the start of the allocation. The HiFi5 variant uses circular addressing and only needed the ring size. Configurations with matching ibs and obs and an even number of samples per chunk produce the same output as before. The ring is an odd number of samples only for an odd channel count, and the odd channel HiFi3 and HiFi5 paths access it with 32-bit scalar loads and stores. The even channel paths load two samples at a time, and there the ring stays a multiple of 8 bytes with 8-byte aligned pointers, since the allocation is cache line aligned and the pointers advance by whole frames. The allocation size is unchanged. Add an aria ztest that runs the module through the module adapter for both cases and checks the delayed output frame by frame. Without the fix ASan reports a heap-buffer-overflow in aria_algo_get_data(). Signed-off-by: Shrushti P K <shrusthi@labs.digiscrypt.com>
004a5c7 to
b59aa97
Compare
|
Added the sign-off. The ZTest failure is sof.unit.audio.buffer not finding sof/kernel/drivers/interrupt-map.h after the drivers header move; it fails the same way on the other PRs today and the aria test itself passed in that run. |
aria_algo_get_data() can read past aria's internal ring, which holds the last smpl_group_cnt frames (set from ibs in the IPC4 init payload):
The wrap distance now comes from the read pointer, and the ring is exactly chan_cnt * smpl_group_cnt samples from the start of the allocation. HiFi5 uses circular addressing, so only the ring size applies there. Configurations with matching ibs/obs and an even sample count per chunk give the same output as before.
The new aria ztest runs the module through the module adapter and fails without the fix (heap-buffer-overflow READ in aria_algo_get_data(), 0 bytes past the 384 and 568 byte rings). host-testbench.sh, including the aria test, and test-all-defconfigs.sh pass. I could not build the HiFi3 file locally; it gets the same one-line change as the generic path.