All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH v3 1/1] perf tools: Check access permission when reading symbol files
       [not found] <1434704253-2632-1-git-send-email-zhlcindy@linux.vnet.ibm.com>
@ 2015-06-26  6:22 ` Li Zhang
  2015-06-26 15:36   ` Arnaldo Carvalho de Melo
  2015-06-30  4:59 ` [tip:perf/urgent] perf symbols: " tip-bot for Li Zhang
  1 sibling, 1 reply; 3+ messages in thread
From: Li Zhang @ 2015-06-26  6:22 UTC (permalink / raw)
  To: Li Zhang; +Cc: acme, mingo, sukadev, linux-kernel

ping ?

On 2015年06月19日 16:57, Li Zhang wrote:
> There 2 problems when reading symbols files:
>
> *  It doesn't report any errors even if when users specify symbol
>     files which don't exist with --kallsyms or --vmlinux. The result
>     just shows the address without symbols, which is not what is expected.
>     So it's better to report errors and exit the program.
>
> *  When using command perf report --kallsyms=/proc/kallsyms with a
>     non-root user, symbols are resolved. Then select one symbol and
>     annotate it, it reports the error as the following:
>     Can't annotate __clear_user: No vmlinux file with build id xxx was
>     found.
>
>     The problem is caused by reading /proc/kcore without access permission.
>     /proc/kcore requires CAP_SYS_RAWIO capability to access, so it needs to
>     change access permission to allow a specific user to read /proc/kcore or
>     use root to execute the perf command.
>
> This patch is to report errors when symbol files specified by users
> don't exist. And check access permission of /proc/kcore when reading it.
>
> Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com>
> ---
>
> v3 -> v2:
>    * Add checking symbol files when user specify these files.
>    * Report an error to users when open fails. Suggested by Sukar
>
> v2 -> v1:
>    * Report one useful message to users about the access permision,
>      then go back to the tools. Suggested by Arnaldo Carvalho de Melo.
>
>   tools/perf/builtin-report.c | 11 +++++++++++
>   tools/perf/util/symbol.c    |  5 ++++-
>   2 files changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
> index 476cdf7..1c353b1 100644
> --- a/tools/perf/builtin-report.c
> +++ b/tools/perf/builtin-report.c
> @@ -731,6 +731,17 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
>
>   	argc = parse_options(argc, argv, options, report_usage, 0);
>
> +	if (symbol_conf.vmlinux_name &&
> +		access(symbol_conf.vmlinux_name, R_OK)) {
> +		pr_err("Invalid file: %s\n", symbol_conf.vmlinux_name);
> +		return -EINVAL;
> +	}
> +	if (symbol_conf.kallsyms_name &&
> +		access(symbol_conf.kallsyms_name, R_OK)) {
> +		pr_err("Invalid file: %s\n", symbol_conf.kallsyms_name);
> +		return -EINVAL;
> +	}
> +
>   	if (report.use_stdio)
>   		use_browser = 0;
>   	else if (report.use_tui)
> diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
> index 201f6c4c..46aa93d 100644
> --- a/tools/perf/util/symbol.c
> +++ b/tools/perf/util/symbol.c
> @@ -1126,8 +1126,11 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
>   	INIT_LIST_HEAD(&md.maps);
>
>   	fd = open(kcore_filename, O_RDONLY);
> -	if (fd < 0)
> +	if (fd < 0) {
> +		pr_err("%s requires CAP_SYS_RAWIO capability to access.\n",
> +			kcore_filename);
>   		return -EINVAL;
> +	}
>
>   	/* Read new maps into temporary lists */
>   	err = file__read_maps(fd, md.type == MAP__FUNCTION, kcore_mapfn, &md,


-- 

Li Zhang
IBM China Linux Technology Centre


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

* Re: [PATCH v3 1/1] perf tools: Check access permission when reading symbol files
  2015-06-26  6:22 ` [PATCH v3 1/1] perf tools: Check access permission when reading symbol files Li Zhang
