Commit 2fbe4abe authored by Adrian Hunter's avatar Adrian Hunter Committed by Arnaldo Carvalho de Melo

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: default avatarAdrian 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.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 56921bec
...@@ -698,7 +698,8 @@ static size_t perf_evlist__mmap_size(unsigned long pages) ...@@ -698,7 +698,8 @@ static size_t perf_evlist__mmap_size(unsigned long pages)
int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str, int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str,
int unset __maybe_unused) int unset __maybe_unused)
{ {
unsigned int pages, val, *mmap_pages = opt->value; unsigned int *mmap_pages = opt->value;
unsigned long pages, val;
size_t size; size_t size;
static struct parse_tag tags[] = { static struct parse_tag tags[] = {
{ .tag = 'B', .mult = 1 }, { .tag = 'B', .mult = 1 },
...@@ -709,12 +710,12 @@ int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str, ...@@ -709,12 +710,12 @@ int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str,
}; };
val = parse_tag_value(str, tags); val = parse_tag_value(str, tags);
if (val != (unsigned int) -1) { if (val != (unsigned long) -1) {
/* we got file size value */ /* we got file size value */
pages = PERF_ALIGN(val, page_size) / page_size; pages = PERF_ALIGN(val, page_size) / page_size;
if (!is_power_of_2(pages)) { if (pages < (1UL << 31) && !is_power_of_2(pages)) {
pages = next_pow2(pages); pages = next_pow2(pages);
pr_info("rounding mmap pages size to %u (%u pages)\n", pr_info("rounding mmap pages size to %lu (%lu pages)\n",
pages * page_size, pages); pages * page_size, pages);
} }
} else { } else {
...@@ -727,6 +728,11 @@ int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str, ...@@ -727,6 +728,11 @@ int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str,
} }
} }
if (pages > UINT_MAX || pages > SIZE_MAX / page_size) {
pr_err("--mmap_pages/-m value too big\n");
return -1;
}
size = perf_evlist__mmap_size(pages); size = perf_evlist__mmap_size(pages);
if (!size) { if (!size) {
pr_err("--mmap_pages/-m value must be a power of two."); pr_err("--mmap_pages/-m value must be a power of two.");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment