From 11b85ee510a15e4ae6dbe65e00dd9e048839569e Mon Sep 17 00:00:00 2001 From: Flavio Ceolin Date: Thu, 14 Mar 2024 16:32:07 -0700 Subject: [PATCH] kernel: stack: Check possible overflow Check possible overflow in k_stack data struct. An overflow can happens resulting in a much smaller amount of memory allocation. Signed-off-by: Flavio Ceolin --- kernel/stack.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kernel/stack.c b/kernel/stack.c index 822abfca36..adebb2d68e 100644 --- a/kernel/stack.c +++ b/kernel/stack.c @@ -8,6 +8,7 @@ * @brief fixed-size stack object */ +#include #include #include @@ -64,8 +65,12 @@ int32_t z_impl_k_stack_alloc_init(struct k_stack *stack, uint32_t num_entries) static inline int32_t z_vrfy_k_stack_alloc_init(struct k_stack *stack, uint32_t num_entries) { + size_t total_size; + K_OOPS(K_SYSCALL_OBJ_NEVER_INIT(stack, K_OBJ_STACK)); K_OOPS(K_SYSCALL_VERIFY(num_entries > 0)); + K_OOPS(K_SYSCALL_VERIFY(!size_mul_overflow(num_entries, sizeof(stack_data_t), + &total_size))); return z_impl_k_stack_alloc_init(stack, num_entries); } #include