From: Andy Lutomirski <luto@kernel.org>
To: X86 ML <x86@kernel.org>, linux-kernel@vger.kernel.org
Cc: Brian Gerst <brgerst@gmail.com>,
Steven Rostedt <rostedt@goodmis.org>, Willy Tarreau <w@1wt.eu>,
Borislav Petkov <bp@alien8.de>,
Thomas Gleixner <tglx@linutronix.de>,
Peter Zijlstra <peterz@infradead.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Andy Lutomirski <luto@kernel.org>
Subject: [PATCH 3/3] x86/entry/64: Move #BP from IST to the IRQ stack
Date: Thu, 23 Jul 2015 15:37:48 -0700 [thread overview]
Message-ID: <881f70d2156267e8f9cd901ce0f66b6cd029a44c.1437690860.git.luto@kernel.org> (raw)
In-Reply-To: <cover.1437690860.git.luto@kernel.org>
In-Reply-To: <cover.1437690860.git.luto@kernel.org>
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 <luto@kernel.org>
---
arch/x86/entry/entry_64.S | 2 +-
arch/x86/kernel/traps.c | 26 +++++++++++++-------------
2 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
index ce72beba6045..fb3253ae7ecc 100644
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -990,7 +990,7 @@ apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
#endif /* CONFIG_HYPERV */
idtentry debug do_debug has_error_code=0 paranoid=1 shift_ist=DEBUG_STACK
-idtentry int3 do_int3 has_error_code=0 paranoid=1 shift_ist=DEBUG_STACK
+idtentry int3 do_int3 has_error_code=0 irqstack=1
idtentry stack_segment do_stack_segment has_error_code=1
#ifdef CONFIG_XEN
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index 8e65d8a9b8db..d823db70f492 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -479,7 +479,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
}
NOKPROBE_SYMBOL(do_general_protection);
-/* May run on IST stack. */
+/* Runs on IRQ stack. */
dotraplinkage void notrace do_int3(struct pt_regs *regs, long error_code)
{
#ifdef CONFIG_DYNAMIC_FTRACE
@@ -494,7 +494,15 @@ dotraplinkage void notrace do_int3(struct pt_regs *regs, long error_code)
if (poke_int3_handler(regs))
return;
+ /*
+ * Use ist_enter despite the fact that we don't use an IST stack.
+ * We can be called from a kprobe in non-CONTEXT_KERNEL kernel
+ * mode or even during context tracking state changes.
+ *
+ * This means that we can't schedule. That's okay.
+ */
ist_enter(regs);
+
CT_WARN_ON(ct_state() != CONTEXT_KERNEL);
#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP
if (kgdb_ll_trap(DIE_INT3, "int3", regs, error_code, X86_TRAP_BP,
@@ -511,15 +519,10 @@ dotraplinkage void notrace do_int3(struct pt_regs *regs, long error_code)
SIGTRAP) == NOTIFY_STOP)
goto exit;
- /*
- * Let others (NMI) know that the debug stack is in use
- * as we may switch to the interrupt stack.
- */
- debug_stack_usage_inc();
preempt_conditional_sti(regs);
do_trap(X86_TRAP_BP, SIGTRAP, "int3", regs, error_code, NULL);
preempt_conditional_cli(regs);
- debug_stack_usage_dec();
+
exit:
ist_exit(regs);
}
@@ -885,19 +888,16 @@ void __init trap_init(void)
cpu_init();
/*
- * X86_TRAP_DB and X86_TRAP_BP have been set
- * in early_trap_init(). However, ITS works only after
- * cpu_init() loads TSS. See comments in early_trap_init().
+ * X86_TRAP_DB was installed in early_trap_init(). However,
+ * IST works only after cpu_init() loads TSS. See comments
+ * in early_trap_init().
*/
set_intr_gate_ist(X86_TRAP_DB, &debug, DEBUG_STACK);
- /* int3 can be called from all */
- set_system_intr_gate_ist(X86_TRAP_BP, &int3, DEBUG_STACK);
x86_init.irqs.trap_init();
#ifdef CONFIG_X86_64
memcpy(&debug_idt_table, &idt_table, IDT_ENTRIES * 16);
set_nmi_gate(X86_TRAP_DB, &debug);
- set_nmi_gate(X86_TRAP_BP, &int3);
#endif
}
--
2.4.3
next prev parent reply other threads:[~2015-07-23 22:38 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-23 22:37 [PATCH 0/3] x86_64: Make int3 non-magical Andy Lutomirski
2015-07-23 22:37 ` [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe Andy Lutomirski
2015-07-24 6:08 ` Andy Lutomirski
2015-07-24 10:25 ` Borislav Petkov
2015-07-24 18:02 ` Andy Lutomirski
2015-07-25 4:16 ` Borislav Petkov
2015-07-25 4:28 ` Andy Lutomirski
2015-07-25 4:32 ` Borislav Petkov
2015-07-25 4:59 ` Andy Lutomirski
2015-07-25 8:39 ` Borislav Petkov
2015-07-25 17:56 ` Linus Torvalds
2015-07-25 17:59 ` Andy Lutomirski
2015-07-25 18:12 ` Linus Torvalds
2015-08-05 8:59 ` Ingo Molnar
2015-08-05 18:24 ` Andy Lutomirski
2015-08-05 18:27 ` Steven Rostedt
2015-08-05 18:32 ` Andy Lutomirski
2015-08-22 13:55 ` Ingo Molnar
2015-07-23 22:37 ` [PATCH 2/3] x86/entry/64: Teach idtentry to use the IRQ stack Andy Lutomirski
2015-07-23 22:37 ` Andy Lutomirski [this message]
2015-07-24 11:02 ` [PATCH 3/3] x86/entry/64: Move #BP from IST to " Borislav Petkov
2015-07-23 22:39 ` [PATCH 0/3] x86_64: Make int3 non-magical Andy Lutomirski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=881f70d2156267e8f9cd901ce0f66b6cd029a44c.1437690860.git.luto@kernel.org \
--to=luto@kernel.org \
--cc=bp@alien8.de \
--cc=brgerst@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=w@1wt.eu \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®