Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Always bail out when config_attr function fails

Not sure why we allowed the fail state, but it's wrong. Wrong type for
'name' term can cause segfault, and there's probably more fun hidden.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1429729824-13932-4-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
c056ba6a 6297d423

+11 -4
+11 -4
tools/perf/util/parse-events.c
··· 549 549 } while (0) 550 550 551 551 switch (term->type_term) { 552 + case PARSE_EVENTS__TERM_TYPE_USER: 553 + /* 554 + * Always succeed for sysfs terms, as we dont know 555 + * at this point what type they need to have. 556 + */ 557 + return 0; 552 558 case PARSE_EVENTS__TERM_TYPE_CONFIG: 553 559 CHECK_TYPE_VAL(NUM); 554 560 attr->config = term->val.num; ··· 589 583 } 590 584 591 585 static int config_attr(struct perf_event_attr *attr, 592 - struct list_head *head, int fail) 586 + struct list_head *head) 593 587 { 594 588 struct parse_events_term *term; 595 589 596 590 list_for_each_entry(term, head, list) 597 - if (config_term(attr, term) && fail) 591 + if (config_term(attr, term)) 598 592 return -EINVAL; 599 593 600 594 return 0; ··· 611 605 attr.config = config; 612 606 613 607 if (head_config && 614 - config_attr(&attr, head_config, 1)) 608 + config_attr(&attr, head_config)) 615 609 return -EINVAL; 616 610 617 611 return add_event(list, idx, &attr, NULL); ··· 665 659 * Configure hardcoded terms first, no need to check 666 660 * return value when called with fail == 0 ;) 667 661 */ 668 - config_attr(&attr, head_config, 0); 662 + if (config_attr(&attr, head_config)) 663 + return -EINVAL; 669 664 670 665 if (perf_pmu__config(pmu, &attr, head_config)) 671 666 return -EINVAL;