diff options
author | Li Zhang <zhlcindy@linux.vnet.ibm.com> | 2015-06-19 04:57:33 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2015-06-26 11:11:53 -0400 |
commit | 36c8bb56a9f718a9a5f35d1834ca9dcec95deb4a (patch) | |
tree | ca03e7f2fa83e2401af8f1c773c297baae2115b7 | |
parent | 32b8af82e3708bc19af75c31fa773a98449f0edc (diff) |
perf symbols: Check access permission when reading symbol files
There 2 problems when reading symbols files:
* It doesn't report any errors even if when users specify symbol
files which don't exist with --kallsyms or --vmlinux. The result
just shows the address without symbols, which is not what is expected.
So it's better to report errors and exit the program.
* When using command perf report --kallsyms=/proc/kallsyms with a
non-root user, symbols are resolved. Then select one symbol and
annotate it, it reports the error as the following:
Can't annotate __clear_user: No vmlinux file with build id xxx was
found.
The problem is caused by reading /proc/kcore without access permission.
/proc/kcore requires CAP_SYS_RAWIO capability to access, so it needs to
change access permission to allow a specific user to read /proc/kcore or
use root to execute the perf command.
This patch is to report errors when symbol files specified by users
don't exist. And check access permission of /proc/kcore when reading it.
Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com>
Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Link: http://lkml.kernel.org/r/1434704253-2632-1-git-send-email-zhlcindy@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/builtin-report.c | 11 | ||||
-rw-r--r-- | tools/perf/util/symbol.c | 5 |
2 files changed, 15 insertions, 1 deletions
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 32626ea3e227..348bed4a2abf 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c | |||
@@ -742,6 +742,17 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused) | |||
742 | 742 | ||
743 | argc = parse_options(argc, argv, options, report_usage, 0); | 743 | argc = parse_options(argc, argv, options, report_usage, 0); |
744 | 744 | ||
745 | if (symbol_conf.vmlinux_name && | ||
746 | access(symbol_conf.vmlinux_name, R_OK)) { | ||
747 | pr_err("Invalid file: %s\n", symbol_conf.vmlinux_name); | ||
748 | return -EINVAL; | ||
749 | } | ||
750 | if (symbol_conf.kallsyms_name && | ||
751 | access(symbol_conf.kallsyms_name, R_OK)) { | ||
752 | pr_err("Invalid file: %s\n", symbol_conf.kallsyms_name); | ||
753 | return -EINVAL; | ||
754 | } | ||
755 | |||
745 | if (report.use_stdio) | 756 | if (report.use_stdio) |
746 | use_browser = 0; | 757 | use_browser = 0; |
747 | else if (report.use_tui) | 758 | else if (report.use_tui) |
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 504f2d73b7ee..48b588c6951a 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c | |||
@@ -1132,8 +1132,11 @@ static int dso__load_kcore(struct dso *dso, struct map *map, | |||
1132 | INIT_LIST_HEAD(&md.maps); | 1132 | INIT_LIST_HEAD(&md.maps); |
1133 | 1133 | ||
1134 | fd = open(kcore_filename, O_RDONLY); | 1134 | fd = open(kcore_filename, O_RDONLY); |
1135 | if (fd < 0) | 1135 | if (fd < 0) { |
1136 | pr_err("%s requires CAP_SYS_RAWIO capability to access.\n", | ||
1137 | kcore_filename); | ||
1136 | return -EINVAL; | 1138 | return -EINVAL; |
1139 | } | ||
1137 | 1140 | ||
1138 | /* Read new maps into temporary lists */ | 1141 | /* Read new maps into temporary lists */ |
1139 | err = file__read_maps(fd, md.type == MAP__FUNCTION, kcore_mapfn, &md, | 1142 | err = file__read_maps(fd, md.type == MAP__FUNCTION, kcore_mapfn, &md, |