Skip to content

Commit 9b78475

Browse files
committed
ipc4: helper: bound host TLV length in DMA config walk
Reject a gateway-config TLV whose length overruns the buffer so the uintptr_t walk cannot wrap past the low address space. Signed-off-by: Adrian Bonislawski <adrian.bonislawski@intel.com>
1 parent 3f7738d commit 9b78475

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/ipc/ipc4/helper.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,12 +1302,18 @@ int ipc4_find_dma_config(struct ipc_config_dai *dai, uint8_t *data_buffer, uint3
13021302
int ipc4_find_dma_config_multiple(struct ipc_config_dai *dai, uint8_t *data_buffer,
13031303
uint32_t size, uint32_t device_id, int dma_cfg_idx)
13041304
{
1305-
uint32_t end_addr = (uint32_t)data_buffer + size;
1305+
uintptr_t end_addr = (uintptr_t)data_buffer + size;
13061306
struct ipc_dma_config *dma_cfg;
13071307
struct sof_tlv *tlvs;
13081308

1309-
for (tlvs = (struct sof_tlv *)data_buffer; tlvs && (uint32_t)tlvs < end_addr;
1309+
for (tlvs = (struct sof_tlv *)data_buffer; tlvs && (uintptr_t)tlvs < end_addr;
13101310
tlvs = tlv_next(tlvs)) {
1311+
/* Reject a host TLV that overruns the buffer or wraps tlv_next(). */
1312+
uintptr_t remaining = end_addr - (uintptr_t)tlvs;
1313+
1314+
if (remaining < sizeof(*tlvs) || tlvs->length > remaining - sizeof(*tlvs))
1315+
return IPC4_INVALID_REQUEST;
1316+
13111317
dma_cfg = tlv_value_ptr_get(tlvs, GTW_DMA_CONFIG_ID);
13121318
if (!dma_cfg)
13131319
continue;

0 commit comments

Comments
 (0)