kprobes: introduce nokprobe and updating blacklist
Subsystems (2)
v2 cover kprobes: introduce nokprobe and updating blacklist
According to Ingo's suggestion, I've introduced 'nokprobe' new annotation as like as 'notrace' annotation, since __kprobes annotation is too confusing to mark non-kprobe able functions.
I took 'nokprobe' instead of 'noprobe' since we already have irq_set_noprobe() etc.
Also, 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,
Changes in the latest version:
- introduce nokprobe annotation
- change __kprobes to nokprobe in bugfixes
- remove unneeded linux/kprobes.h includings.
---
Masami Hiramatsu (3):
kprobes: Introduce nokprobe annotation for non-probe-able functions [BUGFIX] kprobes/x86: Prohibit probing on debug_stack_* [BUGFIX] kprobes: Prohibit probing on func_ptr_is_kernel_text
arch/x86/kernel/cpu/common.c | 6 +++--- include/linux/compiler.h | 6 ++++-- kernel/extable.c | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-)
Signature · 4 lines
Masami HIRAMATSU IT Management Research Dept. Linux Technology Center Hitachi, Ltd., Yokohama Research Laboratory E-mail: [email protected]
PATCH v2 1/3 kprobes: Introduce nokprobe annotation for non-probe-able functions
Instead of __kprobes annotation, introduce 'nokprobe' new annotation to annotate that the function is not probed by kprobes.
Previously the '__kprobes' is used just for avoiding probes on kprobes-related functions which will be used from kprobes. However nowadays we use it for prohibiting probing the functions implicitly invoked from kprobes int3 handler, since that causes infinit-loop lockup or sudden reboot. In this case, the annotated functions are not limited in the kprobes-related functions, and __kprobes looks very confusing. (Moreover, actually, most of control-side kprobes functions like as register_kprobes() are safely probed by kprobes)
Thus, we decide to introduce 'nokprobe' new annotation. We leave "__kprobes" just for compatibility but it should be replaced or removed eventually.
New commits must use 'nokprobe' for this purpose.
--- include/linux/compiler.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
include/linux/compiler.h +4 -2
@@ -353,8 +353,10 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);/* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */ #ifdef CONFIG_KPROBES -# define __kprobes __attribute__((__section__(".kprobes.text"))) +# define nokprobe __attribute__((__section__(".kprobes.text")))#else -# define __kprobes +# define nokprobe#endif +#define __kprobes nokprobe +#endif /* __LINUX_COMPILER_H */
Re: [PATCH -tip v2 1/3] kprobes: Introduce nokprobe annotation for non-probe-able functions
Quoted 31 lines · On Fri, 01 Nov 2013 11:25:32 +0000 Masami Hiramatsu…
Instead of
__kprobesannotation, introduce 'nokprobe' new annotation to annotate that the function is not probed by kprobes.Previously the '
__kprobes' is used just for avoiding probes on kprobes-related functions which will be used from kprobes. However nowadays we use it for prohibiting probing the functions implicitly invoked from kprobes int3 handler, since that causes infinit-loop lockup or sudden reboot. In this case, the annotated functions are not limited in the kprobes-related functions, and__kprobeslooks very confusing. (Moreover, actually, most of control-side kprobes functions like asregister_kprobes()are safely probed by kprobes)Thus, we decide to introduce 'nokprobe' new annotation. We leave "
__kprobes" just for compatibility but it should be replaced or removed eventually.New commits must use 'nokprobe' for this purpose.
Signed-off-by Masami Hiramatsu <[email protected]>Cc Ingo Molnar <[email protected]>Cc Ananth N Mavinakayanahalli <[email protected]>Cc "David S. Miller" <[email protected]>--- include/linux/compiler.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)include/linux/compiler.h +0
-0
include/linux/compiler.h void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect); · line 356
Quoted 5 lines
include/linux/compiler.h +1
-1@@ -353,8 +353,10 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);/* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */ #ifdef CONFIG_KPROBES -# define __kprobes __attribute__((__section__(".kprobes.text"))) +# define nokprobe __attribute__((__section__(".kprobes.text")))
I wonder if we should have both a __kprobes and nokprobe annotation, such that we have:
# define __kprobes __attribute__((__section__(".kprobes.text")))
# define nokprobe __attribute__((__section__(".nokprobes.text")))Then use __kprobes for the actual kprobes code, and nokprobe for all the places that must not be traced by kprobes.
It just seems strange to me grouping kprobes code with non kprobes code.
-- Steve
Quoted 8 lines
include/linux/compiler.h +3
-1#else -# define __kprobes +# define nokprobe#endif +#define __kprobes nokprobe +#endif /* __LINUX_COMPILER_H */
Re: Re: [PATCH -tip v2 1/3] kprobes: Introduce nokprobe annotation for non-probe-able functions
Quoted 43 lines · Steven Rostedt
Quoted 31 lines · On Fri, 01 Nov 2013 11:25:32 +0000 Masami Hiramatsu…
Instead of
__kprobesannotation, introduce 'nokprobe' new annotation to annotate that the function is not probed by kprobes.Previously the '
__kprobes' is used just for avoiding probes on kprobes-related functions which will be used from kprobes. However nowadays we use it for prohibiting probing the functions implicitly invoked from kprobes int3 handler, since that causes infinit-loop lockup or sudden reboot. In this case, the annotated functions are not limited in the kprobes-related functions, and__kprobeslooks very confusing. (Moreover, actually, most of control-side kprobes functions like asregister_kprobes()are safely probed by kprobes)Thus, we decide to introduce 'nokprobe' new annotation. We leave "
__kprobes" just for compatibility but it should be replaced or removed eventually.New commits must use 'nokprobe' for this purpose.
Signed-off-by Masami Hiramatsu <[email protected]>Cc Ingo Molnar <[email protected]>Cc Ananth N Mavinakayanahalli <[email protected]>Cc "David S. Miller" <[email protected]>--- include/linux/compiler.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)include/linux/compiler.h +0
-0include/linux/compiler.h void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect); · line 356
Quoted 5 lines
include/linux/compiler.h +1
-1@@ -353,8 +353,10 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);/* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */ #ifdef CONFIG_KPROBES -# define __kprobes __attribute__((__section__(".kprobes.text"))) +# define nokprobe __attribute__((__section__(".kprobes.text")))I wonder if we should have both a
__kprobesand nokprobe annotation, such that we have:
Quoted 5 lines
# define __kprobes __attribute__((__section__(".kprobes.text"))) # define nokprobe __attribute__((__section__(".nokprobes.text")))Then use
__kprobesfor the actual kprobes code, and nokprobe for all the places that must not be traced by kprobes.
No, actually, we don't need __kprobes anymore. That has started historically by misunderstanding the problem. kprobes is using the .kprobes.text only for blacklisting the non probe-able functions. Thus, eventually it should be renamed .nokprobe.text, not be added.
Quoted 1 line
It just seems strange to me grouping kprobes code with non kprobes code.
Yeah, so I'd like to cleanup all the __kprobes finally (and classify which is not needed).
Thank you,
Signature · 4 lines
Masami HIRAMATSU IT Management Research Dept. Linux Technology Center Hitachi, Ltd., Yokohama Research Laboratory E-mail: [email protected]
PATCH v2 2/3 kprobes/x86: Prohibit probing on debug_stack_*
In reply to Masami HiramatsuProhibit 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.
--- arch/x86/kernel/cpu/common.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/common.c +3 -3
@@ -1157,7 +1157,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 nokprobe is_debug_stack(unsigned long addr) { return __get_cpu_var(debug_stack_usage) || (addr <= __get_cpu_var(debug_stack_addr) &&
@@ -1166,13 +1166,13 @@ int is_debug_stack(unsigned long addr)DEFINE_PER_CPU (u32, debug_idt_ctr); -void debug_stack_set_zero (void ) +void nokprobe debug_stack_set_zero(void) {this_cpu_inc (debug_idt_ctr);load_current_idt (); } -void debug_stack_reset (void ) +void nokprobe debug_stack_reset(void) {if (WARN_ON (!this_cpu_read (debug_idt_ctr)))return ;
Re: [PATCH -tip v2 2/3] [BUGFIX] kprobes/x86: Prohibit probing on debug_stack_*
Quoted 8 lines · On Fri, 01 Nov 2013 11:25:34 +0000 Masami Hiramatsu…
Prohibit probing on
debug_stack_resetanddebug_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=yandCONFIG_TRACE_IRQFLAGS=y.
Quoted 8 lines
Signed-off-by Masami Hiramatsu <[email protected]>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]>---
-- Steve
PATCH v2 3/3 kprobes: Prohibit probing on func_ptr_is_kernel_text
In reply to Masami HiramatsuProhibit 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.
--- kernel/extable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/extable.c +1 -1
@@ -129,7 +129,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 nokprobe func_ptr_is_kernel_text(void *ptr) {unsigned long addr; addr = (unsigned long )dereference_function_descriptor (ptr);
Re: [PATCH -tip v2 3/3] [BUGFIX] kprobes: Prohibit probing on func_ptr_is_kernel_text
Quoted 7 lines · On Fri, 01 Nov 2013 11:25:37 +0000 Masami Hiramatsu…
Prohibit probing on
func_ptr_is_kernel_text(). Since thefunc_ptr_is_kernel_text()is called fromnotifier_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.
-- Steve
Quoted 24 lines
Signed-off-by Masami Hiramatsu <[email protected]>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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/extable.c +1
-1@@ -129,7 +129,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 nokprobe func_ptr_is_kernel_text(void *ptr) {unsigned long addr; addr = (unsigned long )dereference_function_descriptor (ptr);
Re: [PATCH -tip v2 3/3] [BUGFIX] kprobes: Prohibit probing on func_ptr_is_kernel_text
In reply to Masami HiramatsuQuoted 23 lines · On Fri, 01 Nov 2013 11:25:37 +0000 Masami Hiramatsu…
Prohibit probing on
func_ptr_is_kernel_text(). Since thefunc_ptr_is_kernel_text()is called fromnotifier_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.Signed-off-by Masami Hiramatsu <[email protected]>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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/extable.c +0
-0
kernel/extable.c int kernel_text_address(unsigned long addr) · line 135
Quoted 8 lines
kernel/extable.c +1
-1@@ -129,7 +129,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 nokprobe func_ptr_is_kernel_text(void *ptr) {unsigned long addr; addr = (unsigned long )dereference_function_descriptor (ptr);
One thing I worry about the "nokprobe" annotation, is that it moves the location of the function out of local. This function no exists in the section with its users. Same with the debug functions in the other patch.
Now these may be a slow path where we really don't care, but if the nokprobe expands this can cause issues.
The "nokprobe" works differently than "notrace" as "notrace" is just an attribute that tells gcc not to add mcount to it. The "nokprobe" actually moves the function into a different section.
-- Steve
Re: [PATCH -tip v2 3/3] [BUGFIX] kprobes: Prohibit probing on func_ptr_is_kernel_text
Quoted 40 lines · Steven Rostedt
Quoted 23 lines · On Fri, 01 Nov 2013 11:25:37 +0000 Masami Hiramatsu…
Prohibit probing on
func_ptr_is_kernel_text(). Since thefunc_ptr_is_kernel_text()is called fromnotifier_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.Signed-off-by Masami Hiramatsu <[email protected]>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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/extable.c +0
-0kernel/extable.c int kernel_text_address(unsigned long addr) · line 135
Quoted 8 lines
kernel/extable.c +1
-1@@ -129,7 +129,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 nokprobe func_ptr_is_kernel_text(void *ptr) {unsigned long addr; addr = (unsigned long )dereference_function_descriptor (ptr);One thing I worry about the "nokprobe" annotation, is that it moves the location of the function out of local. This function no exists in the section with its users. Same with the debug functions in the other patch.
Quoted 6 lines
Now these may be a slow path where we really don't care, but if the nokprobe expands this can cause issues.
The "nokprobe" works differently than "notrace" as "notrace" is just an attribute that tells gcc not to add mcount to it. The "nokprobe" actually moves the function into a different section.
Well, in that case, I can put it in the opt-out type blacklist(kprobe_blacklist). :) Hmm, I think if I can list nokprobe functions up at build time, we can almost remove the .kprobes.text (Note that some of entry functions in asm still require it.)
Thank you,
Signature · 4 lines
Masami HIRAMATSU IT Management Research Dept. Linux Technology Center Hitachi, Ltd., Yokohama Research Laboratory E-mail: [email protected]
Re: [PATCH -tip v2 3/3] [BUGFIX] kprobes: Prohibit probing on func_ptr_is_kernel_text
In reply to Steven RostedtQuoted 31 lines · Steven Rostedt
Quoted 28 lines · On Fri, 01 Nov 2013 11:25:37 +0000 Masami Hiramatsu…
Prohibit probing on
func_ptr_is_kernel_text(). Since thefunc_ptr_is_kernel_text()is called fromnotifier_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.Signed-off-by Masami Hiramatsu <[email protected]>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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/extable.c +1
-1@@ -129,7 +129,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 nokprobe func_ptr_is_kernel_text(void *ptr) {
Quoted 8 lines
kernel/extable.c int kernel_text_address(unsigned long addr) · line 135
Quoted 3 lines
kernel/extable.c +0
-0unsigned long addr; addr = (unsigned long )dereference_function_descriptor (ptr);One thing I worry about the "nokprobe" annotation, is that it moves the location of the function out of local. This function no exists in the section with its users. Same with the debug functions in the other patch.
Well, it's a bit like noinline, that changes the position of the function as well. So it's not true that 'noxyz' attributes don't affect function placement - they often don't, but some do.
The more important aspect is that 'noprobe' makes it really, really apparent what the tag is about, at first sight.
_How_ the 'non probing' is achived is an implementational detail when kprobes are enabled: right now it puts a function into a separate section, but we could just a much build a list of function names and check against it at probe insertion time.
Thanks,
Ingo
Re: [PATCH -tip v2 3/3] [BUGFIX] kprobes: Prohibit probing on func_ptr_is_kernel_text
Quoted 47 lines · Ingo Molnar
Quoted 31 lines · Steven Rostedt
Quoted 28 lines · On Fri, 01 Nov 2013 11:25:37 +0000 Masami Hiramatsu…
Prohibit probing on
func_ptr_is_kernel_text(). Since thefunc_ptr_is_kernel_text()is called fromnotifier_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.Signed-off-by Masami Hiramatsu <[email protected]>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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/extable.c +1
-1@@ -129,7 +129,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 nokprobe func_ptr_is_kernel_text(void *ptr) {Quoted 8 lines
kernel/extable.c int kernel_text_address(unsigned long addr) · line 135
Quoted 3 lines
kernel/extable.c +0
-0unsigned long addr; addr = (unsigned long )dereference_function_descriptor (ptr);One thing I worry about the "nokprobe" annotation, is that it moves the location of the function out of local. This function no exists in the section with its users. Same with the debug functions in the other patch.
Well, it's a bit like noinline, that changes the position of the function as well. So it's not true that 'noxyz' attributes don't affect function placement - they often don't, but some do.
Quoted 7 lines
The more important aspect is that 'noprobe' makes it really, really apparent what the tag is about, at first sight.
_How_ the 'non probing' is achived is an implementational detail when kprobes are enabled: right now it puts a function into a separate section, but we could just a much build a list of function names and check against it at probe insertion time.
Actually, kprobes already has it -- kprobes_blacklist. Currently the list is manually maintained in kprobes.c separated from the function definition. I hope to build the list when the kernel build time if possible... Would you have any idea to classify some annotated(but no side-effect) functions?
Thank you,
Signature · 4 lines
Masami HIRAMATSU IT Management Research Dept. Linux Technology Center Hitachi, Ltd., Yokohama Research Laboratory E-mail: [email protected]
Re: [PATCH -tip v2 3/3] [BUGFIX] kprobes: Prohibit probing on func_ptr_is_kernel_text
Quoted 51 lines · Masami Hiramatsu
Quoted 50 lines · Ingo Molnar
Quoted 31 lines · Steven Rostedt
Quoted 28 lines · On Fri, 01 Nov 2013 11:25:37 +0000 Masami Hiramatsu…
Prohibit probing on
func_ptr_is_kernel_text(). Since thefunc_ptr_is_kernel_text()is called fromnotifier_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.Signed-off-by Masami Hiramatsu <[email protected]>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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/extable.c +1
-1@@ -129,7 +129,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 nokprobe func_ptr_is_kernel_text(void *ptr) {Quoted 8 lines
kernel/extable.c int kernel_text_address(unsigned long addr) · line 135
Quoted 3 lines
kernel/extable.c +0
-0unsigned long addr; addr = (unsigned long )dereference_function_descriptor (ptr);One thing I worry about the "nokprobe" annotation, is that it moves the location of the function out of local. This function no exists in the section with its users. Same with the debug functions in the other patch.
Well, it's a bit like noinline, that changes the position of the function as well. So it's not true that 'noxyz' attributes don't affect function placement - they often don't, but some do.
The more important aspect is that 'noprobe' makes it really, really apparent what the tag is about, at first sight.
Quoted 8 lines
Quoted 4 lines
_How_ the 'non probing' is achived is an implementational detail when kprobes are enabled: right now it puts a function into a separate section, but we could just a much build a list of function names and check against it at probe insertion time.
Actually, kprobes already has it --
kprobes_blacklist. Currently the list is manually maintained inkprobes.cseparated from the function definition. [...]
Yes, I meant a list that is built automatically from the 'noprobe' annotations.
Quoted 3 lines
[...] I hope to build the list when the kernel build time if possible... Would you have any idea to classify some annotated(but no side-effect) functions?
The macro magic I can think of would need to change the syntax of the function definition - for example that is how the SYSCALL_DEFINE*() macros work.
It would be nice if there was a GCC extension that marked a function noinline and allowed the emitting of the function's address (and size) into a special section - but I'm not aware of any such compiler feature today.
Thanks,
Ingo
Re: [PATCH -tip v2 3/3] [BUGFIX] kprobes: Prohibit probing on func_ptr_is_kernel_text
Quoted 59 lines · Ingo Molnar
Quoted 56 lines · Masami Hiramatsu
Quoted 54 lines · Ingo Molnar
Quoted 31 lines · Steven Rostedt
Quoted 28 lines · On Fri, 01 Nov 2013 11:25:37 +0000 Masami Hiramatsu…
Prohibit probing on
func_ptr_is_kernel_text(). Since thefunc_ptr_is_kernel_text()is called fromnotifier_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.Signed-off-by Masami Hiramatsu <[email protected]>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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/extable.c +1
-1@@ -129,7 +129,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 nokprobe func_ptr_is_kernel_text(void *ptr) {Quoted 8 lines
kernel/extable.c int kernel_text_address(unsigned long addr) · line 135
Quoted 3 lines
kernel/extable.c +0
-0unsigned long addr; addr = (unsigned long )dereference_function_descriptor (ptr);One thing I worry about the "nokprobe" annotation, is that it moves the location of the function out of local. This function no exists in the section with its users. Same with the debug functions in the other patch.
Well, it's a bit like noinline, that changes the position of the function as well. So it's not true that 'noxyz' attributes don't affect function placement - they often don't, but some do.
The more important aspect is that 'noprobe' makes it really, really apparent what the tag is about, at first sight.
_How_ the 'non probing' is achived is an implementational detail when kprobes are enabled: right now it puts a function into a separate section, but we could just a much build a list of function names and check against it at probe insertion time.
Quoted 6 lines
Quoted 3 lines
Actually, kprobes already has it --
kprobes_blacklist. Currently the list is manually maintained inkprobes.cseparated from the function definition. [...]Yes, I meant a list that is built automatically from the 'noprobe' annotations.
Agreed. That makes maintenance work simple, and we can remove ".kprobes.text" section.
Quoted 7 lines
Quoted 3 lines
[...] I hope to build the list when the kernel build time if possible... Would you have any idea to classify some annotated(but no side-effect) functions?
The macro magic I can think of would need to change the syntax of the function definition - for example that is how the SYSCALL_DEFINE*() macros work.
Would you mean something like the below macro? :)
NOKPROBE_SYMBOL(int, func_ptr_is_kernel_text)(void *ptr)
which is expanded as;
static struct nokprobe_entry __used __nokprobe_entry_func_ptr_is_kernel_text = {
.name = "func_ptr_is_kernel_text"
};
static struct kprobe_blacklist_entry __used __attribute__((section("_nokprobe_list"))) __p_nokprobe_entry_func_ptr_is_kernel_text = &__nokprobe_entry_func_ptr_is_kernel_text; int func_ptr_is_kernel_text(void *ptr)
Hmm, this looks worth to try.
Thank you,
Signature · 4 lines
Masami HIRAMATSU IT Management Research Dept. Linux Technology Center Hitachi, Ltd., Yokohama Research Laboratory E-mail: [email protected]
Re: [PATCH -tip v2 3/3] [BUGFIX] kprobes: Prohibit probing on func_ptr_is_kernel_text
Quoted 84 lines · Masami Hiramatsu
Quoted 59 lines · Ingo Molnar
Quoted 56 lines · Masami Hiramatsu
Quoted 54 lines · Ingo Molnar
Quoted 31 lines · Steven Rostedt
Quoted 28 lines · On Fri, 01 Nov 2013 11:25:37 +0000 Masami Hiramatsu…
Prohibit probing on
func_ptr_is_kernel_text(). Since thefunc_ptr_is_kernel_text()is called fromnotifier_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.Signed-off-by Masami Hiramatsu <[email protected]>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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/extable.c +1
-1@@ -129,7 +129,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 nokprobe func_ptr_is_kernel_text(void *ptr) {Quoted 8 lines
kernel/extable.c int kernel_text_address(unsigned long addr) · line 135
Quoted 3 lines
kernel/extable.c +0
-0unsigned long addr; addr = (unsigned long )dereference_function_descriptor (ptr);One thing I worry about the "nokprobe" annotation, is that it moves the location of the function out of local. This function no exists in the section with its users. Same with the debug functions in the other patch.
Well, it's a bit like noinline, that changes the position of the function as well. So it's not true that 'noxyz' attributes don't affect function placement - they often don't, but some do.
The more important aspect is that 'noprobe' makes it really, really apparent what the tag is about, at first sight.
_How_ the 'non probing' is achived is an implementational detail when kprobes are enabled: right now it puts a function into a separate section, but we could just a much build a list of function names and check against it at probe insertion time.
Quoted 6 lines
Quoted 3 lines
Actually, kprobes already has it --
kprobes_blacklist. Currently the list is manually maintained inkprobes.cseparated from the function definition. [...]Yes, I meant a list that is built automatically from the 'noprobe' annotations.
Agreed. That makes maintenance work simple, and we can remove ".kprobes.text" section.
Quoted 7 lines
Quoted 3 lines
[...] I hope to build the list when the kernel build time if possible... Would you have any idea to classify some annotated(but no side-effect) functions?
The macro magic I can think of would need to change the syntax of the function definition - for example that is how the SYSCALL_DEFINE*() macros work.
Would you mean something like the below macro? :)
NOKPROBE_SYMBOL(int, func_ptr_is_kernel_text)(void *ptr)which is expanded as;
Quoted 9 lines
static struct
nokprobe_entry__used__nokprobe_entry_func_ptr_is_kernel_text= {
.name = "func_ptr_is_kernel_text"
};
static structkprobe_blacklist_entry__used__attribute__((section("_nokprobe_list")))__p_nokprobe_entry_func_ptr_is_kernel_text=&__nokprobe_entry_func_ptr_is_kernel_text; intfunc_ptr_is_kernel_text(void *ptr)
By the way, this method can be done in C file, but not in asm file. And there are many sensitive entries in the entry_*.S. I think we have two options.
(A) keep the kprobes.text(or nokprobe.text) section for such assembler parts.
(B) Put a starter symbol and end symbol in such region and make a list of symbols between them in build time by using nm.
Anyway, until removing all __kprobes from kernel, we can not remove the kprobes.text section. So, at the first step I just try to introduce above macro and apply it to only the symbols in kprobes_blacklist. After that, I'll try to classify the real unsafe entries and apply the new macro. Eventually, I think I can remove all __kprobes.
Thank you,
Signature · 4 lines
Masami HIRAMATSU IT Management Research Dept. Linux Technology Center Hitachi, Ltd., Yokohama Research Laboratory E-mail: [email protected]
Re: [PATCH -tip v2 3/3] [BUGFIX] kprobes: Prohibit probing on func_ptr_is_kernel_text
In reply to Masami HiramatsuQuoted 11 lines · Masami Hiramatsu
Quoted 7 lines
Quoted 3 lines
[...] I hope to build the list when the kernel build time if possible... Would you have any idea to classify some annotated(but no side-effect) functions?
The macro magic I can think of would need to change the syntax of the function definition - for example that is how the SYSCALL_DEFINE*() macros work.
Would you mean something like the below macro? :)
NOKPROBE_SYMBOL(int, func_ptr_is_kernel_text)(void *ptr)
I think this is rather ugly and harder to maintain. The whole _point_ of such annotations is to make them 'easy on the eyes', to make it easy to skip a 'noinline', 'noprobe' or 'notrace' tag.
Using something like NOKPROBE_SYMBOL() makes the whole construct ugly and attention seeking.
So until compilers get smarter (or there's some compiler trick I haven't noticed) lets stay with the separate section - it's not the end of the world, the (effective) 'noinline' aspect of noprobes changes code generation anyway.
Thanks,
Ingo
Re: [PATCH -tip v2 3/3] [BUGFIX] kprobes: Prohibit probing on func_ptr_is_kernel_text
Quoted 13 lines · Ingo Molnar
Quoted 10 lines · Masami Hiramatsu
Quoted 7 lines
Quoted 3 lines
[...] I hope to build the list when the kernel build time if possible... Would you have any idea to classify some annotated(but no side-effect) functions?
The macro magic I can think of would need to change the syntax of the function definition - for example that is how the SYSCALL_DEFINE*() macros work.
Would you mean something like the below macro? :)
Quoted 8 lines
Quoted 1 line
NOKPROBE_SYMBOL(int, func_ptr_is_kernel_text)(void *ptr)I think this is rather ugly and harder to maintain. The whole _point_ of such annotations is to make them 'easy on the eyes', to make it easy to skip a 'noinline', 'noprobe' or 'notrace' tag.
Using something like
NOKPROBE_SYMBOL()makes the whole construct ugly and attention seeking.
Hmm, by the way how about Steven's idea? A macro like EXPORT_SYMBOL? At least for kprobes_blacklist, which is defined/maintained in kprobes.c for some symbols(*), that is useful for updating it because we can put it near the function definition.
* These symbols can not moves to other section because it already in a different section.
Of course, still this is not a big problem since there are a few symbols in the kprobe_blacklist.
Quoted 4 lines
So until compilers get smarter (or there's some compiler trick I haven't noticed) lets stay with the separate section - it's not the end of the world, the (effective) 'noinline' aspect of noprobes changes code generation anyway.
I see. :)
So, would you pull this series ? Or I need any update?
Thank you,
Signature · 4 lines
Masami HIRAMATSU IT Management Research Dept. Linux Technology Center Hitachi, Ltd., Yokohama Research Laboratory E-mail: [email protected]
Re: [PATCH -tip v2 3/3] [BUGFIX] kprobes: Prohibit probing on func_ptr_is_kernel_text
Quoted 20 lines · Masami Hiramatsu
Quoted 19 lines · Ingo Molnar
Quoted 11 lines · Masami Hiramatsu
Quoted 7 lines
Quoted 3 lines
[...] I hope to build the list when the kernel build time if possible... Would you have any idea to classify some annotated(but no side-effect) functions?
The macro magic I can think of would need to change the syntax of the function definition - for example that is how the SYSCALL_DEFINE*() macros work.
Would you mean something like the below macro? :)
NOKPROBE_SYMBOL(int, func_ptr_is_kernel_text)(void *ptr)I think this is rather ugly and harder to maintain. The whole _point_ of such annotations is to make them 'easy on the eyes', to make it easy to skip a 'noinline', 'noprobe' or 'notrace' tag.
Quoted 7 lines
Quoted 2 lines
Using something like
NOKPROBE_SYMBOL()makes the whole construct ugly and attention seeking.Hmm, by the way how about Steven's idea? A macro like
EXPORT_SYMBOL? At least forkprobes_blacklist, which is defined/maintained inkprobes.cfor somesymbols(*), that is useful for updating it because we can put it near the function definition.
Dunno, it feels a bit fragile to me.
Thanks,
Ingo
Re: [PATCH -tip v2 3/3] [BUGFIX] kprobes: Prohibit probing on func_ptr_is_kernel_text
In reply to Ingo MolnarQuoted 5 lines · On Wed, 6 Nov 2013 07:07:37 +0100 Ingo Molnar <[email protected]> wrote:
So until compilers get smarter (or there's some compiler trick I haven't noticed) lets stay with the separate section - it's not the end of the world, the (effective) 'noinline' aspect of noprobes changes code generation anyway.
It's fine now. I just wanted everyone to be ware if this annotation starts to get used a bit more, that it can cause unwanted side effects.
-- Steve
Re: [PATCH -tip v2 3/3] [BUGFIX] kprobes: Prohibit probing on func_ptr_is_kernel_text
In reply to Ingo MolnarQuoted 3 lines · On Tue, 5 Nov 2013 08:05:37 +0100 Ingo Molnar <[email protected]> wrote:
The macro magic I can think of would need to change the syntax of the function definition - for example that is how the SYSCALL_DEFINE*() macros work.
Or something like the EXPORT_SYMBOL(), but that wouldn't include the size of the function. But using the name we could use kallsyms to see if a probe is placed in a function that is blacklisted. Not very pretty to do though.
Quoted 5 lines
It would be nice if there was a GCC extension that marked a function noinline and allowed the emitting of the function's address (and size) into a special section - but I'm not aware of any such compiler feature today.
Yeah, I was wishing the same thing. Maybe I'll try to talk with the gcc folks about adding such a feature. Something like
void __attribute__((save_loc_and_size(".section"))) function(void) {
}
-- Steve