Skip to content

Commit 5a0baf5

Browse files
ahunter6acmel
authored andcommitted
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 <[email protected]> Acked-by: Jiri Olsa <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent f948eb4 commit 5a0baf5

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

tools/perf/util/copyfile.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,16 @@ static int copyfile_mode_ns(const char *from, const char *to, mode_t mode,
101101
if (tofd < 0)
102102
goto out;
103103

104-
if (fchmod(tofd, mode))
105-
goto out_close_to;
106-
107104
if (st.st_size == 0) { /* /proc? do it slowly... */
108105
err = slow_copyfile(from, tmp, nsi);
106+
if (!err && fchmod(tofd, mode))
107+
err = -1;
109108
goto out_close_to;
110109
}
111110

111+
if (fchmod(tofd, mode))
112+
goto out_close_to;
113+
112114
nsinfo__mountns_enter(nsi, &nsc);
113115
fromfd = open(from, O_RDONLY);
114116
nsinfo__mountns_exit(&nsc);

0 commit comments

Comments
 (0)