Skip to content

audio: copier: bound ipcgtw SET_DATA read to the message window - #11400

Open
Shrusti-pk wants to merge 1 commit into
thesofproject:mainfrom
Shrusti-pk:copier-ipcgtw-setdata-bound
Open

Shrusti-pk wants to merge 1 commit into
thesofproject:mainfrom
Shrusti-pk:copier-ipcgtw-setdata-bound

Conversation

@Shrusti-pk

Copy link
Copy Markdown
Contributor

Out-of-bounds read in the IPC4 gateway SET_DATA path

copier_ipcgtw_process() sets data_size = MIN(cmd->extension.r.data_size, sink_get_free_size(sink)) and then reads that many bytes from the inbox window (in->payload, at MAILBOX_HOSTBOX_BASE + 4) into the gateway sink. Both inputs are host controlled: extension.r.data_size is a 30-bit field in the gateway command, and the sink free size comes from the gateway buffer whose size is taken from blob->buffer_size in the gateway config and applied with buffer_set_size(), so it can be much larger than the fixed inbox window. A SET_DATA with a large count then reads (and dcache-invalidates) past the MAILBOX_HOSTBOX region and copies adjacent memory into the audio stream. The IPC4_IPCGWCMD_GET_DATA case right above already caps at SOF_IPC_MSG_MAX_SIZE - 4; SET_DATA now does the same before the sink free-size MIN.

Reproduced under ASan with the SET_DATA bound logic: a 0x1000 inbox window and host data_size 0x10000 gives a heap-buffer-overflow READ of 65536 bytes 0 bytes past the 4096-byte region; with the cap the read is bounded to 4092 bytes and completes cleanly.

copier_ipcgtw_process() handles the IPC4 IPCGATEWAY_CMD. The SET_DATA
case sets data_size to MIN(cmd->extension.r.data_size,
sink_get_free_size(sink)) and then reads that many bytes from
in->payload (MAILBOX_HOSTBOX_BASE + 4) into the gateway sink with
sink_copy_bytes_from_linear(), after a dcache invalidate over the same
span.

Both inputs are host controlled. extension.r.data_size is a 30-bit
field in the gateway command, and the sink free size derives from the
gateway buffer whose size comes from blob->buffer_size in the gateway
config and is applied with buffer_set_size(), so it can be much larger
than the fixed inbox window. When both exceed the window the copy reads
past the MAILBOX_HOSTBOX region and feeds adjacent memory into the audio
stream.

The sibling IPC4_IPCGWCMD_GET_DATA case in the same function already
caps data_size at SOF_IPC_MSG_MAX_SIZE - 4. Apply the same cap before
the sink free-size MIN in the SET_DATA case.

Signed-off-by: Shrushti P K <shrusthi@labs.digiscrypt.com>
@sofci

sofci commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

reply test this please to run this test once

@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.

Thanks @Shrusti-pk !

@kv2019i

kv2019i commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

test this please

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.

4 participants