Skip to content
Open
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
10 changes: 8 additions & 2 deletions src/ipc/ipc4/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -1302,12 +1302,18 @@ int ipc4_find_dma_config(struct ipc_config_dai *dai, uint8_t *data_buffer, uint3
int ipc4_find_dma_config_multiple(struct ipc_config_dai *dai, uint8_t *data_buffer,
uint32_t size, uint32_t device_id, int dma_cfg_idx)
{
uint32_t end_addr = (uint32_t)data_buffer + size;
uintptr_t end_addr = (uintptr_t)data_buffer + size;

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.

I do not really follow what Copilot is trying to suggest here. If the end_addr wraps, then the loop bellow will end immediately and no harm is done. The code of course does not work and function would return an error, but that is correct behaviour since the arguments are invalid.

struct ipc_dma_config *dma_cfg;
struct sof_tlv *tlvs;

for (tlvs = (struct sof_tlv *)data_buffer; tlvs && (uint32_t)tlvs < end_addr;
for (tlvs = (struct sof_tlv *)data_buffer; tlvs && (uintptr_t)tlvs < end_addr;
tlvs = tlv_next(tlvs)) {
/* Reject a host TLV that overruns the buffer or wraps tlv_next(). */
uintptr_t remaining = end_addr - (uintptr_t)tlvs;

if (remaining < sizeof(*tlvs) || tlvs->length > remaining - sizeof(*tlvs))
return IPC4_INVALID_REQUEST;

dma_cfg = tlv_value_ptr_get(tlvs, GTW_DMA_CONFIG_ID);
if (!dma_cfg)
continue;
Expand Down
Loading