Skip to content

Commit c25fa96

Browse files
dcpleungnashif
authored andcommitted
x86: only set psp pointer for thread stacks
Only set the privileged stack pointer for thread stacks, but nullify the pointer for kernel-only stacks, as these stacks do not have the reserved space. The psp pointer may point to arbitrary memory in this case if stack is not big enough. Signed-off-by: Daniel Leung <[email protected]>
1 parent d26b7d4 commit c25fa96

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

arch/x86/core/userspace.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,18 @@ void *z_x86_userspace_prepare_thread(struct k_thread *thread)
7070
{
7171
void *initial_entry;
7272

73-
struct z_x86_thread_stack_header *header =
73+
if (z_stack_is_user_capable(thread->stack_obj)) {
74+
struct z_x86_thread_stack_header *header =
7475
#ifdef CONFIG_THREAD_STACK_MEM_MAPPED
75-
(struct z_x86_thread_stack_header *)thread->stack_info.mapped.addr;
76+
(struct z_x86_thread_stack_header *)thread->stack_info.mapped.addr;
7677
#else
77-
(struct z_x86_thread_stack_header *)thread->stack_obj;
78+
(struct z_x86_thread_stack_header *)thread->stack_obj;
7879
#endif /* CONFIG_THREAD_STACK_MEM_MAPPED */
7980

80-
thread->arch.psp =
81-
header->privilege_stack + sizeof(header->privilege_stack);
81+
thread->arch.psp = header->privilege_stack + sizeof(header->privilege_stack);
82+
} else {
83+
thread->arch.psp = NULL;
84+
}
8285

8386
#ifndef CONFIG_X86_COMMON_PAGE_TABLE
8487
/* Important this gets cleared, so that arch_mem_domain_* APIs

0 commit comments

Comments
 (0)