summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAdrian Hunter <adrian.hunter@intel.com>2013-10-22 03:34:18 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-10-23 10:06:03 -0400
commit2fbe4abe944868aafdde233557ac85379b60ce46 (patch)
tree7830890d701ac2d052e06ca9c7499410b3af60b1 /tools
parent56921becdd1eb0720603fc2e6e4c7f518196d917 (diff)
perf evlist: Validate that mmap_pages is not too big
Amend perf_evlist__parse_mmap_pages() to check that the mmap_pages entered via the --mmap_pages/-m option is not too big. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Namhyung Kim <namhyung@gmail.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/r/1382427258-17495-15-git-send-email-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/util/evlist.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 85c4c80bcac8..2ce92eceb424 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -698,7 +698,8 @@ static size_t perf_evlist__mmap_size(unsigned long pages)
698int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str, 698int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str,
699 int unset __maybe_unused) 699 int unset __maybe_unused)
700{ 700{
701 unsigned int pages, val, *mmap_pages = opt->value; 701 unsigned int *mmap_pages = opt->value;
702 unsigned long pages, val;
702 size_t size; 703 size_t size;
703 static struct parse_tag tags[] = { 704 static struct parse_tag tags[] = {
704 { .tag = 'B', .mult = 1 }, 705 { .tag = 'B', .mult = 1 },
@@ -709,12 +710,12 @@ int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str,
709 }; 710 };
710 711
711 val = parse_tag_value(str, tags); 712 val = parse_tag_value(str, tags);
712 if (val != (unsigned int) -1) { 713 if (val != (unsigned long) -1) {
713 /* we got file size value */ 714 /* we got file size value */
714 pages = PERF_ALIGN(val, page_size) / page_size; 715 pages = PERF_ALIGN(val, page_size) / page_size;
715 if (!is_power_of_2(pages)) { 716 if (pages < (1UL << 31) && !is_power_of_2(pages)) {
716 pages = next_pow2(pages); 717 pages = next_pow2(pages);
717 pr_info("rounding mmap pages size to %u (%u pages)\n", 718 pr_info("rounding mmap pages size to %lu (%lu pages)\n",
718 pages * page_size, pages); 719 pages * page_size, pages);
719 } 720 }
720 } else { 721 } else {
@@ -727,6 +728,11 @@ int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str,
727 } 728 }
728 } 729 }
729 730
731 if (pages > UINT_MAX || pages > SIZE_MAX / page_size) {
732 pr_err("--mmap_pages/-m value too big\n");
733 return -1;
734 }
735
730 size = perf_evlist__mmap_size(pages); 736 size = perf_evlist__mmap_size(pages);
731 if (!size) { 737 if (!size) {
732 pr_err("--mmap_pages/-m value must be a power of two."); 738 pr_err("--mmap_pages/-m value must be a power of two.");