From: James Clark <james.clark@linaro.org>
To: Ian Rogers <irogers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
Kan Liang <kan.liang@linux.intel.com>, Leo Yan <leo.yan@arm.com>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1] perf test cpumap: Avoid use-after-free following merge
Date: Wed, 8 Jan 2025 15:07:53 +0000 [thread overview]
Message-ID: <ac163e57-1bf8-4662-920c-9dbfecb26c06@linaro.org> (raw)
In-Reply-To: <20250108051511.1720369-1-irogers@google.com>
On 08/01/2025 5:15 am, Ian Rogers wrote:
> 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: a9d2217556f7 ("libperf cpumap: Refactor perf_cpu_map__merge()")
> Signed-off-by: Ian Rogers <irogers@google.com>
Reviewed-by: James Clark <james.clark@linaro.org>
> ---
> tools/perf/tests/cpumap.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/tools/perf/tests/cpumap.c b/tools/perf/tests/cpumap.c
> index 5ed7ff072ea3..2354246afc5a 100644
> --- a/tools/perf/tests/cpumap.c
> +++ b/tools/perf/tests/cpumap.c
> @@ -252,16 +252,16 @@ static int test__cpu_map_equal(struct test_suite *test __maybe_unused, int subte
> struct perf_cpu_map *empty = perf_cpu_map__intersect(one, two);
> struct perf_cpu_map *pair = perf_cpu_map__new("1-2");
> struct perf_cpu_map *tmp;
> - struct perf_cpu_map *maps[] = {empty, any, one, two, pair};
> + struct perf_cpu_map **maps[] = {&empty, &any, &one, &two, &pair};
>
> for (size_t i = 0; i < ARRAY_SIZE(maps); i++) {
> /* Maps equal themself. */
> - TEST_ASSERT_VAL("equal", perf_cpu_map__equal(maps[i], maps[i]));
> + TEST_ASSERT_VAL("equal", perf_cpu_map__equal(*maps[i], *maps[i]));
> for (size_t j = 0; j < ARRAY_SIZE(maps); j++) {
> /* Maps dont't equal each other. */
> if (i == j)
> continue;
> - TEST_ASSERT_VAL("not equal", !perf_cpu_map__equal(maps[i], maps[j]));
> + TEST_ASSERT_VAL("not equal", !perf_cpu_map__equal(*maps[i], *maps[j]));
> }
> }
>
> @@ -274,7 +274,7 @@ static int test__cpu_map_equal(struct test_suite *test __maybe_unused, int subte
> perf_cpu_map__put(tmp);
>
> for (size_t i = 0; i < ARRAY_SIZE(maps); i++)
> - perf_cpu_map__put(maps[i]);
> + perf_cpu_map__put(*maps[i]);
>
> return TEST_OK;
> }
next prev parent reply other threads:[~2025-01-08 15:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-08 5:15 Ian Rogers
2025-01-08 15:07 ` James Clark [this message]
2025-01-08 20:41 ` Arnaldo Carvalho de Melo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ac163e57-1bf8-4662-920c-9dbfecb26c06@linaro.org \
--to=james.clark@linaro.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=leo.yan@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®