ipc3: minor fixes for ipc validation#10883
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens IPC3 handling of host-supplied fields to prevent integer wrap/underflow and to ensure DMA/page-table parsing stays within fixed DSP-side buffers.
Changes:
- Add validation for
ring->pages(reject 0 and values that cannot fit in the fixedPLATFORM_PAGE_TABLE_SIZEcompressed page table) before any size arithmetic/DMA. - Replace an overflow-prone size-sum check with an overflow-safe comparison when validating host-supplied
proc->comp.hdr.sizeandproc->size.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/ipc/ipc3/host-page-table.c | Validates host page count early to avoid underflow in size checks and out-of-bounds DMA/page-table parsing. |
| src/ipc/ipc3/helper.c | Prevents uint32 wraparound when validating host-provided process component sizes against SOF_IPC_MSG_MAX_SIZE. |
kv2019i
left a comment
There was a problem hiding this comment.
Code change is good, but please fix the commit message formatting.
I second the above and would also add the need to fix the failing checks in CI: FAILED: [code=1] modules/sof/CMakeFiles/modules_sof.dir/home/runner/work/sof/sof/workspace/sof/src/ipc/ipc3/host-page-table.c.obj
/usr/bin/clang -DCC_OPTIMIZE_FLAGS=\"\" -DKERNEL -DK_HEAP_MEM_POOL_SIZE=2048 -DXCC_TOOLS_VERSION=\"host\" -D_POSIX_THREAD_SAFE_FUNCTIONS=200809L -D__ZEPHYR__=1 -DRELATIVE_FILE=\"../sof/src/ipc/ipc3/host-page-table.c\" -I/home/runner/work/sof/sof/workspace/build-fuzz/zephyr/include/generated/zephyr -I/home/runner/work/sof/sof/workspace/zephyr/include -I/home/runner/work/sof/sof/workspace/build-fuzz/zephyr/include/generated -I/home/runner/work/sof/sof/workspace/zephyr/soc/native/inf_clock -I/home/runner/work/sof/sof/workspace/zephyr/boards/native/native_sim -I/home/runner/work/sof/sof/workspace/zephyr/scripts/native_simulator/common/src/include -I/home/runner/work/sof/sof/workspace/zephyr/scripts/native_simulator/native/src/include -I/home/runner/work/sof/sof/workspace/zephyr/subsys/portability/posix/c_lib_ext/getopt -I/home/runner/work/sof/sof/workspace/zephyr/drivers -I/home/runner/work/sof/sof/workspace/sof/zephyr/include -I/home/runner/work/sof/sof/workspace/zephyr/kernel/include -I/home/runner/work/sof/sof/workspace/zephyr/arch/host/include -I/home/runner/work/sof/sof/workspace/sof/src/include/sof/audio/module_adapter/iadk -I/home/runner/work/sof/sof/workspace/sof/src/include/sof/audio/module_adapter/library -I/home/runner/work/sof/sof/workspace/sof/src/audio/smart_amp/CONFIG_MAXIM_DSM -I/home/runner/work/sof/sof/workspace/sof/src/audio/smart_amp/include/dsm_api/inc -I/home/runner/work/sof/sof/workspace/sof/src/platform/posix/include -I/home/runner/work/sof/sof/workspace/sof/tools/rimage/src/include -I/home/runner/work/sof/sof/workspace/sof/src/include -I/home/runner/work/sof/sof/workspace/sof/src/arch/host/include -I/home/runner/work/sof/sof/workspace/sof/third_party/include -isystem /home/runner/work/sof/sof/workspace/zephyr/lib/libc/minimal/include -isystem /home/runner/work/sof/sof/workspace/zephyr/lib/libc/common/include -fno-strict-aliasing -O2 -imacros /home/runner/work/sof/sof/workspace/build-fuzz/zephyr/include/generated/zephyr/autoconf.h -ffreestanding -fno-common -g -gdwarf-4 -fcolor-diagnostics --config=/home/runner/work/sof/sof/workspace/zephyr/cmake/toolchain/host/llvm/clang_libgcc.cfg -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-unused-but-set-variable -Wno-typedef-redefinition -Wno-deprecated-non-prototype -Wdouble-promotion -Wno-pointer-sign -Wpointer-arith -Wno-self-assign -Wno-initializer-overrides -Wno-section -Wno-gnu -Werror=implicit-int -fno-pic -fno-pie -Werror -fno-asynchronous-unwind-tables -fstrict-overflow -Wno-vla -fmacro-prefix-map=/home/runner/work/sof/sof/workspace/sof/app=CMAKE_SOURCE_DIR -fmacro-prefix-map=/home/runner/work/sof/sof/workspace/zephyr=ZEPHYR_BASE -fmacro-prefix-map=/home/runner/work/sof/sof/workspace=WEST_TOPDIR -ffunction-sections -fdata-sections -m32 -msse2 -mfpmath=sse -fvisibility=hidden -nostdinc -isystem /usr/lib/llvm-18/lib/clang/18/include -include /home/runner/work/sof/sof/workspace/zephyr/arch/posix/include/undef_system_defines.h -fno-builtin -fsanitize-recover=all -fPIC -fsanitize=address,fuzzer -std=c17 -fno-inline-functions -std=gnu99 -MD -MT modules/sof/CMakeFiles/modules_sof.dir/home/runner/work/sof/sof/workspace/sof/src/ipc/ipc3/host-page-table.c.obj -MF modules/sof/CMakeFiles/modules_sof.dir/home/runner/work/sof/sof/workspace/sof/src/ipc/ipc3/host-page-table.c.obj.d -o modules/sof/CMakeFiles/modules_sof.dir/home/runner/work/sof/sof/workspace/sof/src/ipc/ipc3/host-page-table.c.obj -c /home/runner/work/sof/sof/workspace/sof/src/ipc/ipc3/host-page-table.c
/home/runner/work/sof/sof/workspace/sof/src/ipc/ipc3/host-page-table.c:230:20: error: use of undeclared identifier 'PLATFORM_PAGE_TABLE_SIZE'
230 | ring->pages > PLATFORM_PAGE_TABLE_SIZE * 8 / 20) {
| ^
1 error generated. |
| * below in ipc_parse_page_descriptors(). | ||
| */ | ||
| if (ring->pages == 0 || | ||
| ring->pages > PLATFORM_PAGE_TABLE_SIZE * 8 / 20) { |
There was a problem hiding this comment.
8/20 magic is the only way to calculate this?
There was a problem hiding this comment.
Good point — I've named them so it's self-documenting now. The compressed page table stores one 20-bit entry per host page, so the number of pages whose entries fit in the buffer is (buffer_bytes * 8) / 20 (the * 8 converts the buffer size from bytes to bits). It now reads:
#define HOST_PAGE_TABLE_BITS_PER_PAGE 20
#define HOST_PAGE_TABLE_MAX_PAGES \
(PLATFORM_PAGE_TABLE_SIZE * 8 / HOST_PAGE_TABLE_BITS_PER_PAGE)The 20-bit packing is the existing on-the-wire page-table format — see ipc_parse_page_descriptors(), which unpacks 20 bits per page — so the arithmetic follows from that rather than being arbitrary.
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>
The bounds check added two host-supplied 32-bit sizes, which could wrap and let an oversized value pass. Compare without adding by subtracting from the maximum instead. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
|
Thanks — both addressed and force-pushed:
|
Seen the fuzzing failure in another unrelated PR. Checking. |
Small fixes for data passed in by host.