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.

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 thread src/kernel/audio/base_fw.c Resolved
@intel-sofci

intel-sofci commented Dec 3, 2026 •

Copy link
Copy Markdown

PR 11609: test results

Run date: 2026-12-04 15:11 UTC

Tested commit: 6a907c14ab09aea07105c8c1554f874467329f1c

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

@lgirdwood

Copy link
Copy Markdown
Member

@tmleman are you able to resolve copilot comments. Thanks !

@tmleman
tmleman force-pushed the topic/upstream/pr/ipc4/base_fw/fix/config_set branch from b0bcf39 to 6a907c1 Compare December 4, 2026 14:39
@tmleman
tmleman requested a balanced review from Copilot December 4, 2026 14:43

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 IPC capacity check still allows HW_CONFIG to overflow comp_data after preceding SYSTEM_TIME entries because the getter does not enforce remaining buffer capacity before writing; checking its returned length afterward is too late. Separately, with CONFIG_SOF_ZEPHYR_NO_SOF_CLOCK enabled, the base firmware capacity check overestimates the serialized reply by 24 bytes and rejects a host max_length that exactly fits the complete reply.

2 open issues
1 resolved since last review

Review effort: Balanced

Comment on lines +792 to +794
if (produced_data + sizeof(*output_tlv) > MAILBOX_DSPBOX_SIZE ||
input_tl[i].max_length >
MAILBOX_DSPBOX_SIZE - produced_data - sizeof(*output_tlv)) {
sizeof(struct sof_tlv) + sizeof(uint32_t))

/* Upper bound of the uint32_t value tuples basefw_config() writes. */
#define BASEFW_CONFIG_U32_TUPLES_MAX 17
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_FIXED_SIZE_MAX, the worst-case size of the fixed
tuples including the vendor tuples (new BASEFW_VENDOR_FW_CONFIG_SIZE_MAX).
Build the nested IPC4_FW_SOF_INFO tuple once up front, so that its actual
size, not the all-codec-slots worst case, is added to the bound, and the
checked size is the size that gets written. 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.

Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
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.

4 participants