diff options
author | Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> | 2015-09-30 12:41:35 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2015-09-30 17:34:36 -0400 |
commit | 20f49859c785183d5296670a10dace454131274b (patch) | |
tree | 294ae96fff016f4c3575bbed2297199d825c04de | |
parent | 9b239a12bc872f212cefbaee4d028c838abe6ff3 (diff) |
perf probe: Fix a segfault bug in debuginfo_cache
perf probe --list will get a segfault if the first kprobe event is on a
module and the second or latter one is on the kernel.
e.g.
----
# ./perf probe -q -m pcspkr pcspkr_event
# ./perf probe -q vfs_read
# ./perf probe -l
Segmentation fault (core dumped)
----
This is because the debuginfo_cache fails to handle NULL module name,
which causes segfault on strcmp. (Note that strcmp("something", NULL)
always causes segfault)
To fix this debuginfo_cache__open always translates the NULL module name
to "kernel" (this is correct, because NULL module name means opening the
debuginfo for the kernel)
----
# ./perf probe -l
probe:pcspkr_event (on pcspkr_event@drivers/input/misc/pcspkr.c
in pcspkr)
probe:vfs_read (on vfs_read@ksrc/linux-3/fs/read_write.c)
----
Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/20150930164135.3733.23993.stgit@localhost.localdomain
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/util/probe-event.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 65be284823d5..3010abc071ff 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c | |||
@@ -441,19 +441,22 @@ static char *debuginfo_cache_path; | |||
441 | 441 | ||
442 | static struct debuginfo *debuginfo_cache__open(const char *module, bool silent) | 442 | static struct debuginfo *debuginfo_cache__open(const char *module, bool silent) |
443 | { | 443 | { |
444 | if ((debuginfo_cache_path && !strcmp(debuginfo_cache_path, module)) || | 444 | const char *path = module; |
445 | (!debuginfo_cache_path && !module && debuginfo_cache)) | 445 | |
446 | /* If the module is NULL, it should be the kernel. */ | ||
447 | if (!module) | ||
448 | path = "kernel"; | ||
449 | |||
450 | if (debuginfo_cache_path && !strcmp(debuginfo_cache_path, path)) | ||
446 | goto out; | 451 | goto out; |
447 | 452 | ||
448 | /* Copy module path */ | 453 | /* Copy module path */ |
449 | free(debuginfo_cache_path); | 454 | free(debuginfo_cache_path); |
450 | if (module) { | 455 | debuginfo_cache_path = strdup(path); |
451 | debuginfo_cache_path = strdup(module); | 456 | if (!debuginfo_cache_path) { |
452 | if (!debuginfo_cache_path) { | 457 | debuginfo__delete(debuginfo_cache); |
453 | debuginfo__delete(debuginfo_cache); | 458 | debuginfo_cache = NULL; |
454 | debuginfo_cache = NULL; | 459 | goto out; |
455 | goto out; | ||
456 | } | ||
457 | } | 460 | } |
458 | 461 | ||
459 | debuginfo_cache = open_debuginfo(module, silent); | 462 | debuginfo_cache = open_debuginfo(module, silent); |