Kernel: Don't kill process if stack pointer is OOB

This can be valid if process is using green threads or for some other
reason using its own stack
This commit is contained in:
Bananymous 2025-08-03 21:46:38 +03:00
parent 927fbda1e8
commit 284c9e5f61
1 changed files with 20 additions and 20 deletions

View File

@ -188,26 +188,6 @@ namespace Kernel
if (isr == ISR::PageFault && Thread::current().is_userspace()) if (isr == ISR::PageFault && Thread::current().is_userspace())
{ {
// Check if stack is OOB
if (ARCH(i686) && !GDT::is_user_segment(interrupt_stack->cs))
; // 32 bit does not push stack pointer when no CPL change happens
else if (thread.userspace_stack_bottom() < interrupt_stack->sp && interrupt_stack->sp <= thread.userspace_stack_top())
; // using userspace stack
else if (thread.kernel_stack_bottom() < interrupt_stack->sp && interrupt_stack->sp <= thread.kernel_stack_top())
; // using kernel stack
else
{
derrorln("Stack pointer out of bounds!");
derrorln("rip {H}", interrupt_stack->ip);
derrorln("rsp {H}, userspace stack {H}->{H}, kernel stack {H}->{H}",
interrupt_stack->sp,
thread.userspace_stack_bottom(), thread.userspace_stack_top(),
thread.kernel_stack_bottom(), thread.kernel_stack_top()
);
Thread::current().handle_signal(SIGKILL);
goto done;
}
if (pid) if (pid)
{ {
PageFaultError page_fault_error; PageFaultError page_fault_error;
@ -227,6 +207,26 @@ namespace Kernel
goto done; goto done;
} }
} }
// Check if stack is OOB
if (ARCH(i686) && !GDT::is_user_segment(interrupt_stack->cs))
; // 32 bit does not push stack pointer when no CPL change happens
else if (thread.userspace_stack_bottom() < interrupt_stack->sp && interrupt_stack->sp <= thread.userspace_stack_top())
; // using userspace stack
else if (thread.kernel_stack_bottom() < interrupt_stack->sp && interrupt_stack->sp <= thread.kernel_stack_top())
; // using kernel stack
else
{
derrorln("Stack pointer out of bounds!");
derrorln("rip {H}", interrupt_stack->ip);
derrorln("rsp {H}, userspace stack {H}->{H}, kernel stack {H}->{H}",
interrupt_stack->sp,
thread.userspace_stack_bottom(), thread.userspace_stack_top(),
thread.kernel_stack_bottom(), thread.kernel_stack_top()
);
Thread::current().handle_signal(SIGKILL);
goto done;
}
} }
} }