All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf tools: Fix mode setting in copyfile_mode_ns()
@ 2019-10-07  7:02 Adrian Hunter
  2019-10-07 10:47 ` Jiri Olsa
  2019-10-21  6:26 ` [tip: perf/urgent] " tip-bot2 for Adrian Hunter
  0 siblings, 2 replies; 4+ messages in thread
From: Adrian Hunter @ 2019-10-07  7:02 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa; +Cc: linux-kernel

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>
---
 tools/perf/util/copyfile.c | 8 +++++---
 1 file 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,
 	if (tofd < 0)
 		goto out;
 
-	if (fchmod(tofd, mode))
-		goto out_close_to;
-
 	if (st.st_size == 0) { /* /proc? do it slowly... */
 		err = slow_copyfile(from, tmp, nsi);
+		if (!err && fchmod(tofd, mode))
+			err = -1;
 		goto out_close_to;
 	}
 
+	if (fchmod(tofd, mode))
+		goto out_close_to;
+
 	nsinfo__mountns_enter(nsi, &nsc);
 	fromfd = open(from, O_RDONLY);
 	nsinfo__mountns_exit(&nsc);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] perf tools: Fix mode setting in copyfile_mode_ns()
  2019-10-07  7:02 [PATCH] perf tools: Fix mode setting in copyfile_mode_ns() Adrian Hunter
@ 2019-10-07 10:47 ` Jiri Olsa
  2019-10-15 15:07   ` Arnaldo Carvalho de Melo
  2019-10-21  6:26 ` [tip: perf/urgent] " tip-bot2 for Adrian Hunter
  1 sibling, 1 reply; 4+ messages in thread
From: Jiri Olsa @ 2019-10-07 10:47 UTC (permalink / raw)
  To: Adrian Hunter; +Cc: Arnaldo Carvalho de Melo, linux-kernel

On Mon, Oct 07, 2019 at 10:02:21AM +0300, Adrian Hunter wrote:
> 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>

thanks,
jirka

> ---
>  tools/perf/util/copyfile.c | 8 +++++---
>  1 file 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,
>  	if (tofd < 0)
>  		goto out;
>  
> -	if (fchmod(tofd, mode))
> -		goto out_close_to;
> -
>  	if (st.st_size == 0) { /* /proc? do it slowly... */
>  		err = slow_copyfile(from, tmp, nsi);
> +		if (!err && fchmod(tofd, mode))
> +			err = -1;
>  		goto out_close_to;
>  	}
>  
> +	if (fchmod(tofd, mode))
> +		goto out_close_to;
> +
>  	nsinfo__mountns_enter(nsi, &nsc);
>  	fromfd = open(from, O_RDONLY);
>  	nsinfo__mountns_exit(&nsc);
> -- 
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] perf tools: Fix mode setting in copyfile_mode_ns()
  2019-10-07 10:47 ` Jiri Olsa
@ 2019-10-15 15:07   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 4+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-10-15 15:07 UTC (permalink / raw)
  To: Jiri Olsa; +Cc: Adrian Hunter, linux-kernel

Em Mon, Oct 07, 2019 at 12:47:47PM +0200, Jiri Olsa escreveu:
> On Mon, Oct 07, 2019 at 10:02:21AM +0300, Adrian Hunter wrote:
> > 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>

Thanks, applied to perf/urgent.

- Arnaldo
 
> thanks,
> jirka
> 
> > ---
> >  tools/perf/util/copyfile.c | 8 +++++---
> >  1 file 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,
> >  	if (tofd < 0)
> >  		goto out;
> >  
> > -	if (fchmod(tofd, mode))
> > -		goto out_close_to;
> > -
> >  	if (st.st_size == 0) { /* /proc? do it slowly... */
> >  		err = slow_copyfile(from, tmp, nsi);
> > +		if (!err && fchmod(tofd, mode))
> > +			err = -1;
> >  		goto out_close_to;
> >  	}
> >  
> > +	if (fchmod(tofd, mode))
> > +		goto out_close_to;
> > +
> >  	nsinfo__mountns_enter(nsi, &nsc);
> >  	fromfd = open(from, O_RDONLY);
> >  	nsinfo__mountns_exit(&nsc);
> > -- 
> > 2.17.1
> > 

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [tip: perf/urgent] perf tools: Fix mode setting in copyfile_mode_ns()
  2019-10-07  7:02 [PATCH] perf tools: Fix mode setting in copyfile_mode_ns() Adrian Hunter
  2019-10-07 10:47 ` Jiri Olsa
@ 2019-10-21  6:26 ` tip-bot2 for Adrian Hunter
  1 sibling, 0 replies; 4+ messages in thread
From: tip-bot2 for Adrian Hunter @ 2019-10-21  6:26 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Adrian Hunter, Jiri Olsa, Arnaldo Carvalho de Melo, Ingo Molnar,
	Borislav Petkov, linux-kernel

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID:     5a0baf5123236362fda4e9772cc63b7faa16a0df
Gitweb:        https://git.kernel.org/tip/5a0baf5123236362fda4e9772cc63b7faa16a0df
Author:        Adrian Hunter <adrian.hunter@intel.com>
AuthorDate:    Mon, 07 Oct 2019 10:02:21 +03:00
Committer:     Arnaldo Carvalho de Melo <acme@redhat.com>
CommitterDate: Tue, 15 Oct 2019 12:05:18 -03:00

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>
---
 tools/perf/util/copyfile.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/copyfile.c b/tools/perf/util/copyfile.c
index 3fa0db1..47e03de 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,
 	if (tofd < 0)
 		goto out;
 
-	if (fchmod(tofd, mode))
-		goto out_close_to;
-
 	if (st.st_size == 0) { /* /proc? do it slowly... */
 		err = slow_copyfile(from, tmp, nsi);
+		if (!err && fchmod(tofd, mode))
+			err = -1;
 		goto out_close_to;
 	}
 
+	if (fchmod(tofd, mode))
+		goto out_close_to;
+
 	nsinfo__mountns_enter(nsi, &nsc);
 	fromfd = open(from, O_RDONLY);
 	nsinfo__mountns_exit(&nsc);

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-10-21  6:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-07  7:02 [PATCH] perf tools: Fix mode setting in copyfile_mode_ns() Adrian Hunter
2019-10-07 10:47 ` Jiri Olsa
2019-10-15 15:07   ` Arnaldo Carvalho de Melo
2019-10-21  6:26 ` [tip: perf/urgent] " tip-bot2 for Adrian Hunter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.