summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorHe Zhe <zhe.he@windriver.com>2019-08-02 16:29:52 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-08-29 08:30:18 +0200
commit40db83cb0c861f4cb64b7c2bf5baccca834bea39 (patch)
tree097e6047121af6fd71b768b17615e77883a1db74 /tools
parentdcd75c90dec1d69d22211bdf5d0faf03fd51b9b7 (diff)
downloadlinux-stable-40db83cb0c861f4cb64b7c2bf5baccca834bea39.tar.gz
linux-stable-40db83cb0c861f4cb64b7c2bf5baccca834bea39.tar.bz2
linux-stable-40db83cb0c861f4cb64b7c2bf5baccca834bea39.zip
perf cpumap: Fix writing to illegal memory in handling cpumap mask
[ Upstream commit 5f5e25f1c7933a6e1673515c0b1d5acd82fea1ed ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/util/cpumap.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index 0b599229bc7e..0aba5b39c21e 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -701,7 +701,10 @@ size_t cpu_map__snprint_mask(struct cpu_map *map, char *buf, size_t size)
unsigned char *bitmap;
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) {
buf[0] = '\0';
return 0;