Skip to content

Commit d0035f9

Browse files
Andrew Boieandrewboie
authored andcommitted
kernel: fix stack size check in k_thread_create
The pointer arithmetic used didn't account for ARC supervisor mode stacks, which are allocated at the end of the stack object. Use the new macro to know exactly how much space is reserved. Signed-off-by: Andrew Boie <[email protected]>
1 parent 575abc0 commit d0035f9

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

kernel/thread.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,7 @@ Z_SYSCALL_HANDLER(k_thread_create,
451451
int prio;
452452
u32_t options, delay;
453453
u32_t total_size;
454-
#ifndef CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT
455-
u32_t guard_size;
456-
#endif
454+
457455
struct _k_object *stack_object;
458456
struct k_thread *new_thread = (struct k_thread *)new_thread_p;
459457
volatile struct _syscall_10_args *margs =
@@ -468,23 +466,15 @@ Z_SYSCALL_HANDLER(k_thread_create,
468466
_OBJ_INIT_FALSE) == 0,
469467
"bad stack object"));
470468

471-
#ifndef CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT
472469
/* Verify that the stack size passed in is OK by computing the total
473470
* size and comparing it with the size value in the object metadata
474-
*
475-
* We skip this check for SoCs which utilize MPUs with power of two
476-
* alignment requirements as the guard is allocated out of the stack
477-
* size and not allocated in addition to the stack size
478471
*/
479-
guard_size = (u32_t)K_THREAD_STACK_BUFFER(stack) - (u32_t)stack;
480-
Z_OOPS(Z_SYSCALL_VERIFY_MSG(!__builtin_uadd_overflow(guard_size,
472+
Z_OOPS(Z_SYSCALL_VERIFY_MSG(!__builtin_uadd_overflow(K_THREAD_STACK_RESERVED,
481473
stack_size,
482474
&total_size),
483475
"stack size overflow (%u+%u)", stack_size,
484-
guard_size));
485-
#else
486-
total_size = stack_size;
487-
#endif
476+
K_THREAD_STACK_RESERVED));
477+
488478
/* They really ought to be equal, make this more strict? */
489479
Z_OOPS(Z_SYSCALL_VERIFY_MSG(total_size <= stack_object->data,
490480
"stack size %u is too big, max is %u",

0 commit comments

Comments
 (0)