Skip to contentSkip to conversation

tracing/kprobes: Fix symbol counting logic by looking at modules as well

PATCH In review Markus Boehme 2 participants 4 messages Jan 11, 2024 – Jan 13, 2024 Stable branch

lore
Share & tools
lore
#0 lore raw

cover tracing/kprobes: Fix symbol counting logic by looking at modules as well

This backports the fix to the kprobe_events interface allowing to create kprobes on symbols defined in loadable modules again. The backport is simpler than ones for later kernels, since the backport of the commit introducing the bug already brought along much of the code needed to fix it.

Andrii Nakryiko (1):
tracing/kprobes: Fix symbol counting logic by looking at modules as
well

Jiri Olsa (1):
kallsyms: Make module_kallsyms_on_each_symbol generally available

 include/linux/module.h      | 9 +++++++++
 kernel/module.c             | 2 --
 kernel/trace/trace_kprobe.c | 2 ++
 3 files changed, 11 insertions(+), 2 deletions(-)
Signature · 1 line
2.40.1
#1 lore raw

PATCH 1/2 kallsyms: Make module_kallsyms_on_each_symbol generally available

From: Jiri Olsa <[email protected]>

commit 73feb8d5fa3b755bb51077c0aabfb6aa556fd498 upstream.

Making module_kallsyms_on_each_symbol generally available, so it can be used outside CONFIG_LIVEPATCH option in following changes.

Rather than adding another ifdef option let's make the function generally available (when CONFIG_KALLSYMS and CONFIG_MODULES options are defined).

Stable-dep-of: 926fe783c8a6 ("tracing/kprobes: Fix symbol counting logic by looking at modules as well")

---
 include/linux/module.h | 9 +++++++++
 kernel/module.c        | 2 --
 2 files changed, 9 insertions(+), 2 deletions(-)
include/linux/module.h +9 -0
index c9f1200b2312..701c150485b2 100644
@@ -867,8 +867,17 @@ static inline bool module_sig_ok(struct module *module)
 }
 #endif	/* CONFIG_MODULE_SIG */
 
+#if defined(CONFIG_MODULES) && defined(CONFIG_KALLSYMS)
 int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
 					     struct module *, unsigned long),
 				   void *data);
+#else
+static inline int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
+						 struct module *, unsigned long),
+						 void *data)
+{
+	return -EOPNOTSUPP;
+}
+#endif  /* CONFIG_MODULES && CONFIG_KALLSYMS */
 
 #endif /* _LINUX_MODULE_H */
kernel/module.c +0 -2
index 3c90840133c0..ba9f2bb57889 100644
@@ -4482,7 +4482,6 @@ unsigned long module_kallsyms_lookup_name(const char *name)
 	return ret;
 }
 
-#ifdef CONFIG_LIVEPATCH
 int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
 					     struct module *, unsigned long),
 				   void *data)
@@ -4514,7 +4513,6 @@ int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
 	mutex_unlock(&module_mutex);
 	return ret;
 }
-#endif /* CONFIG_LIVEPATCH */
 #endif /* CONFIG_KALLSYMS */
 
 static void cfi_init(struct module *mod)
Signature · 1 line
2.40.1
#2 lore raw

PATCH 2/2 tracing/kprobes: Fix symbol counting logic by looking at modules as well

In reply to Markus Boehme

From: Andrii Nakryiko <[email protected]>

commit 926fe783c8a64b33997fec405cf1af3e61aed441 upstream.

Recent changes to count number of matching symbols when creating a kprobe event failed to take into account kernel modules. As such, it breaks kprobes on kernel module symbols, by assuming there is no match.

Fix this my calling module_kallsyms_on_each_symbol() in addition to kallsyms_on_each_match_symbol() to perform a proper counting.

Cc Francis Laniel <[email protected]>
Cc Masami Hiramatsu <[email protected]>
Cc Steven Rostedt <[email protected]>
Fixes b022f0c7e404 ("tracing/kprobes: Return EADDRNOTAVAIL when func matches several symbols")
---
 kernel/trace/trace_kprobe.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/trace/trace_kprobe.c +2 -0
index 1c565db2de7b..21aef22a8489 100644
@@ -735,6 +735,8 @@ static unsigned int number_of_same_symbols(char *func_name)
 
 	kallsyms_on_each_symbol(count_symbols, &args);
 
+	module_kallsyms_on_each_symbol(count_symbols, &args);
+
 	return args.count;
 }
 
Signature · 1 line
2.40.1
#3 lore raw
In reply to Markus Boehme
Quoted 10 lines · Markus Boehme

This backports the fix to the kprobe_events interface allowing to create kprobes on symbols defined in loadable modules again. The backport is simpler than ones for later kernels, since the backport of the commit introducing the bug already brought along much of the code needed to fix it.

Andrii Nakryiko (1):
tracing/kprobes: Fix symbol counting logic by looking at modules as
well

Quoted 12 lines

Jiri Olsa (1):
kallsyms: Make module_kallsyms_on_each_symbol generally available

 include/linux/module.h      | 9 +++++++++
 kernel/module.c             | 2 --
 kernel/trace/trace_kprobe.c | 2 ++
 3 files changed, 11 insertions(+), 2 deletions(-)
Signature · 1 line
2.40.1

Now queued up, thanks.

greg k-h