Skip to content

Commit 5db6357

Browse files
He Zhegregkh
authored andcommitted
perf cpumap: Fix writing to illegal memory in handling cpumap mask
[ Upstream commit 5f5e25f ] 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]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 5411aef commit 5db6357

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
@@ -701,7 +701,10 @@ size_t cpu_map__snprint_mask(struct cpu_map *map, char *buf, size_t size)
701701
unsigned char *bitmap;
702702
int last_cpu = cpu_map__cpu(map, map->nr - 1);
703703

704-
bitmap = zalloc((last_cpu + 7) / 8);
704+
if (buf == NULL)
705+
return 0;
706+
707+
bitmap = zalloc(last_cpu / 8 + 1);
705708
if (bitmap == NULL) {
706709
buf[0] = '\0';
707710
return 0;

0 commit comments

Comments
 (0)