Skip to content

Commit 7dbcf2b

Browse files
KAGA-KOKOsuryasaimadhu
authored andcommitted
x86/irq/64: Limit IST stack overflow check to #DB stack
Commit 37fe6a4 ("x86: Check stack overflow in detail") added a broad check for the full exception stack area, i.e. it considers the full exception stack area as valid. That's wrong in two aspects: 1) It does not check the individual areas one by one 2) #DF, NMI and #MCE are not enabling interrupts which means that a regular device interrupt cannot happen in their context. In fact if a device interrupt hits one of those IST stacks that's a bug because some code path enabled interrupts while handling the exception. Limit the check to the #DB stack and consider all other IST stacks as 'overflow' or invalid. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Borislav Petkov <bp@suse.de> Cc: Andy Lutomirski <luto@kernel.org> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Mitsuo Hayasaka <mitsuo.hayasaka.hu@hitachi.com> Cc: Nicolai Stange <nstange@suse.de> Cc: Sean Christopherson <sean.j.christopherson@intel.com> Cc: x86-ml <x86@kernel.org> Link: https://lkml.kernel.org/r/20190414160143.682135110@linutronix.de
1 parent 80552f0 commit 7dbcf2b

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

‎arch/x86/kernel/irq_64.c‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,18 @@ int sysctl_panic_on_stackoverflow;
2626
/*
2727
* Probabilistic stack overflow check:
2828
*
29-
* Only check the stack in process context, because everything else
30-
* runs on the big interrupt stacks. Checking reliably is too expensive,
31-
* so we just check from interrupts.
29+
* Regular device interrupts can enter on the following stacks:
30+
*
31+
* - User stack
32+
*
33+
* - Kernel task stack
34+
*
35+
* - Interrupt stack if a device driver reenables interrupts
36+
* which should only happen in really old drivers.
37+
*
38+
* - Debug IST stack
39+
*
40+
* All other contexts are invalid.
3241
*/
3342
static inline void stack_overflow_check(struct pt_regs *regs)
3443
{
@@ -53,8 +62,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
5362
return;
5463

5564
oist = this_cpu_ptr(&orig_ist);
56-
estack_top = (u64)oist->ist[0] - EXCEPTION_STKSZ + STACK_TOP_MARGIN;
57-
estack_bottom = (u64)oist->ist[N_EXCEPTION_STACKS - 1];
65+
estack_bottom = (u64)oist->ist[DEBUG_STACK];
66+
estack_top = estack_bottom - DEBUG_STKSZ + STACK_TOP_MARGIN;
5867
if (regs->sp >= estack_top && regs->sp <= estack_bottom)
5968
return;
6069

0 commit comments

Comments
 (0)