Message ID | 162399994018.506599.10332627573727646767.stgit@devnote2 (mailing list archive) |
---|---|
State | Not Applicable |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | kprobes: Fix stacktrace with kretprobes on x86 | expand |
Context | Check | Description |
---|---|---|
netdev/tree_selection | success | Not a local patch |
* Masami Hiramatsu <mhiramat@kernel.org> wrote: > Replace arch_deref_entry_point() with dereference_symbol_descriptor() > because those are doing same thing. > > Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> > Tested-by: Andrii Nakryik <andrii@kernel.org> A better changelog: ~15 years ago kprobes grew the 'arch_deref_entry_point()' __weak function: 3d7e33825d87: ("jprobes: make jprobes a little safer for users") But this is just open-coded dereference_symbol_descriptor() in essence, and its obscure nature was causing bugs. Just use the real thing. Thanks, Ingo
On Mon, 5 Jul 2021 09:48:09 +0200 Ingo Molnar <mingo@kernel.org> wrote: > > * Masami Hiramatsu <mhiramat@kernel.org> wrote: > > > Replace arch_deref_entry_point() with dereference_symbol_descriptor() > > because those are doing same thing. > > > > Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> > > Tested-by: Andrii Nakryik <andrii@kernel.org> > > A better changelog: > > ~15 years ago kprobes grew the 'arch_deref_entry_point()' __weak function: > > 3d7e33825d87: ("jprobes: make jprobes a little safer for users") > > But this is just open-coded dereference_symbol_descriptor() in essence, and > its obscure nature was causing bugs. > > Just use the real thing. OK. BTW, I couldn't find actual bugs from it. What about this? "its obscure nature was causing problems in the past." Thank you, > > Thanks, > > Ingo
On Fri, Jun 18, 2021 at 12:05 AM Masami Hiramatsu <mhiramat@kernel.org> wrote: > > Replace arch_deref_entry_point() with dereference_symbol_descriptor() > because those are doing same thing. > > Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> > Tested-by: Andrii Nakryik <andrii@kernel.org> Hi Masami, If you are going to post v9 anyway, can you please fix up my name, it should be "Andrii Nakryiko", thanks! > --- > Changes in v6: > - Use dereference_symbol_descriptor() so that it can handle address in > modules correctly. > --- > arch/ia64/kernel/kprobes.c | 5 ----- > arch/powerpc/kernel/kprobes.c | 11 ----------- > include/linux/kprobes.h | 1 - > kernel/kprobes.c | 7 +------ > lib/error-inject.c | 3 ++- > 5 files changed, 3 insertions(+), 24 deletions(-) > [...]
On Wed, 7 Jul 2021 11:28:10 -0700 Andrii Nakryiko <andrii.nakryiko@gmail.com> wrote: > On Fri, Jun 18, 2021 at 12:05 AM Masami Hiramatsu <mhiramat@kernel.org> wrote: > > > > Replace arch_deref_entry_point() with dereference_symbol_descriptor() > > because those are doing same thing. > > > > Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> > > Tested-by: Andrii Nakryik <andrii@kernel.org> > > Hi Masami, > > If you are going to post v9 anyway, can you please fix up my name, it > should be "Andrii Nakryiko", thanks! Oops, sorry. OK, I'll fix it. Thank you, > > > --- > > Changes in v6: > > - Use dereference_symbol_descriptor() so that it can handle address in > > modules correctly. > > --- > > arch/ia64/kernel/kprobes.c | 5 ----- > > arch/powerpc/kernel/kprobes.c | 11 ----------- > > include/linux/kprobes.h | 1 - > > kernel/kprobes.c | 7 +------ > > lib/error-inject.c | 3 ++- > > 5 files changed, 3 insertions(+), 24 deletions(-) > > > > [...]
diff --git a/arch/ia64/kernel/kprobes.c b/arch/ia64/kernel/kprobes.c index d4048518a1d7..0f8573bbf520 100644 --- a/arch/ia64/kernel/kprobes.c +++ b/arch/ia64/kernel/kprobes.c @@ -891,11 +891,6 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self, return ret; } -unsigned long arch_deref_entry_point(void *entry) -{ - return ((struct fnptr *)entry)->ip; -} - static struct kprobe trampoline_p = { .pre_handler = trampoline_probe_handler }; diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c index c64a5feaebbe..24472f2c2cfc 100644 --- a/arch/powerpc/kernel/kprobes.c +++ b/arch/powerpc/kernel/kprobes.c @@ -522,17 +522,6 @@ int kprobe_fault_handler(struct pt_regs *regs, int trapnr) } NOKPROBE_SYMBOL(kprobe_fault_handler); -unsigned long arch_deref_entry_point(void *entry) -{ -#ifdef PPC64_ELF_ABI_v1 - if (!kernel_text_address((unsigned long)entry)) - return ppc_global_function_entry(entry); - else -#endif - return (unsigned long)entry; -} -NOKPROBE_SYMBOL(arch_deref_entry_point); - static struct kprobe trampoline_p = { .addr = (kprobe_opcode_t *) &kretprobe_trampoline, .pre_handler = trampoline_probe_handler diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h index 523ffc7bc3a8..713c3a683011 100644 --- a/include/linux/kprobes.h +++ b/include/linux/kprobes.h @@ -382,7 +382,6 @@ int register_kprobe(struct kprobe *p); void unregister_kprobe(struct kprobe *p); int register_kprobes(struct kprobe **kps, int num); void unregister_kprobes(struct kprobe **kps, int num); -unsigned long arch_deref_entry_point(void *); int register_kretprobe(struct kretprobe *rp); void unregister_kretprobe(struct kretprobe *rp); diff --git a/kernel/kprobes.c b/kernel/kprobes.c index e41385afe79d..f8fe9d077b41 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -1838,11 +1838,6 @@ static struct notifier_block kprobe_exceptions_nb = { .priority = 0x7fffffff /* we need to be notified first */ }; -unsigned long __weak arch_deref_entry_point(void *entry) -{ - return (unsigned long)entry; -} - #ifdef CONFIG_KRETPROBES unsigned long __kretprobe_trampoline_handler(struct pt_regs *regs, @@ -2305,7 +2300,7 @@ static int __init populate_kprobe_blacklist(unsigned long *start, int ret; for (iter = start; iter < end; iter++) { - entry = arch_deref_entry_point((void *)*iter); + entry = (unsigned long)dereference_symbol_descriptor((void *)*iter); ret = kprobe_add_ksym_blacklist(entry); if (ret == -EINVAL) continue; diff --git a/lib/error-inject.c b/lib/error-inject.c index c73651b15b76..2ff5ef689d72 100644 --- a/lib/error-inject.c +++ b/lib/error-inject.c @@ -8,6 +8,7 @@ #include <linux/mutex.h> #include <linux/list.h> #include <linux/slab.h> +#include <asm/sections.h> /* Whitelist of symbols that can be overridden for error injection. */ static LIST_HEAD(error_injection_list); @@ -64,7 +65,7 @@ static void populate_error_injection_list(struct error_injection_entry *start, mutex_lock(&ei_mutex); for (iter = start; iter < end; iter++) { - entry = arch_deref_entry_point((void *)iter->addr); + entry = (unsigned long)dereference_symbol_descriptor((void *)iter->addr); if (!kernel_text_address(entry) || !kallsyms_lookup_size_offset(entry, &size, &offset)) {