perf symbols: Check access permission when reading symbol files
authorLi Zhang <zhlcindy@linux.vnet.ibm.com>
Fri, 19 Jun 2015 08:57:33 +0000 (16:57 +0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 26 Jun 2015 15:11:53 +0000 (12:11 -0300)
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>
tools/perf/builtin-report.c
tools/perf/util/symbol.c

index 32626ea3e2276b11279db88207e42c29eeed391a..348bed4a2abf5a449be3279b969229444d112c7e 100644 (file)
@@ -742,6 +742,17 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
 
        argc = parse_options(argc, argv, options, report_usage, 0);
 
+       if (symbol_conf.vmlinux_name &&
+           access(symbol_conf.vmlinux_name, R_OK)) {
+               pr_err("Invalid file: %s\n", symbol_conf.vmlinux_name);
+               return -EINVAL;
+       }
+       if (symbol_conf.kallsyms_name &&
+           access(symbol_conf.kallsyms_name, R_OK)) {
+               pr_err("Invalid file: %s\n", symbol_conf.kallsyms_name);
+               return -EINVAL;
+       }
+
        if (report.use_stdio)
                use_browser = 0;
        else if (report.use_tui)
index 504f2d73b7eefe2699349ac75c5cc3b875961375..48b588c6951a9476246d6c71a9ee7b8535a8be37 100644 (file)
@@ -1132,8 +1132,11 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
        INIT_LIST_HEAD(&md.maps);
 
        fd = open(kcore_filename, O_RDONLY);
-       if (fd < 0)
+       if (fd < 0) {
+               pr_err("%s requires CAP_SYS_RAWIO capability to access.\n",
+                       kcore_filename);
                return -EINVAL;
+       }
 
        /* Read new maps into temporary lists */
        err = file__read_maps(fd, md.type == MAP__FUNCTION, kcore_mapfn, &md,
This page took 0.029934 seconds and 5 git commands to generate.