Skip to content

ipc4: handler-user: avoid wrap in vendor config get bound check - #11609

Open
tmleman wants to merge 2 commits into
thesofproject:mainfrom
tmleman:topic/upstream/pr/ipc4/base_fw/fix/config_set
Open

tmleman wants to merge 2 commits into
thesofproject:mainfrom
tmleman:topic/upstream/pr/ipc4/base_fw/fix/config_set

Conversation

@tmleman

@tmleman tmleman commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

ipc4_get_vendor_config_module_instance() rejects a TL when produced_data + sizeof(struct sof_tlv) + max_length exceeds MAILBOX_DSPBOX_SIZE. max_length comes straight from the host and the sum is a 32-bit size_t on the DSP, so max_length = 0xffffffff wraps the sum to produced_data + 7 and the check always passes. Each getter is then told it has 0xffffffff bytes and the loop keeps appending replies past the end of ipc->comp_data (SOF_IPC_MSG_MAX_SIZE bytes).

Found by the IPC4 fuzzer (ASan): 38 BaseFW TLs of {IPC4_FW_CONFIG, 0xffffffff} write at comp_data + 4096 on the 15th basefw_config() call.

Check that the header fits first, then compare max_length against the space left instead of adding it.

ipc4_get_vendor_config_module_instance() rejects a TL when
produced_data + sizeof(struct sof_tlv) + max_length exceeds
MAILBOX_DSPBOX_SIZE. max_length comes straight from the host and the
sum is a 32-bit size_t on the DSP, so max_length = 0xffffffff wraps the
sum to produced_data + 7 and the check always passes. Each getter is
then told it has 0xffffffff bytes and the loop keeps appending replies
past the end of ipc->comp_data (SOF_IPC_MSG_MAX_SIZE bytes).

Found by the IPC4 fuzzer (ASan): 38 BaseFW TLs of
{IPC4_FW_CONFIG, 0xffffffff} write at comp_data + 4096 on the 15th
basefw_config() call.

Check that the header fits first, then compare max_length against the
space left instead of adding it.

Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
basefw_config() writes the whole IPC4_FW_CONFIG tuple list (about
280 bytes) without looking at *data_offset. Through a
VENDOR_CONFIG_PARAM get, data points after earlier TLV replies inside
ipc->comp_data and *data_offset is the host max_length, narrowed to the
room that is left. A host sending many {IPC4_FW_CONFIG, 0} TLs passes
the vendor loop bound on every TL while each reply is ~288 bytes, so
the 15th reply runs past the end of the 4096 byte comp_data.

Add BASEFW_CONFIG_SIZE_MAX, the worst-case reply size including the
nested IPC4_FW_SOF_INFO tuple and the vendor tuples (new
BASEFW_VENDOR_FW_CONFIG_SIZE_MAX), and refuse with IPC4_OUT_OF_MEMORY
when MIN(*data_offset, SOF_IPC_MSG_MAX_SIZE) is smaller, as done for the
extended perf data reply. The bound is 536 bytes on posix and 572
bytes with the Intel vendor tuples; Linux asks with the full max
payload size, so normal FW_CONFIG queries are unchanged.

Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
Copilot AI balanced review requested due to automatic review settings December 3, 2026 15:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The size check requires worst-case capacity rather than the actual serialized reply size. With the default 64 Intel codec slots and both clock tuples enabled, it requires 572 bytes even though an empty-codec reply needs only 304, so a valid vendor request with a 512-byte buffer fails with IPC4_OUT_OF_MEMORY.

1 open issue
What changed in this PR

Hardens IPC4 vendor configuration replies against integer overflow in host-controlled length checks.

Changes:

  • Replaces length addition with remaining-capacity checks.
  • Adds worst-case FW_CONFIG size validation and vendor-specific size bounds.
File Description
src/​kernel/​audio/​base_fw.c Adds a worst-case reply capacity guard.
src/​ipc/​ipc4/​handler-user.c Makes vendor reply length checks overflow-safe.
src/​include/​ipc4/​base_fw_vendor.h Defines vendor configuration size bounds.

Review effort: Balanced

Comment on lines +318 to +319
if (MIN(*data_offset, SOF_IPC_MSG_MAX_SIZE) < BASEFW_CONFIG_SIZE_MAX)
return IPC4_OUT_OF_MEMORY;
@intel-sofci

Copy link
Copy Markdown

PR 11609: test results

Run date: 2026-12-03 19:04 UTC

Tested commit: b0bcf3939df75326ffd5655327e731268548e43a

mtl pass rate lnl pass rate ptl pass rate wcl pass rate nvl pass rate

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