Skip to content

Commit 4de6627

Browse files
cujomalaineylgirdwood
authored andcommitted
ipc: check type before freeing
When freeing we currently implicitly are trusting the ID to match the type specified in the message. From a security standpoint this is wrong, never trust the other side. This is the likely cause of how the fuzzer is leaking memory in pipelines since they have additional allocations that are not freed when they are treated as a buffer or a component. Signed-off-by: Curtis Malainey <cujomalainey@chromium.org>
1 parent 853c0a7 commit 4de6627

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/ipc/ipc-helper.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,13 @@ int ipc_comp_free(struct ipc *ipc, uint32_t comp_id)
282282
if (!icd)
283283
return -ENODEV;
284284

285+
/* check type */
286+
if (icd->type != COMP_TYPE_COMPONENT) {
287+
tr_err(&ipc_tr, "ipc_comp_free(): comp id: %d is not a COMPONENT",
288+
comp_id);
289+
return -EINVAL;
290+
}
291+
285292
/* check core */
286293
if (!cpu_is_me(icd->core))
287294
return ipc_process_on_core(icd->core, false);

src/ipc/ipc3/helper.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,13 @@ int ipc_pipeline_free(struct ipc *ipc, uint32_t comp_id)
386386
if (!ipc_pipe)
387387
return -ENODEV;
388388

389+
/* check type */
390+
if (ipc_pipe->type != COMP_TYPE_PIPELINE) {
391+
tr_err(&ipc_tr, "ipc_pipeline_free(): comp id: %d is not a PIPELINE",
392+
comp_id);
393+
return -EINVAL;
394+
}
395+
389396
/* check core */
390397
if (!cpu_is_me(ipc_pipe->core))
391398
return ipc_process_on_core(ipc_pipe->core, false);
@@ -455,6 +462,13 @@ int ipc_buffer_free(struct ipc *ipc, uint32_t buffer_id)
455462
if (!ibd)
456463
return -ENODEV;
457464

465+
/* check type */
466+
if (ibd->type != COMP_TYPE_BUFFER) {
467+
tr_err(&ipc_tr, "ipc_buffer_free(): comp id: %d is not a BUFFER",
468+
buffer_id);
469+
return -EINVAL;
470+
}
471+
458472
/* check core */
459473
if (!cpu_is_me(ibd->core))
460474
return ipc_process_on_core(ibd->core, false);

0 commit comments

Comments
 (0)