Re: [PATCH] perf tools: check perf_event_paranoid and kptr_restrict on 'perf top'
From: Jiri Olsa
Date: Tue Feb 23 2021 - 09:39:44 EST
On Tue, Feb 23, 2021 at 02:24:40PM +0800, Jackie Liu wrote:
> Perf top will segfault, we should give prompt information like perf
> record instead of crashing directly.
>
> Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> Cc: Ingo Molnar <mingo@xxxxxxxxxx>
> Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
> Cc: Mark Rutland <mark.rutland@xxxxxxx>
> Cc: Alexander Shishkin <alexander.shishkin@xxxxxxxxxxxxxxx>
> Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
> Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
> Signed-off-by: Jackie Liu <liuyun01@xxxxxxxxxx>
> ---
> tools/perf/builtin-top.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
> index 3673c04d16b6..b257fadba3bd 100644
> --- a/tools/perf/builtin-top.c
> +++ b/tools/perf/builtin-top.c
> @@ -1239,6 +1239,14 @@ static int __cmd_top(struct perf_top *top)
> return ret;
> }
>
> + if (symbol_conf.kptr_restrict && !evlist__exclude_kernel(top->evlist)) {
> + pr_warning(
> +"Kernel address maps (/proc/{kallsyms,modules}) are restricted.\n\n"
> +"Check /proc/sys/kernel/kptr_restrict and /proc/sys/kernel/perf_event_paranoid.\n\n"
> +"Kernel samples will not be resolved.\n");
> + return -1;
> + }
> +
hm, why not fix that crash by checking prog_addrs != NULL before using it
perf_event__synthesize_one_bpf_prog:
...
__u64 *prog_addrs = (__u64 *)(uintptr_t)(info->jited_ksyms);
it looks like we're already checking on kptr_restrict in
perf_event__process_sample and allow it on some level
jirka
> ret = callchain_param__setup_sample_type(&callchain_param);
> if (ret)
> return ret;
> --
> 2.25.1
>