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 <daniel.leung@intel.com>
This commit is contained in:
Daniel Leung 2024-07-31 11:46:07 -07:00 committed by Anas Nashif
commit c25fa96a68

View file

@ -70,15 +70,18 @@ void *z_x86_userspace_prepare_thread(struct k_thread *thread)
{ {
void *initial_entry; void *initial_entry;
struct z_x86_thread_stack_header *header = if (z_stack_is_user_capable(thread->stack_obj)) {
struct z_x86_thread_stack_header *header =
#ifdef CONFIG_THREAD_STACK_MEM_MAPPED #ifdef CONFIG_THREAD_STACK_MEM_MAPPED
(struct z_x86_thread_stack_header *)thread->stack_info.mapped.addr; (struct z_x86_thread_stack_header *)thread->stack_info.mapped.addr;
#else #else
(struct z_x86_thread_stack_header *)thread->stack_obj; (struct z_x86_thread_stack_header *)thread->stack_obj;
#endif /* CONFIG_THREAD_STACK_MEM_MAPPED */ #endif /* CONFIG_THREAD_STACK_MEM_MAPPED */
thread->arch.psp = thread->arch.psp = header->privilege_stack + sizeof(header->privilege_stack);
header->privilege_stack + sizeof(header->privilege_stack); } else {
thread->arch.psp = NULL;
}
#ifndef CONFIG_X86_COMMON_PAGE_TABLE #ifndef CONFIG_X86_COMMON_PAGE_TABLE
/* Important this gets cleared, so that arch_mem_domain_* APIs /* Important this gets cleared, so that arch_mem_domain_* APIs