Skip to content

audio: module_adapter: cap connected buffers at MODULE_MAX_CONNECTIONS - #11417

Open
Shrusti-pk wants to merge 1 commit into
thesofproject:mainfrom
Shrusti-pk:module-adapter-max-connections
Open

Shrusti-pk wants to merge 1 commit into
thesofproject:mainfrom
Shrusti-pk:module-adapter-max-connections

Conversation

@Shrusti-pk

Copy link
Copy Markdown
Contributor

module_adapter keeps one sinks[]/sources[] slot per connected buffer, but nothing stops a module from having more buffers than CONFIG_MODULE_MAX_CONNECTIONS (8):

  • IPC4: ipc4_comp_connect() connects a new buffer for every MOD_BIND and module_adapter_update_sinks_sources() then stores all of them. The ninth bind on one side writes sinks[8] over sources[0], later ones run off the end of struct processing_module. IPC3 module_adapter_sink_src_prepare() does the same at prepare. The count checks in module_adapter_prepare() only covered the audio_stream path removed in a42e9b7.
  • Repro: IPC4 CONFIG_LIBRARY libsof built with ASan and driven through ipc_cmd() the way sof-testbench4 does it. Create 16 gain instances and bind gain.1..15 into gain.0: the 14th MOD_BIND gives a heap-buffer-overflow WRITE of size 8 in module_adapter_update_sinks_sources() (module_adapter_bind() <- ipc4_comp_connect() <- ipc4_bind_module_instance()), 0 bytes after the 448-byte processing_module. The IPC3 prepare overflows the same way in the cmocka build with 14 sources.
  • A bind refused on the sink side runs the e_sink_bind path, which unbound the source while the buffer was still connected, so the source's sinks[] kept the buffer freed right after (ASan heap-use-after-free on the next use with only the bind check applied). mixout_bind() refusing a ninth mixin already takes that path. It now disconnects first, as ipc4_comp_disconnect() does.

With the patch the ninth bind is refused with IPC4_INVALID_RESOURCE_STATE on either side and the refused source is left with no stale sink. Binds up to 8 per side are unchanged, the IPC4 library build (-Wall -Werror) is clean and the cmocka unit tests pass.

struct processing_module holds CONFIG_MODULE_MAX_CONNECTIONS entries in
sinks[] and sources[], but the module adapter stores one entry per
connected buffer without bounding the index. On IPC4,
module_adapter_update_sinks_sources() runs from module_adapter_bind(),
and ipc4_comp_connect() connects a new buffer for every MOD_BIND, so a
ninth bind on one side of a module writes sinks[8] over sources[0] and
further binds run past the processing_module allocation. On IPC3,
module_adapter_sink_src_prepare() does the same at prepare time.

The connection count checks in module_adapter_prepare() only covered
the audio_stream path removed in a42e9b7, and the max_sources and
max_sinks fields are no longer read.

Refuse a bind in module_adapter_bind() that brings the buffers
connected on that side above CONFIG_MODULE_MAX_CONNECTIONS, and fail
module_adapter_sink_src_prepare() with -EINVAL instead of writing past
the arrays.

A refusal on the sink side goes through the e_sink_bind path of
ipc4_comp_connect(), which unbinds the source while the buffer is
still connected. The source then refreshes its sinks[] with the buffer
that is freed right after. Disconnect first, as ipc4_comp_disconnect()
does.
@sofci

sofci commented Nov 7, 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