]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commit
feat: guard pages for kernel stacks — detect overflow via page fault
authorTulio A M Mendes <[email protected]>
Thu, 12 Feb 2026 07:40:52 +0000 (04:40 -0300)
committerTulio A M Mendes <[email protected]>
Fri, 13 Feb 2026 02:44:55 +0000 (23:44 -0300)
commit9b3e297ac460daa5668732d3644e5d77bd733b79
treef60dd6008666aed3935fc9ea42c3370113494f13
parentfe27fefd94e95a8a8eff22fe4729f82ec6a37de7
feat: guard pages for kernel stacks — detect overflow via page fault

Replaced kmalloc(4096) kernel stack allocation with a dedicated
kstack_alloc() that uses a virtual address region (0xC8000000+)
with guard pages. Each stack slot is 2 pages:

  [guard page (unmapped)] [stack page (mapped, 4KB)]

If a kernel stack overflows, the CPU hits the unmapped guard page
and triggers a page fault instead of silently corrupting heap
metadata. This eliminates the class of heap corruption bugs caused
by deep syscall call chains or large stack frames.

All 4 kernel stack allocation sites updated:
- process_init (PID 0)
- process_fork_create
- process_clone_impl
- create_kernel_thread

kstack_free() unmaps the stack page on process exit.
src/kernel/scheduler.c