Skip to content

audio: aria: fix over-read of the internal ring buffer - #11499

Open
Shrusti-pk wants to merge 1 commit into
thesofproject:mainfrom
Shrusti-pk:aria-ring-wrap
Open

Shrusti-pk wants to merge 1 commit into
thesofproject:mainfrom
Shrusti-pk:aria-ring-wrap

Conversation

@Shrusti-pk

Copy link
Copy Markdown
Contributor

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):

  • each chunk is bounded by the distance from cd->data_ptr to the ring end instead of from the read pointer, so when the sink buffer wraps first, the next chunk still uses the old distance and runs past data_end. It needs a short period to move data_ptr off the ring start and a sink buffer that is not a multiple of the ring, for example obs set different from ibs. Both HiFi3 variants have the same line.
  • aria_algo_init() rounded the ring up to an even sample count and started it one sample in, so with 3, 5 or 7 channels and an odd number of frames per ms a frame straddles the ring end: up to channels - 1 extra samples are read and the output channels rotate by one sample each period
  • the over-read samples are scaled and written to the sink. With the functions copied verbatim under ASan, the worst case I found was 736 bytes past a 1536 byte ring (8 channels, obs of 13 frames, short first period)

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.

@sofci

sofci commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

reply test this please to run this test once

@lgirdwood

Copy link
Copy Markdown
Member

test this please

@lgirdwood lgirdwood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also missing a SoB - pls add this to your Agents workflow.

Comment thread src/audio/aria/aria.c
/* 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Pls check as the buffers need to work on SIMD vector size alignment not just frame alignments/sizes

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.

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>
@Shrusti-pk

Copy link
Copy Markdown
Contributor Author

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.

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.

3 participants