* [PATCH] kprobes: Mark ftrace mcount handler functions nokprobe
@ 2022-09-19 8:45 Liao Chang
2022-09-26 18:37 ` Steven Rostedt
0 siblings, 1 reply; 4+ messages in thread
From: Liao Chang @ 2022-09-19 8:45 UTC (permalink / raw)
To: rostedt, mingo, paul.walmsley, palmer, aou; +Cc: linux-kernel, linux-riscv
Mark ftrace mcount handler functions nokprobe since probing on these
functions probably reaches mcount recursivly during kprobe breakpoint
handler for some architecture(tested for riscv, arm64), and reenter
kprobe is treated as a fatal error, causes kernel panic.
Pesudo code below demonstrate this problem:
mcount
function_trace_call (probed)
arch_breakpoint_handler
arch_setup_singlestep [mcount]
function_trace_call (probed)
arch_breakpoint_handler
reenter_kprobe
BUG
Signed-off-by: Liao Chang <liaochang1@huawei.com>
---
kernel/trace/trace_functions.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c
index 9f1bfbe105e8..440a678a8c7c 100644
--- a/kernel/trace/trace_functions.c
+++ b/kernel/trace/trace_functions.c
@@ -16,6 +16,7 @@
#include <linux/ftrace.h>
#include <linux/slab.h>
#include <linux/fs.h>
+#include <linux/kprobes.h>
#include "trace.h"
@@ -194,6 +195,7 @@ function_trace_call(unsigned long ip, unsigned long parent_ip,
ftrace_test_recursion_unlock(bit);
}
+NOKPROBE_SYMBOL(function_trace_call);
#ifdef CONFIG_UNWINDER_ORC
/*
@@ -245,6 +247,7 @@ function_stack_trace_call(unsigned long ip, unsigned long parent_ip,
atomic_dec(&data->disabled);
local_irq_restore(flags);
}
+NOKPROBE_SYMBOL(function_stack_trace_call);
static inline bool is_repeat_check(struct trace_array *tr,
struct trace_func_repeats *last_info,
@@ -321,6 +324,7 @@ function_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip,
out:
ftrace_test_recursion_unlock(bit);
}
+NOKPROBE_SYMBOL(function_no_repeats_trace_call);
static void
function_stack_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip,
@@ -363,6 +367,7 @@ function_stack_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip,
atomic_dec(&data->disabled);
local_irq_restore(flags);
}
+NOKPROBE_SYMBOL(function_stack_no_repeats_trace_call);
static struct tracer_opt func_opts[] = {
#ifdef CONFIG_STACKTRACE
--
2.17.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] kprobes: Mark ftrace mcount handler functions nokprobe
2022-09-19 8:45 [PATCH] kprobes: Mark ftrace mcount handler functions nokprobe Liao Chang
@ 2022-09-26 18:37 ` Steven Rostedt
2022-09-27 11:10 ` liaochang (A)
2022-09-27 15:22 ` Masami Hiramatsu
0 siblings, 2 replies; 4+ messages in thread
From: Steven Rostedt @ 2022-09-26 18:37 UTC (permalink / raw)
To: Liao Chang
Cc: mingo, paul.walmsley, palmer, aou, linux-kernel, linux-riscv,
Masami Hiramatsu
On Mon, 19 Sep 2022 16:45:33 +0800
Liao Chang <liaochang1@huawei.com> wrote:
> Mark ftrace mcount handler functions nokprobe since probing on these
> functions probably reaches mcount recursivly during kprobe breakpoint
> handler for some architecture(tested for riscv, arm64), and reenter
> kprobe is treated as a fatal error, causes kernel panic.
This looks to me that the affected archs should be made more robust for this
case than to add this to the generic code.
-- Steve
>
> Pesudo code below demonstrate this problem:
>
> mcount
> function_trace_call (probed)
> arch_breakpoint_handler
> arch_setup_singlestep [mcount]
> function_trace_call (probed)
> arch_breakpoint_handler
> reenter_kprobe
> BUG
>
> Signed-off-by: Liao Chang <liaochang1@huawei.com>
> ---
> kernel/trace/trace_functions.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c
> index 9f1bfbe105e8..440a678a8c7c 100644
> --- a/kernel/trace/trace_functions.c
> +++ b/kernel/trace/trace_functions.c
> @@ -16,6 +16,7 @@
> #include <linux/ftrace.h>
> #include <linux/slab.h>
> #include <linux/fs.h>
> +#include <linux/kprobes.h>
>
> #include "trace.h"
>
> @@ -194,6 +195,7 @@ function_trace_call(unsigned long ip, unsigned long parent_ip,
>
> ftrace_test_recursion_unlock(bit);
> }
> +NOKPROBE_SYMBOL(function_trace_call);
>
> #ifdef CONFIG_UNWINDER_ORC
> /*
> @@ -245,6 +247,7 @@ function_stack_trace_call(unsigned long ip, unsigned long parent_ip,
> atomic_dec(&data->disabled);
> local_irq_restore(flags);
> }
> +NOKPROBE_SYMBOL(function_stack_trace_call);
>
> static inline bool is_repeat_check(struct trace_array *tr,
> struct trace_func_repeats *last_info,
> @@ -321,6 +324,7 @@ function_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip,
> out:
> ftrace_test_recursion_unlock(bit);
> }
> +NOKPROBE_SYMBOL(function_no_repeats_trace_call);
>
> static void
> function_stack_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip,
> @@ -363,6 +367,7 @@ function_stack_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip,
> atomic_dec(&data->disabled);
> local_irq_restore(flags);
> }
> +NOKPROBE_SYMBOL(function_stack_no_repeats_trace_call);
>
> static struct tracer_opt func_opts[] = {
> #ifdef CONFIG_STACKTRACE
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] kprobes: Mark ftrace mcount handler functions nokprobe
2022-09-26 18:37 ` Steven Rostedt
@ 2022-09-27 11:10 ` liaochang (A)
2022-09-27 15:22 ` Masami Hiramatsu
1 sibling, 0 replies; 4+ messages in thread
From: liaochang (A) @ 2022-09-27 11:10 UTC (permalink / raw)
To: Steven Rostedt
Cc: mingo, paul.walmsley, palmer, aou, linux-kernel, linux-riscv,
Masami Hiramatsu
在 2022/9/27 2:37, Steven Rostedt 写道:
> On Mon, 19 Sep 2022 16:45:33 +0800
> Liao Chang <liaochang1@huawei.com> wrote:
>
>> Mark ftrace mcount handler functions nokprobe since probing on these
>> functions probably reaches mcount recursivly during kprobe breakpoint
>> handler for some architecture(tested for riscv, arm64), and reenter
>> kprobe is treated as a fatal error, causes kernel panic.
>
> This looks to me that the affected archs should be made more robust for this
> case than to add this to the generic code.
OK, i will fix this problem in arch related code, thanks for feedback.
>
> -- Steve
>
>
>>
>> Pesudo code below demonstrate this problem:
>>
>> mcount
>> function_trace_call (probed)
>> arch_breakpoint_handler
>> arch_setup_singlestep [mcount]
>> function_trace_call (probed)
>> arch_breakpoint_handler
>> reenter_kprobe
>> BUG
>>
>> Signed-off-by: Liao Chang <liaochang1@huawei.com>
>> ---
>> kernel/trace/trace_functions.c | 5 +++++
>> 1 file changed, 5 insertions(+)
>>
>> diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c
>> index 9f1bfbe105e8..440a678a8c7c 100644
>> --- a/kernel/trace/trace_functions.c
>> +++ b/kernel/trace/trace_functions.c
>> @@ -16,6 +16,7 @@
>> #include <linux/ftrace.h>
>> #include <linux/slab.h>
>> #include <linux/fs.h>
>> +#include <linux/kprobes.h>
>>
>> #include "trace.h"
>>
>> @@ -194,6 +195,7 @@ function_trace_call(unsigned long ip, unsigned long parent_ip,
>>
>> ftrace_test_recursion_unlock(bit);
>> }
>> +NOKPROBE_SYMBOL(function_trace_call);
>>
>> #ifdef CONFIG_UNWINDER_ORC
>> /*
>> @@ -245,6 +247,7 @@ function_stack_trace_call(unsigned long ip, unsigned long parent_ip,
>> atomic_dec(&data->disabled);
>> local_irq_restore(flags);
>> }
>> +NOKPROBE_SYMBOL(function_stack_trace_call);
>>
>> static inline bool is_repeat_check(struct trace_array *tr,
>> struct trace_func_repeats *last_info,
>> @@ -321,6 +324,7 @@ function_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip,
>> out:
>> ftrace_test_recursion_unlock(bit);
>> }
>> +NOKPROBE_SYMBOL(function_no_repeats_trace_call);
>>
>> static void
>> function_stack_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip,
>> @@ -363,6 +367,7 @@ function_stack_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip,
>> atomic_dec(&data->disabled);
>> local_irq_restore(flags);
>> }
>> +NOKPROBE_SYMBOL(function_stack_no_repeats_trace_call);
>>
>> static struct tracer_opt func_opts[] = {
>> #ifdef CONFIG_STACKTRACE
>
>
> .
--
BR,
Liao, Chang
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] kprobes: Mark ftrace mcount handler functions nokprobe
2022-09-26 18:37 ` Steven Rostedt
2022-09-27 11:10 ` liaochang (A)
@ 2022-09-27 15:22 ` Masami Hiramatsu
1 sibling, 0 replies; 4+ messages in thread
From: Masami Hiramatsu @ 2022-09-27 15:22 UTC (permalink / raw)
To: Steven Rostedt
Cc: Liao Chang, mingo, paul.walmsley, palmer, aou, linux-kernel,
linux-riscv, Masami Hiramatsu
On Mon, 26 Sep 2022 14:37:23 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:
> On Mon, 19 Sep 2022 16:45:33 +0800
> Liao Chang <liaochang1@huawei.com> wrote:
>
> > Mark ftrace mcount handler functions nokprobe since probing on these
> > functions probably reaches mcount recursivly during kprobe breakpoint
> > handler for some architecture(tested for riscv, arm64), and reenter
> > kprobe is treated as a fatal error, causes kernel panic.
>
> This looks to me that the affected archs should be made more robust for this
> case than to add this to the generic code.
Yeah, kprobes (arch specific code) itself shouldn't be traced by ftrace usually.
Thank you,
>
> -- Steve
>
>
> >
> > Pesudo code below demonstrate this problem:
> >
> > mcount
> > function_trace_call (probed)
> > arch_breakpoint_handler
> > arch_setup_singlestep [mcount]
> > function_trace_call (probed)
> > arch_breakpoint_handler
> > reenter_kprobe
> > BUG
> >
> > Signed-off-by: Liao Chang <liaochang1@huawei.com>
> > ---
> > kernel/trace/trace_functions.c | 5 +++++
> > 1 file changed, 5 insertions(+)
> >
> > diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c
> > index 9f1bfbe105e8..440a678a8c7c 100644
> > --- a/kernel/trace/trace_functions.c
> > +++ b/kernel/trace/trace_functions.c
> > @@ -16,6 +16,7 @@
> > #include <linux/ftrace.h>
> > #include <linux/slab.h>
> > #include <linux/fs.h>
> > +#include <linux/kprobes.h>
> >
> > #include "trace.h"
> >
> > @@ -194,6 +195,7 @@ function_trace_call(unsigned long ip, unsigned long parent_ip,
> >
> > ftrace_test_recursion_unlock(bit);
> > }
> > +NOKPROBE_SYMBOL(function_trace_call);
> >
> > #ifdef CONFIG_UNWINDER_ORC
> > /*
> > @@ -245,6 +247,7 @@ function_stack_trace_call(unsigned long ip, unsigned long parent_ip,
> > atomic_dec(&data->disabled);
> > local_irq_restore(flags);
> > }
> > +NOKPROBE_SYMBOL(function_stack_trace_call);
> >
> > static inline bool is_repeat_check(struct trace_array *tr,
> > struct trace_func_repeats *last_info,
> > @@ -321,6 +324,7 @@ function_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip,
> > out:
> > ftrace_test_recursion_unlock(bit);
> > }
> > +NOKPROBE_SYMBOL(function_no_repeats_trace_call);
> >
> > static void
> > function_stack_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip,
> > @@ -363,6 +367,7 @@ function_stack_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip,
> > atomic_dec(&data->disabled);
> > local_irq_restore(flags);
> > }
> > +NOKPROBE_SYMBOL(function_stack_no_repeats_trace_call);
> >
> > static struct tracer_opt func_opts[] = {
> > #ifdef CONFIG_STACKTRACE
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-09-27 15:22 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-19 8:45 [PATCH] kprobes: Mark ftrace mcount handler functions nokprobe Liao Chang
2022-09-26 18:37 ` Steven Rostedt
2022-09-27 11:10 ` liaochang (A)
2022-09-27 15:22 ` Masami Hiramatsu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).