From: Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>
To: Ian Rogers <irogers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
John Garry <john.garry@huawei.com>,
Jin Yao <yao.jin@linux.intel.com>,
Andi Kleen <ak@linux.intel.com>,
Kan Liang <kan.liang@linux.intel.com>,
linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com,
Stephane Eranian <eranian@google.com>
Subject: Re: [PATCH] perf parse-events: add defensive null check
Date: Wed, 25 Mar 2020 16:25:39 -0300 [thread overview]
Message-ID: <20200325192539.GH14102@kernel.org> (raw)
In-Reply-To: <20200325164022.41385-1-irogers@google.com>
Em Wed, Mar 25, 2020 at 09:40:22AM -0700, Ian Rogers escreveu:
> Terms may have a null config in which case a strcmp will segv. This can
> be reproduced with:
> perf stat -e '*/event=?,nr/' sleep 1
> Add a null check to avoid this. This was caught by LLVM's libfuzzer.
Adding the NULL check doesn't hurt, I guess, but I coudln't repro it:
[root@seventh ~]# perf stat -e '*/event=?,nr/' sleep 1
WARNING: multiple event parsing errors
event syntax error: '*/event=?,nr/'
\___ 'nr' is not usable in 'perf stat'
Initial error:
event syntax error: '*/event=?,nr/'
\___ Cannot find PMU `*'. Missing kernel support?
Run 'perf list' for a list of valid events
Usage: perf stat [<options>] [<command>]
-e, --event <event> event selector. use 'perf list' to list available events
[root@seventh ~]#
Does this take place only when libfuzzer is being used?
- Arnaldo
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
> tools/perf/util/pmu.c | 11 +++++------
> 1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
> index 616fbda7c3fc..ef6a63f3d386 100644
> --- a/tools/perf/util/pmu.c
> +++ b/tools/perf/util/pmu.c
> @@ -984,12 +984,11 @@ static int pmu_resolve_param_term(struct parse_events_term *term,
> struct parse_events_term *t;
>
> list_for_each_entry(t, head_terms, list) {
> - if (t->type_val == PARSE_EVENTS__TERM_TYPE_NUM) {
> - if (!strcmp(t->config, term->config)) {
> - t->used = true;
> - *value = t->val.num;
> - return 0;
> - }
> + if (t->type_val == PARSE_EVENTS__TERM_TYPE_NUM &&
> + t->config && !strcmp(t->config, term->config)) {
> + t->used = true;
> + *value = t->val.num;
> + return 0;
> }
> }
>
> --
> 2.25.1.696.g5e7596f4ac-goog
>
--
- Arnaldo
next prev parent reply other threads:[~2020-03-25 19:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-25 16:40 [PATCH] perf parse-events: add defensive null check Ian Rogers
2020-03-25 19:25 ` Arnaldo Carvalho de Melo [this message]
2020-03-25 21:35 ` Ian Rogers
2020-04-04 8:41 ` [tip: perf/urgent] perf parse-events: Add defensive NULL check tip-bot2 for Ian Rogers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200325192539.GH14102@kernel.org \
--to=arnaldo.melo@gmail.com \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=clang-built-linux@googlegroups.com \
--cc=eranian@google.com \
--cc=irogers@google.com \
--cc=john.garry@huawei.com \
--cc=jolsa@redhat.com \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=yao.jin@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.