Skip to content

Commit bb31335

Browse files
dcpleungnashif
authored andcommitted
riscv: initialize privileged stack during thread init
This adds the bits to initialize the privileged stack when a thread is transitioning to user mode. This prevents information leaking if the stack is reused, and also aids in calculating stack space usage during system calls. Signed-off-by: Daniel Leung <[email protected]>
1 parent 55ee97c commit bb31335

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

arch/riscv/core/thread.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ FUNC_NORETURN void arch_user_mode_enter(k_thread_entry_t user_entry,
144144
K_KERNEL_STACK_RESERVED +
145145
CONFIG_PRIVILEGED_STACK_SIZE);
146146

147+
#ifdef CONFIG_INIT_STACKS
148+
/* Initialize the privileged stack */
149+
(void)memset((void *)_current->arch.priv_stack_start, 0xaa,
150+
Z_STACK_PTR_ALIGN(K_KERNEL_STACK_RESERVED + CONFIG_PRIVILEGED_STACK_SIZE));
151+
#endif /* CONFIG_INIT_STACKS */
152+
147153
top_of_user_stack = Z_STACK_PTR_ALIGN(
148154
_current->stack_info.start +
149155
_current->stack_info.size -

0 commit comments

Comments
 (0)