Skip to content

Commit 98e2fc6

Browse files
kv2019ilgirdwood
authored andcommitted
zephyr: syscall: sof_dma: handle overflow in deep_copy_dma_blk_cfg_list()
deep_copy_dma_blk_cfg_list() is used to verify the syscall arguments. Fix an issue with possible overflow when calculating the alloc size for DMA blocks. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
1 parent 930bd10 commit 98e2fc6

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

zephyr/syscall/sof_dma.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <sof/lib/dma.h>
66
#include <zephyr/kernel.h>
77
#include <zephyr/internal/syscall_handler.h>
8+
#include <zephyr/sys/math_extras.h>
89

910
#ifdef CONFIG_SOF_USERSPACE_INTERFACE_DMA
1011

@@ -111,12 +112,22 @@ static inline struct dma_block_config *deep_copy_dma_blk_cfg_list(struct dma_con
111112
{
112113
struct dma_block_config *kern_cfg;
113114
struct dma_block_config *kern_prev = NULL, *kern_next, *user_next;
115+
size_t alloc_size;
114116
int i = 0;
115117

116118
if (!cfg->block_count)
117119
return NULL;
118120

119-
kern_cfg = rmalloc(0, sizeof(*kern_cfg) * cfg->block_count);
121+
/*
122+
* block_count is user-controlled, so compute the allocation size
123+
* with an overflow check. Without it, a large block_count would
124+
* wrap the product on 32-bit size_t, yield an undersized buffer,
125+
* and let the copy loop below overflow the kernel heap.
126+
*/
127+
if (size_mul_overflow(sizeof(*kern_cfg), cfg->block_count, &alloc_size))
128+
return NULL;
129+
130+
kern_cfg = rmalloc(0, alloc_size);
120131
if (!kern_cfg)
121132
return NULL;
122133

0 commit comments

Comments
 (0)