perf tools: avoid segv in pmu_resolve_param_term
Ian Rogers
reviewerPATCH 1/1 perf tools: avoid segv in pmu_resolve_param_term
PE_TERMS may set the config to NULL, avoid dereferencing this in pmu_resolve_param_term. Error detected by LLVM's libFuzzer. To reproduce the segv run:
$ perf record -e 'm/event=?,time/' ls
Signed-off-by Ian Rogers <[email protected]>
--- tools/perf/util/pmu.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
tools/perf/util/pmu.c +11 -7
@@ -988,13 +988,17 @@ 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 ) +continue ; + +if (t->config ==NULL && term->config !=NULL ) +continue ; +else if (strcmp (t->config, term->config)) +continue ; + + t->used = true; + *value = t->val.num; +return 0 ; }if (verbose >0 )
Signature · 1 line
2.24.0.432.g9d3f5f5b63-goog
Quoted 20 lines · Ian Rogers
PE_TERMSmay set the config to NULL, avoid dereferencing this inpmu_resolve_param_term. Error detected by LLVM's libFuzzer. To reproduce the segv run:$ perf record -e 'm/event=?,time/' lsSigned-off-by Ian Rogers <[email protected]>--- tools/perf/util/pmu.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)tools/perf/util/pmu.c +0
-2@@ -988,13 +988,17 @@ 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)) {
tools/perf/util/pmu.c static int pmu_resolve_param_term(struct parse_events_term *term, · line 995
Quoted 10 lines
tools/perf/util/pmu.c +5
-5- t->used = true; - *value = t->val.num; -return 0 ; - } - } +if (t->type_val !=PARSE_EVENTS__TERM_TYPE_NUM ) +continue ; + +if (t->config ==NULL && term->config !=NULL ) +continue ;
hum, I might be missing something but should above condition be more like this?
if (t->config == NULL || term->config == NULL) continue;
jirka
Quoted 12 lines
tools/perf/util/pmu.c +6
-0+else if (strcmp (t->config, term->config)) +continue ; + + t->used = true; + *value = t->val.num; +return 0 ; }if (verbose >0 )Signature · 1 line
2.24.0.432.g9d3f5f5b63-goog