diff options
author | Adrian Hunter <adrian.hunter@intel.com> | 2019-10-07 03:02:21 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2019-10-15 11:05:18 -0400 |
commit | 5a0baf5123236362fda4e9772cc63b7faa16a0df (patch) | |
tree | 613553545de11d225af3f73f59393e2b347516cb /tools | |
parent | f948eb45e3af9fb18a0487d0797a773897ef6929 (diff) |
perf tools: Fix mode setting in copyfile_mode_ns()
slow_copyfile() opens the file by name, so "write" permissions must not
be removed in copyfile_mode_ns() before calling slow_copyfile().
Example:
Before:
$ sudo chmod +r /proc/kcore
$ sudo setcap "cap_sys_admin,cap_sys_ptrace,cap_syslog,cap_sys_rawio=ep" tools/perf/perf
$ tools/perf/perf buildid-cache -k /proc/kcore
Couldn't add /proc/kcore
After:
$ sudo chmod +r /proc/kcore
$ sudo setcap "cap_sys_admin,cap_sys_ptrace,cap_syslog,cap_sys_rawio=ep" tools/perf/perf
$ tools/perf/perf buildid-cache -v -k /proc/kcore
kcore added to build-id cache directory /home/ahunter/.debug/[kernel.kcore]/37e340b1b5a7cf4f57ba8de2bc777359588a957f/2019100709562289
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Link: http://lore.kernel.org/lkml/20191007070221.11158-1-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/util/copyfile.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/tools/perf/util/copyfile.c b/tools/perf/util/copyfile.c index 3fa0db136667..47e03de7c235 100644 --- a/tools/perf/util/copyfile.c +++ b/tools/perf/util/copyfile.c | |||
@@ -101,14 +101,16 @@ static int copyfile_mode_ns(const char *from, const char *to, mode_t mode, | |||
101 | if (tofd < 0) | 101 | if (tofd < 0) |
102 | goto out; | 102 | goto out; |
103 | 103 | ||
104 | if (fchmod(tofd, mode)) | ||
105 | goto out_close_to; | ||
106 | |||
107 | if (st.st_size == 0) { /* /proc? do it slowly... */ | 104 | if (st.st_size == 0) { /* /proc? do it slowly... */ |
108 | err = slow_copyfile(from, tmp, nsi); | 105 | err = slow_copyfile(from, tmp, nsi); |
106 | if (!err && fchmod(tofd, mode)) | ||
107 | err = -1; | ||
109 | goto out_close_to; | 108 | goto out_close_to; |
110 | } | 109 | } |
111 | 110 | ||
111 | if (fchmod(tofd, mode)) | ||
112 | goto out_close_to; | ||
113 | |||
112 | nsinfo__mountns_enter(nsi, &nsc); | 114 | nsinfo__mountns_enter(nsi, &nsc); |
113 | fromfd = open(from, O_RDONLY); | 115 | fromfd = open(from, O_RDONLY); |
114 | nsinfo__mountns_exit(&nsc); | 116 | nsinfo__mountns_exit(&nsc); |