Skip to content

Commit 4f59ee8

Browse files
marc-hbkv2019i
authored andcommitted
ipc-helper.c: reject invalid SOF_MEM_CAPS_* bits
Fixes lack of SOF_MEM_CAPS_* input validation found in #8832 Signed-off-by: Marc Herbert <marc.herbert@intel.com>
1 parent dc8b367 commit 4f59ee8

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/include/ipc/topology.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ struct sof_ipc_comp {
8686
#define SOF_MEM_CAPS_CACHE BIT(6) /**< cacheable */
8787
#define SOF_MEM_CAPS_EXEC BIT(7) /**< executable */
8888
#define SOF_MEM_CAPS_L3 BIT(8) /**< L3 memory */
89+
/* Don't forget to update when adding a new bit to the ABI. */
90+
#define SOF_MEM_CAPS_LOWEST_INVALID BIT(9) /**< Used for input validation */
8991

9092
/*
9193
* overrun will cause ring buffer overwrite, instead of XRUN.

src/ipc/ipc-helper.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@
3636

3737
LOG_MODULE_DECLARE(ipc, CONFIG_SOF_LOG_LEVEL);
3838

39+
static bool valid_ipc_buffer_desc(const struct sof_ipc_buffer *desc)
40+
{
41+
if (desc->caps >= SOF_MEM_CAPS_LOWEST_INVALID)
42+
return false;
43+
44+
/* TODO: check desc->size and maybe other things */
45+
return true;
46+
}
47+
3948
/* create a new component in the pipeline */
4049
struct comp_buffer *buffer_new(const struct sof_ipc_buffer *desc, bool is_shared)
4150
{
@@ -44,6 +53,12 @@ struct comp_buffer *buffer_new(const struct sof_ipc_buffer *desc, bool is_shared
4453
tr_info(&buffer_tr, "buffer new size 0x%x id %d.%d flags 0x%x",
4554
desc->size, desc->comp.pipeline_id, desc->comp.id, desc->flags);
4655

56+
if (!valid_ipc_buffer_desc(desc)) {
57+
tr_err(&buffer_tr, "Invalid buffer desc! New size 0x%x id %d.%d caps 0x%x",
58+
desc->size, desc->comp.pipeline_id, desc->comp.id, desc->caps);
59+
return NULL;
60+
}
61+
4762
/* allocate buffer */
4863
buffer = buffer_alloc(desc->size, desc->caps, desc->flags, PLATFORM_DCACHE_ALIGN,
4964
is_shared);

src/ipc/ipc3/handler.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ LOG_MODULE_DECLARE(ipc, CONFIG_SOF_LOG_LEVEL);
7676
#define iGS(x) ((x) & SOF_GLB_TYPE_MASK)
7777
#define iCS(x) ((x) & SOF_CMD_TYPE_MASK)
7878

79+
/* FIXME: assert() is most likely turned off in production builds
80+
* https://open-std.org/jtc1/sc22/wg14/www/docs/n1967.htm
81+
*/
7982
#define _IPC_COPY_CMD(rx, tx, rx_size) \
8083
do { \
8184
int ___ret; \

0 commit comments

Comments
 (0)