Skip to contentSkip to conversation

kprobes: fix bugs by updating blacklist

PATCH In review Masami Hiramatsu 2 participants 5 messages Oct 30, 2013 – Nov 1, 2013 x86

lore
Share & tools
lore
#0 lore raw

cover kprobes: fix bugs by updating blacklist

Recently I've found that putting probes on some functions could lock or reboot the kernel. These two patches fix those bugs by prohibiting probing such functions by adding those to blacklist(kprobes.text).

In both cases, those functions are related to int3 handling execution path. One is related to irqoff-tracer and the other is related to notifier debug option.

Thank you,

---

Masami Hiramatsu (2):
[BUGFIX] kprobes/x86: Prohibit probing on debug_stack_* [BUGFIX] kprobes: Prohibit probing on func_ptr_is_kernel_text

 arch/x86/kernel/cpu/common.c |    7 ++++---
 kernel/extable.c             |    3 ++-
 2 files changed, 6 insertions(+), 4 deletions(-)
Signature · 4 lines
Masami HIRAMATSU
IT Management Research Dept. Linux Technology Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: [email protected]
#1 lore raw

PATCH 1/2 kprobes/x86: Prohibit probing on debug_stack_*

Prohibit probing on debug_stack_reset and debug_stack_set_zero. Since the both functions are called from TRACE_IRQS_ON/OFF_DEBUG macros which run in int3 ist entry, probing it may cause a soft lockup.

This happens when the kernel built with CONFIG_DYNAMIC_FTRACE=y and CONFIG_TRACE_IRQFLAGS=y.

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Fenghua Yu <[email protected]>
Cc Seiji Aguchi <[email protected]>
---
 arch/x86/kernel/cpu/common.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/common.c +4 -3
index 35e28b0..8712a1a 100644
@@ -11,6 +11,7 @@
 #include <linux/kgdb.h>
 #include <linux/smp.h>
 #include <linux/io.h>
+#include <linux/kprobes.h>
 
 #include <asm/stackprotector.h>
 #include <asm/perf_event.h>
@@ -1158,7 +1159,7 @@ DEFINE_PER_CPU(struct orig_ist, orig_ist);
 static DEFINE_PER_CPU(unsigned long, debug_stack_addr);
 DEFINE_PER_CPU(int, debug_stack_usage);
 
-int is_debug_stack(unsigned long addr)
+int __kprobes is_debug_stack(unsigned long addr)
 {
 	return __get_cpu_var(debug_stack_usage) ||
 		(addr <= __get_cpu_var(debug_stack_addr) &&
@@ -1167,13 +1168,13 @@ int is_debug_stack(unsigned long addr)
 
 DEFINE_PER_CPU(u32, debug_idt_ctr);
 
-void debug_stack_set_zero(void)
+void __kprobes debug_stack_set_zero(void)
 {
 	this_cpu_inc(debug_idt_ctr);
 	load_current_idt();
 }
 
-void debug_stack_reset(void)
+void __kprobes debug_stack_reset(void)
 {
 	if (WARN_ON(!this_cpu_read(debug_idt_ctr)))
 		return;
#2 lore raw

Re: [PATCH -tip 1/2] [BUGFIX] kprobes/x86: Prohibit probing on debug_stack_*

arch/x86/kernel/cpu/common.c DEFINE_PER_CPU(struct orig_ist, orig_ist); · line 1162

Quoted 2 lines · Masami Hiramatsu
arch/x86/kernel/cpu/common.c +1 -1
-int is_debug_stack(unsigned long addr)
+int __kprobes is_debug_stack(unsigned long addr)

_Please_ add a __noprobes method, for new annotations.

Naming it '__kprobes' is actively confusing, as it suggests that the function is somehow positively involved with kprobes support. Instead it should the noinline/notrace pattern.

I complained about this before and not much happened on this front. We might not want to convert the whole kernel straight away, but for _new_ annotations there's no excuse not to name them properly. Lets phase out __kprobes, and use __noprobe from now on, okay?

Thanks,

Ingo

#3 lore raw

Re: [PATCH -tip 1/2] [BUGFIX] kprobes/x86: Prohibit probing on debug_stack_*

Quoted 7 lines · Ingo Molnar

arch/x86/kernel/cpu/common.c DEFINE_PER_CPU(struct orig_ist, orig_ist); · line 1162

Quoted 2 lines · Masami Hiramatsu
arch/x86/kernel/cpu/common.c +1 -1
-int is_debug_stack(unsigned long addr)
+int __kprobes is_debug_stack(unsigned long addr)

_Please_ add a __noprobes method, for new annotations.

Ah, OK. I'll send new series.

Quoted 8 lines

Naming it '__kprobes' is actively confusing, as it suggests that the function is somehow positively involved with kprobes support. Instead it should the noinline/notrace pattern.

I complained about this before and not much happened on this front. We might not want to convert the whole kernel straight away, but for _new_ annotations there's no excuse not to name them properly. Lets phase out __kprobes, and use __noprobe from now on, okay?

I see it. :)

Thank you,

Signature · 4 lines
Masami HIRAMATSU
IT Management Research Dept. Linux Technology Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: [email protected]
#4 lore raw

PATCH 2/2 kprobes: Prohibit probing on func_ptr_is_kernel_text

In reply to Masami Hiramatsu

Prohibit probing on func_ptr_is_kernel_text(). Since the func_ptr_is_kernel_text() is called from notifier_call_chain() which is called from int3 handler, probing it may cause double int3 fault and kernel will reboot.

This happenes when the kernel built with CONFIG_DEBUG_NOTIFIERS=y.

Cc Andrew Morton <[email protected]>
Cc "Uwe Kleine-König" <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Ingo Molnar <[email protected]>
---
 kernel/extable.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/extable.c +2 -1
index 832cb28..b3b8b6a 100644
@@ -20,6 +20,7 @@
 #include <linux/module.h>
 #include <linux/mutex.h>
 #include <linux/init.h>
+#include <linux/kprobes.h>
 
 #include <asm/sections.h>
 #include <asm/uaccess.h>
@@ -129,7 +130,7 @@ int kernel_text_address(unsigned long addr)
  * pointer is part of the kernel text, we need to do some
  * special dereferencing first.
  */
-int func_ptr_is_kernel_text(void *ptr)
+int __kprobes func_ptr_is_kernel_text(void *ptr)
 {
 	unsigned long addr;
 	addr = (unsigned long) dereference_function_descriptor(ptr);