Skip to content

Commit 3ed1b24

Browse files
committed
fuzz: posix: mirror IPC4 payload into MAILBOX_HOSTBOX
On real hardware (and in the IPC3 harness path) the host kernel deposits the IPC payload into the hostbox shared-memory region before the DSP firmware is signalled. Many IPC4 handlers consume their payload by reading from MAILBOX_HOSTBOX_BASE directly -- for example LARGE_CONFIG_SET / LARGE_CONFIG_GET, vendor config, SET_DX and SET_PIPELINE_STATE in sof/src/ipc/ipc4/handler-user.c and ipc/ipc4/handler-kernel.c. Until now the posix fuzz harness only populated the IPC3 hostbox; in IPC4 builds the region stayed zero-filled, so those handlers either rejected the message early or operated on uninitialised data instead of on the fuzzer-controlled bytes. Lift the existing mailbox mirror copy out of the IPC3-only branch so it runs for both major versions. posix_hostbox is sized to SOF_IPC_MSG_MAX_SIZE (see Commit "fuzz: posix: size MAILBOX_HOSTBOX from SOF_IPC_MSG_MAX_SIZE"), so the copy length is correct for both targets. Update the function comment to record the new contract. This immediately exposes additional reachable code in the IPC4 build (payload decoders that previously saw only zeros) without affecting IPC3 behaviour. Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
1 parent de4aa32 commit 3ed1b24

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

src/platform/posix/ipc.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,38 @@ static void fuzz_isr(const void *arg)
146146
// ipc_platform_compact_read_msg(), writing 8 bytes unconditionally on
147147
// the header object it receives, which is then returned here, and
148148
// then passed to ipc_cmd().
149+
//
150+
// The harness also mirrors the framed message into MAILBOX_HOSTBOX so
151+
// that handlers reading payload directly from the hostbox region
152+
// (large_config_set/get, set_dx, set_pipeline_state, vendor_config and
153+
// friends in ipc4/handler-user.c and ipc4/handler-kernel.c) observe
154+
// the fuzz bytes rather than stale or zero-filled memory.
155+
//
156+
// The two IPC majors split header and payload differently:
157+
//
158+
// * IPC3 carries the header in-band at the start of the message, and
159+
// mailbox_validate() walks the full message starting from offset 0
160+
// of the hostbox. The full message is mirrored as-is.
161+
//
162+
// * IPC4 splits the 8-byte compact header (consumed via
163+
// ipc_compact_read_msg()) from the payload, which on real hardware
164+
// lives in HOSTBOX. The harness therefore mirrors only the
165+
// post-header bytes, so the first dword of MAILBOX_HOSTBOX matches
166+
// the first dword of the IPC4 payload (e.g. pipelines_count for
167+
// SET_PIPELINE_STATE) instead of header bits.
168+
//
169+
// posix_hostbox is sized to SOF_IPC_MSG_MAX_SIZE (see
170+
// platform/lib/memory.h), so the copy is always in bounds for both
171+
// IPC3 and IPC4 message envelopes.
149172
enum task_state ipc_platform_do_cmd(struct ipc *ipc)
150173
{
151174
struct ipc_cmd_hdr *hdr;
152175

153176
#ifdef CONFIG_IPC_MAJOR_4
177+
memset(posix_hostbox, 0, SOF_IPC_MSG_MAX_SIZE);
178+
memcpy(posix_hostbox,
179+
(const uint8_t *)global_ipc->comp_data + sizeof(struct ipc_cmd_hdr),
180+
SOF_IPC_MSG_MAX_SIZE - sizeof(struct ipc_cmd_hdr));
154181
hdr = ipc_compact_read_msg();
155182
#else
156183
memcpy(posix_hostbox, global_ipc->comp_data, SOF_IPC_MSG_MAX_SIZE);

0 commit comments

Comments
 (0)