forked from analogdevicesinc/linux
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf annotate: Validate addr in symbol__inc_addr_samples
This routine was checking only if the provided address was after sym->end, not if it was before sym->start. Fix that by checking for both and return in both cases -ERANGE, so that tools can communicate this to the user properly, or if they chose so, to abort. This problem was reported previously but the fixes involved either doing what was being done for the > end case, i.e. silently drop the sample, returning 0, or aborting at this function, which is in a lib (or better, is slated to be at some point) and shouldn't abort. The 'report' tool already checks this value and uses pr_debug to warn the user. This patch makes the 'top' tool check it too and warn once per map where such range problem takes place. Reported-by: David Miller <[email protected]> Reported-by: Sorin Dumitru <[email protected]> Reported-by: Stephane Eranian <[email protected]> Cc: David Ahern <[email protected]> Cc: Frederic Weisbecker <[email protected]> Cc: Mike Galbraith <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/n/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
- Loading branch information
Showing
4 changed files
with
38 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ | |
#include "util/debug.h" | ||
|
||
#include <assert.h> | ||
#include <elf.h> | ||
#include <fcntl.h> | ||
|
||
#include <stdio.h> | ||
|
@@ -59,6 +60,7 @@ | |
#include <sys/prctl.h> | ||
#include <sys/wait.h> | ||
#include <sys/uio.h> | ||
#include <sys/utsname.h> | ||
#include <sys/mman.h> | ||
|
||
#include <linux/unistd.h> | ||
|
@@ -162,12 +164,40 @@ static void __zero_source_counters(struct hist_entry *he) | |
symbol__annotate_zero_histograms(sym); | ||
} | ||
|
||
static void ui__warn_map_erange(struct map *map, struct symbol *sym, u64 ip) | ||
{ | ||
struct utsname uts; | ||
int err = uname(&uts); | ||
|
||
ui__warning("Out of bounds address found:\n\n" | ||
"Addr: %" PRIx64 "\n" | ||
"DSO: %s %c\n" | ||
"Map: %" PRIx64 "-%" PRIx64 "\n" | ||
"Symbol: %" PRIx64 "-%" PRIx64 " %c %s\n" | ||
"Arch: %s\n" | ||
"Kernel: %s\n" | ||
"Tools: %s\n\n" | ||
"Not all samples will be on the annotation output.\n\n" | ||
"Please report to [email protected]\n", | ||
ip, map->dso->long_name, dso__symtab_origin(map->dso), | ||
map->start, map->end, sym->start, sym->end, | ||
sym->binding == STB_GLOBAL ? 'g' : | ||
sym->binding == STB_LOCAL ? 'l' : 'w', sym->name, | ||
err ? "[unknown]" : uts.machine, | ||
err ? "[unknown]" : uts.release, perf_version_string); | ||
if (use_browser <= 0) | ||
sleep(5); | ||
|
||
map->erange_warned = true; | ||
} | ||
|
||
static void perf_top__record_precise_ip(struct perf_top *top, | ||
struct hist_entry *he, | ||
int counter, u64 ip) | ||
{ | ||
struct annotation *notes; | ||
struct symbol *sym; | ||
int err; | ||
|
||
if (he == NULL || he->ms.sym == NULL || | ||
((top->sym_filter_entry == NULL || | ||
|
@@ -189,9 +219,12 @@ static void perf_top__record_precise_ip(struct perf_top *top, | |
} | ||
|
||
ip = he->ms.map->map_ip(he->ms.map, ip); | ||
symbol__inc_addr_samples(sym, he->ms.map, counter, ip); | ||
err = symbol__inc_addr_samples(sym, he->ms.map, counter, ip); | ||
|
||
pthread_mutex_unlock(¬es->lock); | ||
|
||
if (err == -ERANGE && !he->ms.map->erange_warned) | ||
ui__warn_map_erange(he->ms.map, sym, ip); | ||
} | ||
|
||
static void perf_top__show_details(struct perf_top *top) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters