Skip to content

Commit

Permalink
x86/irq/64: Limit IST stack overflow check to #DB stack
Browse files Browse the repository at this point in the history
[ Upstream commit 7dbcf2b ]

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 <[email protected]>
Signed-off-by: Borislav Petkov <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Josh Poimboeuf <[email protected]>
Cc: Mitsuo Hayasaka <[email protected]>
Cc: Nicolai Stange <[email protected]>
Cc: Sean Christopherson <[email protected]>
Cc: x86-ml <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
KAGA-KOKO authored and gregkh committed May 31, 2019
1 parent 97abdfa commit f843f84
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions arch/x86/kernel/irq_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,18 @@ int sysctl_panic_on_stackoverflow;
/*
* Probabilistic stack overflow check:
*
* Only check the stack in process context, because everything else
* runs on the big interrupt stacks. Checking reliably is too expensive,
* so we just check from interrupts.
* Regular device interrupts can enter on the following stacks:
*
* - User stack
*
* - Kernel task stack
*
* - Interrupt stack if a device driver reenables interrupts
* which should only happen in really old drivers.
*
* - Debug IST stack
*
* All other contexts are invalid.
*/
static inline void stack_overflow_check(struct pt_regs *regs)
{
Expand All @@ -53,8 +62,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
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];
estack_bottom = (u64)oist->ist[DEBUG_STACK];
estack_top = estack_bottom - DEBUG_STKSZ + STACK_TOP_MARGIN;
if (regs->sp >= estack_top && regs->sp <= estack_bottom)
return;

Expand Down

0 comments on commit f843f84

Please sign in to comment.