Skip to content

ipc3: minor fixes for ipc validation#10883

Open
lgirdwood wants to merge 2 commits into
thesofproject:mainfrom
lgirdwood:fix-ipc3
Open

ipc3: minor fixes for ipc validation#10883
lgirdwood wants to merge 2 commits into
thesofproject:mainfrom
lgirdwood:fix-ipc3

Conversation

@lgirdwood

Copy link
Copy Markdown
Member

Small fixes for data passed in by host.

Copilot AI review requested due to automatic review settings June 11, 2026 14:59

Copilot AI left a comment

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.

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 fixed PLATFORM_PAGE_TABLE_SIZE compressed 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.size and proc->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.

@lgirdwood lgirdwood changed the title ipc3: ipc3: minor fixes for ipc validation Jun 11, 2026

@kv2019i kv2019i left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code change is good, but please fix the commit message formatting.

@tmleman

tmleman commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

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.

Comment thread src/ipc/ipc3/host-page-table.c Outdated
* below in ipc_parse_page_descriptors().
*/
if (ring->pages == 0 ||
ring->pages > PLATFORM_PAGE_TABLE_SIZE * 8 / 20) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8/20 magic is the only way to calculate this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

lrgirdwo added 2 commits June 12, 2026 13:52
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>
@lgirdwood

Copy link
Copy Markdown
Member Author

Thanks — both addressed and force-pushed:

  • CI failure (use of undeclared identifier 'PLATFORM_PAGE_TABLE_SIZE' in the fuzz / native_sim build): that macro is only defined by the imx/mediatek platforms. The host/library build allocates the page table as HOST_PAGE_SIZE (see drivers/host/ipc.c) and doesn't define PLATFORM_PAGE_TABLE_SIZE. Added an #ifndef PLATFORM_PAGE_TABLE_SIZE fallback to HOST_PAGE_SIZE, so the bound matches the actual page-table buffer size on every platform.
  • Commit messages reflowed to <=72 columns.

@lgirdwood

Copy link
Copy Markdown
Member Author

Thanks — both addressed and force-pushed:

  • CI failure (use of undeclared identifier 'PLATFORM_PAGE_TABLE_SIZE' in the fuzz / native_sim build): that macro is only defined by the imx/mediatek platforms. The host/library build allocates the page table as HOST_PAGE_SIZE (see drivers/host/ipc.c) and doesn't define PLATFORM_PAGE_TABLE_SIZE. Added an #ifndef PLATFORM_PAGE_TABLE_SIZE fallback to HOST_PAGE_SIZE, so the bound matches the actual page-table buffer size on every platform.
  • Commit messages reflowed to <=72 columns.

Seen the fuzzing failure in another unrelated PR. Checking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants