Commit 08bde997 authored by Philippe Gerum's avatar Philippe Gerum

x86/ipipe: x86_64: fix stack overflow detection

Due to the deferred IRQ dispatching model when the pipeline is active,
the detection code may not assume that its runs over the preempted
stack context, so regs->sp does not necessarily point at the current
stack context anymore.

Explicitly compare the current %rsp value against valid stack
boundaries instead.

This fixes spurious overflow detections when
CONFIG_DEBUG_STACKOVERFLOW is enabled.
parent 30974fdb
......@@ -43,29 +43,35 @@ static inline void stack_overflow_check(struct pt_regs *regs)
u64 irq_stack_top, irq_stack_bottom;
u64 estack_top, estack_bottom;
u64 curbase = (u64)task_stack_page(current);
unsigned long sp;
if (user_mode(regs))
return;
if (regs->sp >= curbase + sizeof(struct thread_info) +
if (IS_ENABLED(CONFIG_IPIPE))
sp = current_stack_pointer();
else
sp = regs->sp;
if (sp >= curbase + sizeof(struct thread_info) +
sizeof(struct pt_regs) + STACK_TOP_MARGIN &&
regs->sp <= curbase + THREAD_SIZE)
sp <= curbase + THREAD_SIZE)
return;
irq_stack_top = (u64)this_cpu_ptr(irq_stack_union.irq_stack) +
STACK_TOP_MARGIN;
irq_stack_bottom = (u64)__this_cpu_read(irq_stack_ptr);
if (regs->sp >= irq_stack_top && regs->sp <= irq_stack_bottom)
if (sp >= irq_stack_top && sp <= irq_stack_bottom)
return;
oist = this_cpu_ptr(&orig_ist);
estack_top = (u64)oist->ist[0] - EXCEPTION_STKSZ + STACK_TOP_MARGIN;
estack_bottom = (u64)oist->ist[N_EXCEPTION_STACKS - 1];
if (regs->sp >= estack_top && regs->sp <= estack_bottom)
if (sp >= estack_top && sp <= estack_bottom)
return;
WARN_ONCE(1, "do_IRQ(): %s has overflown the kernel stack (cur:%Lx,sp:%lx,irq stk top-bottom:%Lx-%Lx,exception stk top-bottom:%Lx-%Lx)\n",
current->comm, curbase, regs->sp,
current->comm, curbase, sp,
irq_stack_top, irq_stack_bottom,
estack_top, estack_bottom);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment