Skip to content

Commit 1dc02fc

Browse files
dcpleungnashif
authored andcommitted
xtensa: initialize privileged stack during thread init
This adds the bits to initialize the privileged stack for each thread during thread initialization. This prevents information leaking if the thread stack is reused, and also aids in calculating stack space usage during system calls. Signed-off-by: Daniel Leung <[email protected]>
1 parent d736af8 commit 1dc02fc

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

arch/xtensa/core/thread.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ static void *init_stack(struct k_thread *thread, int *stack_top,
7272
frame->bsa.ps = PS_WOE | PS_UM | PS_CALLINC(1);
7373
#ifdef CONFIG_USERSPACE
7474
if ((thread->base.user_options & K_USER) == K_USER) {
75+
#ifdef CONFIG_INIT_STACKS
76+
/* setup_thread_stack() does not initialize the architecture specific
77+
* privileged stack. So we need to do it manually here as this function
78+
* is called by arch_new_thread() via z_setup_new_thread() after
79+
* setup_thread_stack() but before thread starts running.
80+
*
81+
* Note that only user threads have privileged stacks and kernel
82+
* only threads do not.
83+
*/
84+
(void)memset(&header->privilege_stack[0], 0xaa, sizeof(header->privilege_stack));
85+
#endif
86+
7587
frame->bsa.pc = (uintptr_t)arch_user_mode_enter;
7688
} else {
7789
frame->bsa.pc = (uintptr_t)z_thread_entry;

0 commit comments

Comments
 (0)