@ 2015-06-26 15:36   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2015-06-26 15:36 UTC (permalink / raw)
  To: Li Zhang; +Cc: mingo, sukadev, linux-kernel

Em Fri, Jun 26, 2015 at 02:22:29PM +0800, Li Zhang escreveu:
> ping ?

Thanks, applied.

- Arnaldo

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

* [tip:perf/urgent] perf symbols: Check access permission when reading symbol files
       [not found] <1434704253-2632-1-git-send-email-zhlcindy@linux.vnet.ibm.com>
  2015-06-26  6:22 ` [PATCH v3 1/1] perf tools: Check access permission when reading symbol files Li Zhang
@ 2015-06-30  4:59 ` tip-bot for Li Zhang
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Li Zhang @ 2015-06-30  4:59 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, acme, tglx, zhlcindy, sukadev

Commit-ID:  36c8bb56a9f718a9a5f35d1834ca9dcec95deb4a
Gitweb:     http://git.kernel.org/tip/36c8bb56a9f718a9a5f35d1834ca9dcec95deb4a
Author:     Li Zhang <zhlcindy@linux.vnet.ibm.com>
AuthorDate: Fri, 19 Jun 2015 16:57:33 +0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Fri, 26 Jun 2015 12:11:53 -0300

perf symbols: Check access permission when reading symbol files

There 2 problems when reading symbols files:

*  It doesn't report any errors even if when users specify symbol
   files which don't exist with --kallsyms or --vmlinux. The result
   just shows the address without symbols, which is not what is expected.
   So it's better to report errors and exit the program.

*  When using command perf report --kallsyms=/proc/kallsyms with a
   non-root user, symbols are resolved. Then select one symbol and
   annotate it, it reports the error as the following:
   Can't annotate __clear_user: No vmlinux file with build id xxx was
   found.

   The problem is caused by reading /proc/kcore without access permission.
   /proc/kcore requires CAP_SYS_RAWIO capability to access, so it needs to
   change access permission to allow a specific user to read /proc/kcore or
   use root to execute the perf command.

This patch is to report errors when symbol files specified by users
don't exist. And check access permission of /proc/kcore when reading it.

Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com>
Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Link: http://lkml.kernel.org/r/1434704253-2632-1-git-send-email-zhlcindy@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-report.c | 11 +++++++++++
 tools/perf/util/symbol.c    |  5 ++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 32626ea..348bed4 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -742,6 +742,17 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
 
 	argc = parse_options(argc, argv, options, report_usage, 0);
 
+	if (symbol_conf.vmlinux_name &&
+	    access(symbol_conf.vmlinux_name, R_OK)) {
+		pr_err("Invalid file: %s\n", symbol_conf.vmlinux_name);
+		return -EINVAL;
+	}
+	if (symbol_conf.kallsyms_name &&
+	    access(symbol_conf.kallsyms_name, R_OK)) {
+		pr_err("Invalid file: %s\n", symbol_conf.kallsyms_name);
+		return -EINVAL;
+	}
+
 	if (report.use_stdio)
 		use_browser = 0;
 	else if (report.use_tui)
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 504f2d7..48b588c 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1132,8 +1132,11 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
 	INIT_LIST_HEAD(&md.maps);
 
 	fd = open(kcore_filename, O_RDONLY);
-	if (fd < 0)
+	if (fd < 0) {
+		pr_err("%s requires CAP_SYS_RAWIO capability to access.\n",
+			kcore_filename);
 		return -EINVAL;
+	}
 
 	/* Read new maps into temporary lists */
 	err = file__read_maps(fd, md.type == MAP__FUNCTION, kcore_mapfn, &md,

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

end of thread, other threads:[~2015-06-30  4:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1434704253-2632-1-git-send-email-zhlcindy@linux.vnet.ibm.com>
2015-06-26  6:22 ` [PATCH v3 1/1] perf tools: Check access permission when reading symbol files Li Zhang
2015-06-26 15:36   ` Arnaldo Carvalho de Melo
2015-06-30  4:59 ` [tip:perf/urgent] perf symbols: " tip-bot for Li Zhang

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.