Skip to content

audio: cadence: ipc3: bound codec params copy to its stack buffer - #11325

Open
Shrusti-pk wants to merge 1 commit into
thesofproject:mainfrom
Shrusti-pk:cadence-ipc3-codec-params-bound
Open

Shrusti-pk wants to merge 1 commit into
thesofproject:mainfrom
Shrusti-pk:cadence-ipc3-codec-params-bound

Conversation

@Shrusti-pk

Copy link
Copy Markdown
Contributor

cadence_codec_resolve_api() on IPC3 hands the host-supplied ext_data_length to memcpy_s() as the destination size of a stack struct snd_codec, so the bound check never trips:

  • ext_data_length from SOF_IPC_STREAM_PCM_PARAMS is only capped at SOF_IPC_MSG_MAX_SIZE - sizeof(struct sof_ipc_pcm_params), 276 bytes on IPC3 builds
  • struct snd_codec is 120 bytes, so prepare writes up to 156 host-controlled bytes past it on the stack
  • ASan on a harness with the function body copied verbatim: stack-buffer-overflow WRITE of size 276 in cadence_codec_resolve_api; with the fix it returns -EINVAL and a 120-byte payload still resolves the codec id
    The IPC4 variant reads the codec params from the size-checked init payload and is not affected.

cadence_codec_resolve_api() copies the stream params extended data
into a struct snd_codec on the stack, but passes ext_data_length as
the memcpy_s() destination size, so the bound check can never fail.

ext_data_length comes from SOF_IPC_STREAM_PCM_PARAMS and is only
limited to SOF_IPC_MSG_MAX_SIZE - sizeof(struct sof_ipc_pcm_params),
276 bytes on IPC3 builds, while struct snd_codec is 120 bytes. A
host sending larger extended data overflows the stack by up to 156
bytes when the codec is prepared.

Use sizeof(codec_params) as the destination size so oversized
extended data is rejected with -EINVAL.

Signed-off-by: Shrushti P K <shrusthi@labs.digiscrypt.com>
@sofci

sofci commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

reply test this please to run this test once

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.

2 participants