Commit 5f5e25f1 authored by He Zhe's avatar He Zhe Committed by Arnaldo Carvalho de Melo

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: default avatarHe 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: 4400ac8a ("perf cpumap: Introduce cpu_map__snprint_mask()")
Link: http://lkml.kernel.org/r/1564734592-15624-2-git-send-email-zhe.he@windriver.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent cf30ae72
...@@ -751,7 +751,10 @@ size_t cpu_map__snprint_mask(struct cpu_map *map, char *buf, size_t size) ...@@ -751,7 +751,10 @@ size_t cpu_map__snprint_mask(struct cpu_map *map, char *buf, size_t size)
unsigned char *bitmap; unsigned char *bitmap;
int last_cpu = cpu_map__cpu(map, map->nr - 1); int last_cpu = cpu_map__cpu(map, map->nr - 1);
bitmap = zalloc((last_cpu + 7) / 8); if (buf == NULL)
return 0;
bitmap = zalloc(last_cpu / 8 + 1);
if (bitmap == NULL) { if (bitmap == NULL) {
buf[0] = '\0'; buf[0] = '\0';
return 0; return 0;
......
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