diff options
author | He Zhe <zhe.he@windriver.com> | 2019-08-02 04:29:52 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2019-08-08 14:41:10 -0400 |
commit | 5f5e25f1c7933a6e1673515c0b1d5acd82fea1ed (patch) | |
tree | e4d1b719ffea2b873448060a191da46c85f34dea /tools | |
parent | cf30ae726c011e0372fd4c2d588466c8b50a8907 (diff) |
perf cpumap: Fix writing to illegal memory in handling cpumap mask
cpu_map__snprint_mask() would write to illegal memory pointed by
zalloc(0) when there is only one cpu.
This patch fixes the calculation and adds sanity check against the input
parameters.
Signed-off-by: He Zhe <zhe.he@windriver.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Fixes: 4400ac8a9a90 ("perf cpumap: Introduce cpu_map__snprint_mask()")
Link: http://lkml.kernel.org/r/1564734592-15624-2-git-send-email-zhe.he@windriver.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/util/cpumap.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 3acfbe34ebaf..39cce66b4ebc 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c | |||
@@ -751,7 +751,10 @@ size_t cpu_map__snprint_mask(struct cpu_map *map, char *buf, size_t size) | |||
751 | unsigned char *bitmap; | 751 | unsigned char *bitmap; |
752 | int last_cpu = cpu_map__cpu(map, map->nr - 1); | 752 | int last_cpu = cpu_map__cpu(map, map->nr - 1); |
753 | 753 | ||
754 | bitmap = zalloc((last_cpu + 7) / 8); | 754 | if (buf == NULL) |
755 | return 0; | ||
756 | |||
757 | bitmap = zalloc(last_cpu / 8 + 1); | ||
755 | if (bitmap == NULL) { | 758 | if (bitmap == NULL) { |
756 | buf[0] = '\0'; | 759 | buf[0] = '\0'; |
757 | return 0; | 760 | return 0; |