All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] perf: report/annotate: fix segfault problem.
@ 2015-04-03  5:56 Wang Nan
  2015-04-03  6:48 ` Ingo Molnar
                   ` (2 more replies)
  0 siblings, 3 replies; 26+ messages in thread
From: Wang Nan @ 2015-04-03  5:56 UTC (permalink / raw)
  To: jolsa, namhyung, jolsa, acme; +Cc: mingo, linux-kernel, pi3orama

perf report and perf annotate are easy to trigger segfault if trace data
contain kernel module information like this:

 # perf report -D -i ./perf.data
 ...
 0 0 0x188 [0x50]: PERF_RECORD_MMAP -1/0: [0xffffffbff1018000(0xf068000) @ 0]: x [test_module]
 ...

 # perf report -i ./perf.data --objdump=/path/to/objdump --kallsyms=/path/to/kallsyms

 perf: Segmentation fault
 -------- backtrace --------
 /path/to/perf[0x503478]
 /lib64/libc.so.6(+0x3545f)[0x7fb201f3745f]
 /path/to/perf[0x499b56]
 /path/to/perf(dso__load_kallsyms+0x13c)[0x49b56c]
 /path/to/perf(dso__load+0x72e)[0x49c21e]
 /path/to/perf(map__load+0x6e)[0x4ae9ee]
 /path/to/perf(thread__find_addr_map+0x24c)[0x47deec]
 /path/to/perf(perf_event__preprocess_sample+0x88)[0x47e238]
 /path/to/perf[0x43ad02]
 /path/to/perf[0x4b55bc]
 /path/to/perf(ordered_events__flush+0xca)[0x4b57ea]
 /path/to/perf[0x4b1a01]
 /path/to/perf(perf_session__process_events+0x3be)[0x4b428e]
 /path/to/perf(cmd_report+0xf11)[0x43bfc1]
 /path/to/perf[0x474702]
 /path/to/perf(main+0x5f5)[0x42de95]
 /lib64/libc.so.6(__libc_start_main+0xf4)[0x7fb201f23bd4]
 /path/to/perf[0x42dfc4]

This is because __kmod_path__parse regard '[' leading name as kernel
instead of kernel module. The DSO will then be passed to
dso__load_kernel_sym() then dso__load_kcore() because of --kallsyms
argument. The segfault is triggered because the kmap structure is not
initialized.

Although in --vmlinux case such segfault can be avoided, the symbols in
the kernel module are unable to be retrived since the attribute of DSO
is incorrect.

This patch fixes __kmod_path__parse, make it regard names like
'[test_module]' as kernel module.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
---

Patch v1 doesn't consider module named as [aaa.bbb].

---
 tools/perf/util/dso.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index fc0ddd5..08d7aaf 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -214,12 +214,23 @@ int __kmod_path__parse(struct kmod_path *m, const char *path,
 {
 	const char *name = strrchr(path, '/');
 	const char *ext  = strrchr(path, '.');
+	bool is_simple_name = false;
 
 	memset(m, 0x0, sizeof(*m));
 	name = name ? name + 1 : path;
 
+	/*
+	 * '.' is also a valid character. For example: [aaa.bbb] is a
+	 * valid module name. '[' should have higher priority than
+	 * '.ko' suffix.
+	 */
+	if ((name[0] == '[') &&	(strncmp(name, "[vdso]", 6) != 0)) {
+		m->kmod = true;
+		is_simple_name = true;
+	}
+
 	/* No extension, just return name. */
-	if (ext == NULL) {
+	if ((ext == NULL) || is_simple_name) {
 		if (alloc_name) {
 			m->name = strdup(name);
 			return m->name ? 0 : -ENOMEM;
-- 
1.8.3.4


^ permalink raw reply related	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2015-04-20  1:19 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-03  5:56 [PATCH v2] perf: report/annotate: fix segfault problem Wang Nan
2015-04-03  6:48 ` Ingo Molnar
2015-04-03  8:47   ` [PATCH] perf: kmaps: enforce usage of kmaps to protect futher bugs Wang Nan
2015-04-03  8:49     ` Ingo Molnar
2015-04-03 11:11     ` Jiri Olsa
2015-04-07 10:42       ` Adrian Hunter
2015-04-08 10:50         ` [PATCH v4] " Wang Nan
2015-04-03  9:07 ` [PATCH v2] perf: report/annotate: fix segfault problem Jiri Olsa
2015-04-03 10:57 ` Jiri Olsa
2015-04-06 12:52   ` Arnaldo Carvalho de Melo
2015-04-07  8:22     ` [PATCH v3 0/2] " Wang Nan
2015-04-07  8:22       ` [PATCH v3 1/2] perf: kmaps: enforce usage of kmaps to protect futher bugs Wang Nan
2015-04-08 15:10         ` [tip:perf/core] perf kmaps: Check kmaps to make code more robust tip-bot for Wang Nan
2015-04-07  8:22       ` [PATCH v3 2/2] perf: report/annotate: fix segfault problem Wang Nan
2015-04-07 15:13         ` Arnaldo Carvalho de Melo
2015-04-08  3:49           ` Wang Nan
2015-04-08  3:52           ` [PATCH v4 " Wang Nan
2015-04-08 13:59             ` Jiri Olsa
2015-04-09  7:05               ` Wang Nan
2015-04-09 11:40                 ` Jiri Olsa
2015-04-09 11:52             ` Jiri Olsa
2015-04-10  1:57               ` Wang Nan
2015-04-10  2:49               ` Wang Nan
2015-04-10  3:53               ` [PATCH v5 " Wang Nan
2015-04-15  1:27                 ` Wang Nan
2015-04-20  1:18                   ` Wang Nan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.