Skip to content

Commit 6bfb4c5

Browse files
captain5050acmel
authored andcommitted
perf test cpumap: Avoid use-after-free following merge
Previously cpu maps in the test weren't modified by calls to the cpu map API, however, perf_cpu_map__merge was modified so the left hand argument was updated. In the test this meant the maps copy of the "two" map was put/deleted in the merge meaning when accessed via maps, the pointer was stale and to the put/deleted memory. To fix this add an extra layer of indirection to the maps array, so the updated value of two is accessed. Fixes: a9d2217 ("libperf cpumap: Refactor perf_cpu_map__merge()") Reviewed-by: James Clark <[email protected]> Signed-off-by: Ian Rogers <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kan Liang <[email protected]> Cc: Leo Yan <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 9c64c7c commit 6bfb4c5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

tools/perf/tests/cpumap.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,16 +252,16 @@ static int test__cpu_map_equal(struct test_suite *test __maybe_unused, int subte
252252
struct perf_cpu_map *empty = perf_cpu_map__intersect(one, two);
253253
struct perf_cpu_map *pair = perf_cpu_map__new("1-2");
254254
struct perf_cpu_map *tmp;
255-
struct perf_cpu_map *maps[] = {empty, any, one, two, pair};
255+
struct perf_cpu_map **maps[] = {&empty, &any, &one, &two, &pair};
256256

257257
for (size_t i = 0; i < ARRAY_SIZE(maps); i++) {
258258
/* Maps equal themself. */
259-
TEST_ASSERT_VAL("equal", perf_cpu_map__equal(maps[i], maps[i]));
259+
TEST_ASSERT_VAL("equal", perf_cpu_map__equal(*maps[i], *maps[i]));
260260
for (size_t j = 0; j < ARRAY_SIZE(maps); j++) {
261261
/* Maps dont't equal each other. */
262262
if (i == j)
263263
continue;
264-
TEST_ASSERT_VAL("not equal", !perf_cpu_map__equal(maps[i], maps[j]));
264+
TEST_ASSERT_VAL("not equal", !perf_cpu_map__equal(*maps[i], *maps[j]));
265265
}
266266
}
267267

@@ -274,7 +274,7 @@ static int test__cpu_map_equal(struct test_suite *test __maybe_unused, int subte
274274
perf_cpu_map__put(tmp);
275275

276276
for (size_t i = 0; i < ARRAY_SIZE(maps); i++)
277-
perf_cpu_map__put(maps[i]);
277+
perf_cpu_map__put(*maps[i]);
278278

279279
return TEST_OK;
280280
}

0 commit comments

Comments
 (0)