Skip to content

Commit d8ba61b

Browse files
amlutoKAGA-KOKO
authored andcommitted
x86/entry/64: Don't use IST entry for #BP stack
There's nothing IST-worthy about #BP/int3. We don't allow kprobes in the small handful of places in the kernel that run at CPL0 with an invalid stack, and 32-bit kernels have used normal interrupt gates for #BP forever. Furthermore, we don't allow kprobes in places that have usergs while in kernel mode, so "paranoid" is also unnecessary. Signed-off-by: Andy Lutomirski <[email protected]> Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Cc: [email protected]
1 parent 06ace26 commit d8ba61b

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

arch/x86/entry/entry_64.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ apicinterrupt3 HYPERV_REENLIGHTENMENT_VECTOR \
11381138
#endif /* CONFIG_HYPERV */
11391139

11401140
idtentry debug do_debug has_error_code=0 paranoid=1 shift_ist=DEBUG_STACK
1141-
idtentry int3 do_int3 has_error_code=0 paranoid=1 shift_ist=DEBUG_STACK
1141+
idtentry int3 do_int3 has_error_code=0
11421142
idtentry stack_segment do_stack_segment has_error_code=1
11431143

11441144
#ifdef CONFIG_XEN

arch/x86/kernel/idt.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ static const __initconst struct idt_data early_pf_idts[] = {
160160
*/
161161
static const __initconst struct idt_data dbg_idts[] = {
162162
INTG(X86_TRAP_DB, debug),
163-
INTG(X86_TRAP_BP, int3),
164163
};
165164
#endif
166165

@@ -183,7 +182,6 @@ gate_desc debug_idt_table[IDT_ENTRIES] __page_aligned_bss;
183182
static const __initconst struct idt_data ist_idts[] = {
184183
ISTG(X86_TRAP_DB, debug, DEBUG_STACK),
185184
ISTG(X86_TRAP_NMI, nmi, NMI_STACK),
186-
SISTG(X86_TRAP_BP, int3, DEBUG_STACK),
187185
ISTG(X86_TRAP_DF, double_fault, DOUBLEFAULT_STACK),
188186
#ifdef CONFIG_X86_MCE
189187
ISTG(X86_TRAP_MC, &machine_check, MCE_STACK),

arch/x86/kernel/traps.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,6 @@ do_general_protection(struct pt_regs *regs, long error_code)
577577
}
578578
NOKPROBE_SYMBOL(do_general_protection);
579579

580-
/* May run on IST stack. */
581580
dotraplinkage void notrace do_int3(struct pt_regs *regs, long error_code)
582581
{
583582
#ifdef CONFIG_DYNAMIC_FTRACE
@@ -592,6 +591,13 @@ dotraplinkage void notrace do_int3(struct pt_regs *regs, long error_code)
592591
if (poke_int3_handler(regs))
593592
return;
594593

594+
/*
595+
* Use ist_enter despite the fact that we don't use an IST stack.
596+
* We can be called from a kprobe in non-CONTEXT_KERNEL kernel
597+
* mode or even during context tracking state changes.
598+
*
599+
* This means that we can't schedule. That's okay.
600+
*/
595601
ist_enter(regs);
596602
RCU_LOCKDEP_WARN(!rcu_is_watching(), "entry code didn't wake RCU");
597603
#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP
@@ -609,15 +615,10 @@ dotraplinkage void notrace do_int3(struct pt_regs *regs, long error_code)
609615
SIGTRAP) == NOTIFY_STOP)
610616
goto exit;
611617

612-
/*
613-
* Let others (NMI) know that the debug stack is in use
614-
* as we may switch to the interrupt stack.
615-
*/
616-
debug_stack_usage_inc();
617618
cond_local_irq_enable(regs);
618619
do_trap(X86_TRAP_BP, SIGTRAP, "int3", regs, error_code, NULL);
619620
cond_local_irq_disable(regs);
620-
debug_stack_usage_dec();
621+
621622
exit:
622623
ist_exit(regs);
623624
}

0 commit comments

Comments
 (0)