Skip to content

Commit 780dd18

Browse files
committed
Validate stack alignment
1 parent 69f6793 commit 780dd18

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

kernel/task.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,12 @@ static bool init_task_stack(tcb_t *tcb, size_t stack_size)
338338
if (!stack)
339339
return false;
340340

341+
/* Validate stack alignment */
342+
if ((uintptr_t) stack & 0x3) {
343+
free(stack);
344+
return false;
345+
}
346+
341347
/* Only initialize essential parts to reduce overhead */
342348
*(uint32_t *) stack = STACK_CANARY;
343349
*(uint32_t *) ((uintptr_t) stack + stack_size - sizeof(uint32_t)) =

0 commit comments

Comments
 (0)