lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 7 Oct 2019 12:47:47 +0200
From:   Jiri Olsa <jolsa@...hat.com>
To:     Adrian Hunter <adrian.hunter@...el.com>
Cc:     Arnaldo Carvalho de Melo <acme@...nel.org>,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH] perf tools: Fix mode setting in copyfile_mode_ns()

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@...el.com>

Acked-by: Jiri Olsa <jolsa@...nel.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
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