Commit 80526491 authored by Masami Hiramatsu's avatar Masami Hiramatsu Committed by Arnaldo Carvalho de Melo

perf probe: Fix to check blacklist address correctly

Fix to check kprobe blacklist address correctly with relocated address
by adjusting debuginfo address.

Since the address in the debuginfo is same as objdump, it is different
from relocated kernel address with KASLR.  Thus, 'perf probe' always
misses to catch the blacklisted addresses.

Without this patch, 'perf probe' can not detect the blacklist addresses
on a KASLR enabled kernel.

  # perf probe kprobe_dispatcher
  Failed to write event: Invalid argument
    Error: Failed to add events.
  #

With this patch, it correctly shows the error message.

  # perf probe kprobe_dispatcher
  kprobe_dispatcher is blacklisted function, skip it.
  Probe point 'kprobe_dispatcher' not found.
    Error: Failed to add events.
  #

Fixes: 9aaf5a5f ("perf probe: Check kprobes blacklist when adding new events")
Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: stable@vger.kernel.org
Link: http://lore.kernel.org/lkml/158763966411.30755.5882376357738273695.stgit@devnote2Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent c6aab66a
...@@ -102,7 +102,7 @@ void exit_probe_symbol_maps(void) ...@@ -102,7 +102,7 @@ void exit_probe_symbol_maps(void)
symbol__exit(); symbol__exit();
} }
static struct ref_reloc_sym *kernel_get_ref_reloc_sym(void) static struct ref_reloc_sym *kernel_get_ref_reloc_sym(struct map **pmap)
{ {
/* kmap->ref_reloc_sym should be set if host_machine is initialized */ /* kmap->ref_reloc_sym should be set if host_machine is initialized */
struct kmap *kmap; struct kmap *kmap;
...@@ -114,6 +114,10 @@ static struct ref_reloc_sym *kernel_get_ref_reloc_sym(void) ...@@ -114,6 +114,10 @@ static struct ref_reloc_sym *kernel_get_ref_reloc_sym(void)
kmap = map__kmap(map); kmap = map__kmap(map);
if (!kmap) if (!kmap)
return NULL; return NULL;
if (pmap)
*pmap = map;
return kmap->ref_reloc_sym; return kmap->ref_reloc_sym;
} }
...@@ -125,7 +129,7 @@ static int kernel_get_symbol_address_by_name(const char *name, u64 *addr, ...@@ -125,7 +129,7 @@ static int kernel_get_symbol_address_by_name(const char *name, u64 *addr,
struct map *map; struct map *map;
/* ref_reloc_sym is just a label. Need a special fix*/ /* ref_reloc_sym is just a label. Need a special fix*/
reloc_sym = kernel_get_ref_reloc_sym(); reloc_sym = kernel_get_ref_reloc_sym(NULL);
if (reloc_sym && strcmp(name, reloc_sym->name) == 0) if (reloc_sym && strcmp(name, reloc_sym->name) == 0)
*addr = (reloc) ? reloc_sym->addr : reloc_sym->unrelocated_addr; *addr = (reloc) ? reloc_sym->addr : reloc_sym->unrelocated_addr;
else { else {
...@@ -745,6 +749,7 @@ post_process_kernel_probe_trace_events(struct probe_trace_event *tevs, ...@@ -745,6 +749,7 @@ post_process_kernel_probe_trace_events(struct probe_trace_event *tevs,
int ntevs) int ntevs)
{ {
struct ref_reloc_sym *reloc_sym; struct ref_reloc_sym *reloc_sym;
struct map *map;
char *tmp; char *tmp;
int i, skipped = 0; int i, skipped = 0;
...@@ -753,7 +758,7 @@ post_process_kernel_probe_trace_events(struct probe_trace_event *tevs, ...@@ -753,7 +758,7 @@ post_process_kernel_probe_trace_events(struct probe_trace_event *tevs,
return post_process_offline_probe_trace_events(tevs, ntevs, return post_process_offline_probe_trace_events(tevs, ntevs,
symbol_conf.vmlinux_name); symbol_conf.vmlinux_name);
reloc_sym = kernel_get_ref_reloc_sym(); reloc_sym = kernel_get_ref_reloc_sym(&map);
if (!reloc_sym) { if (!reloc_sym) {
pr_warning("Relocated base symbol is not found!\n"); pr_warning("Relocated base symbol is not found!\n");
return -EINVAL; return -EINVAL;
...@@ -764,9 +769,13 @@ post_process_kernel_probe_trace_events(struct probe_trace_event *tevs, ...@@ -764,9 +769,13 @@ post_process_kernel_probe_trace_events(struct probe_trace_event *tevs,
continue; continue;
if (tevs[i].point.retprobe && !kretprobe_offset_is_supported()) if (tevs[i].point.retprobe && !kretprobe_offset_is_supported())
continue; continue;
/* If we found a wrong one, mark it by NULL symbol */ /*
* If we found a wrong one, mark it by NULL symbol.
* Since addresses in debuginfo is same as objdump, we need
* to convert it to addresses on memory.
*/
if (kprobe_warn_out_range(tevs[i].point.symbol, if (kprobe_warn_out_range(tevs[i].point.symbol,
tevs[i].point.address)) { map__objdump_2mem(map, tevs[i].point.address))) {
tmp = NULL; tmp = NULL;
skipped++; skipped++;
} else { } else {
...@@ -2935,7 +2944,7 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev, ...@@ -2935,7 +2944,7 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev,
/* Note that the symbols in the kmodule are not relocated */ /* Note that the symbols in the kmodule are not relocated */
if (!pev->uprobes && !pev->target && if (!pev->uprobes && !pev->target &&
(!pp->retprobe || kretprobe_offset_is_supported())) { (!pp->retprobe || kretprobe_offset_is_supported())) {
reloc_sym = kernel_get_ref_reloc_sym(); reloc_sym = kernel_get_ref_reloc_sym(NULL);
if (!reloc_sym) { if (!reloc_sym) {
pr_warning("Relocated base symbol is not found!\n"); pr_warning("Relocated base symbol is not found!\n");
ret = -EINVAL; ret = -EINVAL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment