Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf symbols: Allow forcing reading of non-root owned files by root

When the root user tries to read a file owned by some other user we get:

# ls -la perf.data
-rw-------. 1 acme acme 20032 Nov 12 15:50 perf.data
# perf report
File perf.data not owned by current user or root (use -f to override)
# perf report -f | grep -v ^# | head -2
30.96% ls [kernel.vmlinux] [k] do_set_pte
28.24% ls libc-2.20.so [.] intel_check_word
#

That wasn't happening when the symbol code tried to read a JIT map,
where the same check was done but no forcing was possible, fix it.

Reported-by: Brendan Gregg <brendan.d.gregg@gmail.com>
Tested-by: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://permalink.gmane.org/gmane.linux.kernel.perf.user/2380
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+6 -5
+3 -3
tools/perf/builtin-report.c
··· 44 44 struct report { 45 45 struct perf_tool tool; 46 46 struct perf_session *session; 47 - bool force, use_tui, use_gtk, use_stdio; 47 + bool use_tui, use_gtk, use_stdio; 48 48 bool hide_unresolved; 49 49 bool dont_use_callchains; 50 50 bool show_full_info; ··· 678 678 "file", "vmlinux pathname"), 679 679 OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name, 680 680 "file", "kallsyms pathname"), 681 - OPT_BOOLEAN('f', "force", &report.force, "don't complain, do it"), 681 + OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"), 682 682 OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules, 683 683 "load module symbols - WARNING: use only with -k and LIVE kernel"), 684 684 OPT_BOOLEAN('n', "show-nr-samples", &symbol_conf.show_nr_samples, ··· 832 832 } 833 833 834 834 file.path = input_name; 835 - file.force = report.force; 835 + file.force = symbol_conf.force; 836 836 837 837 repeat: 838 838 session = perf_session__new(&file, false, &report.tool);
+2 -2
tools/perf/util/symbol.c
··· 1436 1436 if (lstat(dso->name, &st) < 0) 1437 1437 goto out; 1438 1438 1439 - if (st.st_uid && (st.st_uid != geteuid())) { 1439 + if (!symbol_conf.force && st.st_uid && (st.st_uid != geteuid())) { 1440 1440 pr_warning("File %s not owned by current user or root, " 1441 - "ignoring it.\n", dso->name); 1441 + "ignoring it (use -f to override).\n", dso->name); 1442 1442 goto out; 1443 1443 } 1444 1444
+1
tools/perf/util/symbol.h
··· 84 84 unsigned short priv_size; 85 85 unsigned short nr_events; 86 86 bool try_vmlinux_path, 87 + force, 87 88 ignore_vmlinux, 88 89 ignore_vmlinux_buildid, 89 90 show_kernel_path,