Skip to content

Commit df835e7

Browse files
KAGA-KOKOsuryasaimadhu
authored andcommitted
x86/irq/64: Sanitize the top/bottom confusion
On x86, stacks go top to bottom, but the stack overflow check uses it the other way round, which is just confusing. Clean it up and sanitize the warning string a bit. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Borislav Petkov <bp@suse.de> Reviewed-by: Sean Christopherson <sean.j.christopherson@intel.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Nicolai Stange <nstange@suse.de> Cc: x86-ml <x86@kernel.org> Link: https://lkml.kernel.org/r/20190414160143.961241397@linutronix.de
1 parent 4f44b8f commit df835e7

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

arch/x86/kernel/irq_64.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ int sysctl_panic_on_stackoverflow;
4242
static inline void stack_overflow_check(struct pt_regs *regs)
4343
{
4444
#ifdef CONFIG_DEBUG_STACKOVERFLOW
45-
#define STACK_TOP_MARGIN 128
45+
#define STACK_MARGIN 128
4646
struct orig_ist *oist;
4747
u64 irq_stack_top, irq_stack_bottom;
4848
u64 estack_top, estack_bottom;
@@ -51,25 +51,25 @@ static inline void stack_overflow_check(struct pt_regs *regs)
5151
if (user_mode(regs))
5252
return;
5353

54-
if (regs->sp >= curbase + sizeof(struct pt_regs) + STACK_TOP_MARGIN &&
54+
if (regs->sp >= curbase + sizeof(struct pt_regs) + STACK_MARGIN &&
5555
regs->sp <= curbase + THREAD_SIZE)
5656
return;
5757

58-
irq_stack_bottom = (u64)__this_cpu_read(irq_stack_ptr);
59-
irq_stack_top = irq_stack_bottom - IRQ_STACK_SIZE + STACK_TOP_MARGIN;
60-
if (regs->sp >= irq_stack_top && regs->sp <= irq_stack_bottom)
58+
irq_stack_top = (u64)__this_cpu_read(irq_stack_ptr);
59+
irq_stack_bottom = irq_stack_top - IRQ_STACK_SIZE + STACK_MARGIN;
60+
if (regs->sp >= irq_stack_bottom && regs->sp <= irq_stack_top)
6161
return;
6262

6363
oist = this_cpu_ptr(&orig_ist);
64-
estack_bottom = (u64)oist->ist[DEBUG_STACK];
65-
estack_top = estack_bottom - DEBUG_STKSZ + STACK_TOP_MARGIN;
66-
if (regs->sp >= estack_top && regs->sp <= estack_bottom)
64+
estack_top = (u64)oist->ist[DEBUG_STACK];
65+
estack_bottom = estack_top - DEBUG_STKSZ + STACK_MARGIN;
66+
if (regs->sp >= estack_bottom && regs->sp <= estack_top)
6767
return;
6868

69-
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,ip:%pF)\n",
69+
WARN_ONCE(1, "do_IRQ(): %s has overflown the kernel stack (cur:%Lx,sp:%lx, irq stack:%Lx-%Lx, exception stack: %Lx-%Lx, ip:%pF)\n",
7070
current->comm, curbase, regs->sp,
71-
irq_stack_top, irq_stack_bottom,
72-
estack_top, estack_bottom, (void *)regs->ip);
71+
irq_stack_bottom, irq_stack_top,
72+
estack_bottom, estack_top, (void *)regs->ip);
7373

7474
if (sysctl_panic_on_stackoverflow)
7575
panic("low stack detected by irq handler - check messages\n");

0 commit comments

Comments
 (0)