diff --git a/kernel/arch/x86_64/IDT.cpp b/kernel/arch/x86_64/IDT.cpp index 67ac57dc37..30d8abcc07 100644 --- a/kernel/arch/x86_64/IDT.cpp +++ b/kernel/arch/x86_64/IDT.cpp @@ -181,14 +181,20 @@ namespace Kernel::IDT { // Check if stack is OOB auto& stack = Thread::current().stack(); - if (interrupt_stack.rsp < stack.vaddr()) + auto& istack = Thread::current().interrupt_stack(); + if (stack.vaddr() < interrupt_stack.rsp && interrupt_stack.rsp <= stack.vaddr() + stack.size()) + ; // using normal stack + else if (istack.vaddr() < interrupt_stack.rsp && interrupt_stack.rsp <= istack.vaddr() + istack.size()) + ; // using interrupt stack + else { - derrorln("Stack overflow"); - goto done; - } - if (interrupt_stack.rsp >= stack.vaddr() + stack.size()) - { - derrorln("Stack underflow"); + derrorln("Stack pointer out of bounds!"); + derrorln("rsp {H}, stack {H}->{H}, istack {H}->{H}", + interrupt_stack.rsp, + stack.vaddr(), stack.vaddr() + stack.size(), + istack.vaddr(), istack.vaddr() + istack.size() + ); + Thread::current().handle_signal(SIGKILL); goto done; } @@ -207,7 +213,7 @@ namespace Kernel::IDT if (result.is_error()) { dwarnln("Demand paging: {}", result.error()); - Thread::current().handle_signal(SIGTERM); + Thread::current().handle_signal(SIGKILL); goto done; } } diff --git a/kernel/include/kernel/Thread.h b/kernel/include/kernel/Thread.h index c988f7af2d..3d5383b072 100644 --- a/kernel/include/kernel/Thread.h +++ b/kernel/include/kernel/Thread.h @@ -71,6 +71,7 @@ namespace Kernel vaddr_t stack_base() const { return m_stack->vaddr(); } size_t stack_size() const { return m_stack->size(); } VirtualRange& stack() { return *m_stack; } + VirtualRange& interrupt_stack() { return *m_interrupt_stack; } vaddr_t interrupt_stack_base() const { return m_interrupt_stack ? m_interrupt_stack->vaddr() : 0; } size_t interrupt_stack_size() const { return m_interrupt_stack ? m_interrupt_stack->size() : 0; }