Skip to content

Commit 5f5e25f

Browse files
He Zheacmel
authored andcommitted
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 <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Alexey Budankov <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kan Liang <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Fixes: 4400ac8 ("perf cpumap: Introduce cpu_map__snprint_mask()") Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent cf30ae7 commit 5f5e25f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

tools/perf/util/cpumap.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,10 @@ size_t cpu_map__snprint_mask(struct cpu_map *map, char *buf, size_t size)
751751
unsigned char *bitmap;
752752
int last_cpu = cpu_map__cpu(map, map->nr - 1);
753753

754-
bitmap = zalloc((last_cpu + 7) / 8);
754+
if (buf == NULL)
755+
return 0;
756+
757+
bitmap = zalloc(last_cpu / 8 + 1);
755758
if (bitmap == NULL) {
756759
buf[0] = '\0';
757760
return 0;

0 commit comments

Comments
 (0)