Skip to content

Commit 89adb95

Browse files
committed
ipc3: bound host page count before page table DMA and parsing
The host-supplied ring->pages drives both the page table DMA transfer length (20 bits per page) and the DSP-side descriptor allocations, but only ring->size was sanity checked. A large page count could overflow the fixed-size page table buffer and wrap the page-count multiplication. Reject a zero or too-large page count at the single entry point before any use. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent 3f7738d commit 89adb95

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/ipc/ipc3/host-page-table.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,22 @@ int ipc_process_host_buffer(struct ipc *ipc,
216216
struct ipc_data_host_buffer *data_host_buffer;
217217
int err;
218218

219+
/*
220+
* The host-supplied page count is used both to size DSP-side
221+
* allocations and to compute the DMA transfer length for the
222+
* compressed page table (20 bits per page). The destination
223+
* page_table buffer is a fixed PLATFORM_PAGE_TABLE_SIZE allocation,
224+
* so reject any count that would not fit before doing any
225+
* arithmetic that could overflow (ring->pages * 20). pages == 0 is
226+
* also invalid and would underflow the ring->size sanity check
227+
* below in ipc_parse_page_descriptors().
228+
*/
229+
if (ring->pages == 0 ||
230+
ring->pages > PLATFORM_PAGE_TABLE_SIZE * 8 / 20) {
231+
tr_err(&ipc_tr, "ipc: invalid page count %u", ring->pages);
232+
return -EINVAL;
233+
}
234+
219235
data_host_buffer = ipc_platform_get_host_buffer(ipc);
220236
dma_sg_init(elem_array);
221237

0 commit comments

Comments
 (0)