From 46e6d262127e1b13b841ad0a3101e9ebc21db348 Mon Sep 17 00:00:00 2001 From: Tomasz Leman Date: Thu, 3 Dec 2026 11:09:10 +0000 Subject: [PATCH 1/2] ipc4: handler-user: avoid wrap in vendor config get bound check 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 --- src/ipc/ipc4/handler-user.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ipc/ipc4/handler-user.c b/src/ipc/ipc4/handler-user.c index 5e210bcf246b..21cbee59f9df 100644 --- a/src/ipc/ipc4/handler-user.c +++ b/src/ipc/ipc4/handler-user.c @@ -784,10 +784,14 @@ __cold int ipc4_get_vendor_config_module_instance(struct comp_dev *dev, struct sof_tlv *output_tlv = (struct sof_tlv *)(data_out + produced_data); /* the TLV header is written in front of the value, so it - * must fit in the DSPBOX together with max_length + * must fit in the DSPBOX together with max_length. + * max_length is host-controlled: compare it against the + * space left instead of adding it, as the sum wraps on + * 32-bit targets (e.g. max_length = 0xffffffff). */ - if (produced_data + sizeof(*output_tlv) + input_tl[i].max_length > - MAILBOX_DSPBOX_SIZE) { + if (produced_data + sizeof(*output_tlv) > MAILBOX_DSPBOX_SIZE || + input_tl[i].max_length > + MAILBOX_DSPBOX_SIZE - produced_data - sizeof(*output_tlv)) { tr_err(&ipc_tr, "error: response payload bigger than DSPBOX size"); return IPC4_FAILURE; } From b0bcf3939df75326ffd5655327e731268548e43a Mon Sep 17 00:00:00 2001 From: Tomasz Leman Date: Thu, 3 Dec 2026 11:09:10 +0000 Subject: [PATCH 2/2] ipc4: base_fw: bound FW_CONFIG reply by the caller buffer size 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 --- src/include/ipc4/base_fw_vendor.h | 13 +++++++++++++ src/kernel/audio/base_fw.c | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/include/ipc4/base_fw_vendor.h b/src/include/ipc4/base_fw_vendor.h index 98250eac9c3a..7a75f049e688 100644 --- a/src/include/ipc4/base_fw_vendor.h +++ b/src/include/ipc4/base_fw_vendor.h @@ -26,6 +26,13 @@ struct comp_dev; */ #ifdef CONFIG_IPC4_BASE_FW_INTEL +/** + * \brief Upper bound in bytes of the tuples basefw_vendor_fw_config() adds: + * three uint32_t value tuples, each with a type and a length word. + * \ingroup ipc4_base_fw_api + */ +#define BASEFW_VENDOR_FW_CONFIG_SIZE_MAX (3 * 3 * sizeof(uint32_t)) + /** * \brief Vendor specific routine to add data tuples to FW_CONFIG * structure sent to host via IPC. @@ -116,6 +123,12 @@ int basefw_vendor_dma_control(uint32_t node_id, #else /* !CONFIG_IPC4_BASE_FW_INTEL */ +/** + * \brief Upper bound in bytes of the tuples basefw_vendor_fw_config() adds. + * \ingroup ipc4_base_fw_api + */ +#define BASEFW_VENDOR_FW_CONFIG_SIZE_MAX 0 + static inline int basefw_vendor_fw_config(uint32_t *data_offset, char *data) { *data_offset = 0; diff --git a/src/kernel/audio/base_fw.c b/src/kernel/audio/base_fw.c index e8c170f43290..573029798f6e 100644 --- a/src/kernel/audio/base_fw.c +++ b/src/kernel/audio/base_fw.c @@ -230,6 +230,17 @@ static void get_codec_info(struct sof_tlv **tuple, bool include_empty) #define SOF_CONFIG_SIZE_MAX (SOF_CONFIG_MEMBER_SIZE(sof_ipc4_codec_info_data) + \ 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 + +/* Upper bound of the whole IPC4_FW_CONFIG reply built by basefw_config(). */ +#define BASEFW_CONFIG_SIZE_MAX (sizeof(struct sof_tlv) + 4 * sizeof(uint16_t) + \ + BASEFW_CONFIG_U32_TUPLES_MAX * \ + (sizeof(struct sof_tlv) + sizeof(uint32_t)) + \ + sizeof(struct sof_tlv) + sizeof(struct ipc4_scheduler_config) + \ + sizeof(struct sof_tlv) + SOF_CONFIG_SIZE_MAX + \ + BASEFW_VENDOR_FW_CONFIG_SIZE_MAX) + /* Serialize nested IPC4_FW_SOF_INFO TLVs (codec list + SOF capability mask). */ static uint32_t build_sof_info_tlvs(char *buf, bool include_empty_codec_info) { @@ -299,6 +310,14 @@ __cold static int basefw_config(uint32_t *data_offset, char *data) assert_can_be_cold(); + /* data_offset is in/out: the host max reply length comes in, and the + * vendor config path narrows it to what is left of comp_data after + * earlier TLVs. The tuples below are written without further checks, + * so refuse up front when the worst-case reply does not fit. + */ + if (MIN(*data_offset, SOF_IPC_MSG_MAX_SIZE) < BASEFW_CONFIG_SIZE_MAX) + return IPC4_OUT_OF_MEMORY; + tlv_value_set(tuple, IPC4_FW_VERSION_FW_CFG, sizeof(version), version); tuple = tlv_next(tuple);