Skip to contentSkip to conversation

perf tools: avoid segv in pmu_resolve_param_term

PATCH In review Ian Rogers 2 participants 2 messages Nov 25, 2019 – Nov 26, 2019 perf events

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 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
---
 tools/perf/util/pmu.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
tools/perf/util/pmu.c +11 -7
index e8d348988026..1a6e36353407 100644
@@ -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
#1 lore raw
Quoted 20 lines · Ian Rogers

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
---
 tools/perf/util/pmu.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
tools/perf/util/pmu.c +0 -2
index e8d348988026..1a6e36353407 100644
@@ -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