Skip to content

Commit ddedd0a

Browse files
committed
ipc: ipc4: harden ipc_comp_disconnect() against invalid sink
Check the provided sink actually is connected to the buffer, before proceeding to free the buffer. This protects against an invalid IPC sent by the host. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
1 parent 3f7738d commit ddedd0a

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/ipc/ipc4/helper.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,27 @@ __cold int ipc_comp_disconnect(struct ipc *ipc, ipc_pipe_comp_connect *_connect)
920920
if (!buffer)
921921
return IPC4_INVALID_RESOURCE_ID;
922922

923+
/*
924+
* The buffer was located on the source's consumer list, but the sink was
925+
* resolved solely from the host-supplied dst_module_id/dst_instance_id.
926+
* Make sure the buffer is actually connected to that sink, otherwise an
927+
* incorrect dst would leave the real sink bound to a buffer we are about
928+
* to free, while unbinding an unrelated component instead.
929+
*/
930+
bool sink_connected = false;
931+
932+
comp_dev_for_each_producer(sink, buf) {
933+
if (buf == buffer) {
934+
sink_connected = true;
935+
break;
936+
}
937+
}
938+
939+
if (!sink_connected) {
940+
tr_err(&ipc_tr, "buffer %#x is not connected to sink %x", buffer_id, sink_id);
941+
return IPC4_INVALID_RESOURCE_ID;
942+
}
943+
923944
/*
924945
* Disconnect and unbind buffer from source/sink components and continue to free the buffer
925946
* even in case of errors. Block LL processing during disconnect and unbinding to prevent

0 commit comments

Comments
 (0)