Skip to content

Commit

Permalink
perf symbols: Prevent the use of kcore if the kernel has moved
Browse files Browse the repository at this point in the history
Use of kcore is predicated upon it matching the recorded data.  If the
kernel has been relocated at boot time (i.e. since the data was
recorded) then do not use kcore.

Note that it is possible to make a copy of kcore at the time the data is
recorded using 'perf buildid-cache'.  Then the perf tools will use the
copy because it does match the data.

Signed-off-by: Adrian Hunter <[email protected]>
Tested-by: Jiri Olsa <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
ahunter6 authored and acmel committed Jan 31, 2014
1 parent 0ae617b commit a00d28c
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions tools/perf/util/symbol.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,23 @@ static int validate_kcore_modules(const char *kallsyms_filename,
return 0;
}

static int validate_kcore_addresses(const char *kallsyms_filename,
struct map *map)
{
struct kmap *kmap = map__kmap(map);

if (kmap->ref_reloc_sym && kmap->ref_reloc_sym->name) {
u64 start;

start = kallsyms__get_function_start(kallsyms_filename,
kmap->ref_reloc_sym->name);
if (start != kmap->ref_reloc_sym->addr)
return -EINVAL;
}

return validate_kcore_modules(kallsyms_filename, map);
}

struct kcore_mapfn_data {
struct dso *dso;
enum map_type type;
Expand Down Expand Up @@ -1019,8 +1036,8 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
kallsyms_filename))
return -EINVAL;

/* All modules must be present at their original addresses */
if (validate_kcore_modules(kallsyms_filename, map))
/* Modules and kernel must be present at their original addresses */
if (validate_kcore_addresses(kallsyms_filename, map))
return -EINVAL;

md.dso = dso;
Expand Down Expand Up @@ -1424,7 +1441,7 @@ static int find_matching_kcore(struct map *map, char *dir, size_t dir_sz)
continue;
scnprintf(kallsyms_filename, sizeof(kallsyms_filename),
"%s/%s/kallsyms", dir, dent->d_name);
if (!validate_kcore_modules(kallsyms_filename, map)) {
if (!validate_kcore_addresses(kallsyms_filename, map)) {
strlcpy(dir, kallsyms_filename, dir_sz);
ret = 0;
break;
Expand Down Expand Up @@ -1479,7 +1496,7 @@ static char *dso__find_kallsyms(struct dso *dso, struct map *map)
if (fd != -1) {
close(fd);
/* If module maps match go with /proc/kallsyms */
if (!validate_kcore_modules("/proc/kallsyms", map))
if (!validate_kcore_addresses("/proc/kallsyms", map))
goto proc_kallsyms;
}

Expand Down

0 comments on commit a00d28c

Please sign in to comment.