Skip to content

Commit

Permalink
x86: make guard pages ro instead of non-present
Browse files Browse the repository at this point in the history
Has the same effect of catching stack overflows, but
makes debugging with GDB simpler since we won't get
errors when inspecting such regions. Making these
areas non-present was more than we needed, read-only
is sufficient.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
  • Loading branch information
Andrew Boie authored and carlescufi committed Aug 5, 2019
1 parent 7fae2bb commit 76310f6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
16 changes: 6 additions & 10 deletions arch/x86/core/ia32/thread.c
Expand Up @@ -72,15 +72,15 @@ void z_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
/* Running in kernel mode, kernel stack region is also a guard
* page */
z_x86_mmu_set_flags(&z_x86_kernel_pdpt,
(void *)(stack_buf - MMU_PAGE_SIZE),
MMU_PAGE_SIZE, MMU_ENTRY_NOT_PRESENT,
MMU_PTE_P_MASK);
(void *)(stack_buf - MMU_PAGE_SIZE),
MMU_PAGE_SIZE, MMU_ENTRY_READ,
MMU_PTE_RW_MASK);
}
#endif /* CONFIG_X86_USERSPACE */

#if CONFIG_X86_STACK_PROTECTION
z_x86_mmu_set_flags(&z_x86_kernel_pdpt, stack, MMU_PAGE_SIZE,
MMU_ENTRY_NOT_PRESENT, MMU_PTE_P_MASK);
MMU_ENTRY_READ, MMU_PTE_RW_MASK);
#endif

stack_high = (char *)STACK_ROUND_DOWN(stack_buf + stack_size);
Expand Down Expand Up @@ -178,12 +178,8 @@ FUNC_NORETURN void z_arch_user_mode_enter(k_thread_entry_t user_entry,

/* Set up the kernel stack used during privilege elevation */
z_x86_mmu_set_flags(&z_x86_kernel_pdpt,
(void *)(_current->stack_info.start - MMU_PAGE_SIZE),
MMU_PAGE_SIZE,
(MMU_ENTRY_PRESENT | MMU_ENTRY_WRITE |
MMU_ENTRY_SUPERVISOR),
(MMU_PTE_P_MASK | MMU_PTE_RW_MASK |
MMU_PTE_US_MASK));
(void *)(_current->stack_info.start - MMU_PAGE_SIZE),
MMU_PAGE_SIZE, MMU_ENTRY_WRITE, MMU_PTE_RW_MASK);

z_x86_userspace_enter(user_entry, p1, p2, p3, stack_end,
_current->stack_info.start);
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/include/ia32/kernel_arch_func.h
Expand Up @@ -49,7 +49,7 @@ static inline void kernel_arch_init(void)
#endif
#if CONFIG_X86_STACK_PROTECTION
z_x86_mmu_set_flags(&z_x86_kernel_pdpt, _interrupt_stack, MMU_PAGE_SIZE,
MMU_ENTRY_NOT_PRESENT, MMU_PTE_P_MASK);
MMU_ENTRY_READ, MMU_PTE_RW_MASK);
#endif
}

Expand Down

0 comments on commit 76310f6

Please sign in to comment.