Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/include/ipc4/base_fw_vendor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions src/ipc/ipc4/handler-user.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
19 changes: 19 additions & 0 deletions src/kernel/audio/base_fw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Comment on lines +318 to +319

tlv_value_set(tuple, IPC4_FW_VERSION_FW_CFG, sizeof(version), version);

tuple = tlv_next(tuple);
Expand Down
Loading