Commit 331b378
ipc4: helper: bound TLV length safely when parsing DMA configs
The IPC4 fuzzer hit an out-of-bounds read in
ipc4_find_all_dma_configs_tlvs_only() while parsing a copier gateway
config blob as a TLV sequence. AddressSanitizer reports a SEGV on a wild
address ~16 MB below the config buffer.
Root cause: the per-TLV bounds check and the iterator both do pointer
arithmetic on the host-controlled tlvs->length without guarding against
overflow. On 32-bit targets (native_sim and the Xtensa DSPs) a large
length wraps the pointer:
if ((uintptr_t)tlvs->value + tlvs->length > end_addr) /* wraps */
return IPC4_INVALID_REQUEST;
...
tlvs = tlv_next(tlvs); /* tlvs + 8 + length, also wraps */
With length = 0xff000000 and a 32-byte buffer, tlvs->value + length
wraps to a value below end_addr, so the check passes; tlv_next() wraps to
the same address, which is still below end_addr, so the loop continues and
dereferences that wild pointer. config_length is already bounded to the
init payload (so the buffer itself is small and valid) - this is a
separate overflow inside the TLV walk, on the length field embedded in the
blob.
Compare tlvs->length against the remaining space using subtraction, which
cannot overflow because the (tightened) loop condition guarantees the TLV
header - and therefore tlvs->value - is within the buffer. tlv_next() is
thus bounded by end_addr as well. The loop condition now also requires the
full 8-byte header to fit before it is dereferenced.
Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>1 parent 9f9ea30 commit 331b378
1 file changed
Lines changed: 12 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1482 | 1482 | | |
1483 | 1483 | | |
1484 | 1484 | | |
1485 | | - | |
| 1485 | + | |
| 1486 | + | |
1486 | 1487 | | |
1487 | | - | |
1488 | | - | |
| 1488 | + | |
| 1489 | + | |
| 1490 | + | |
| 1491 | + | |
| 1492 | + | |
| 1493 | + | |
| 1494 | + | |
| 1495 | + | |
| 1496 | + | |
| 1497 | + | |
1489 | 1498 | | |
1490 | 1499 | | |
1491 | 1500 | | |
| |||
0 commit comments