]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
perf cgroup: Update metric leader in evlist__expand_cgroup
authorIan Rogers <irogers@google.com>
Sat, 4 Apr 2026 06:05:52 +0000 (23:05 -0700)
committerNamhyung Kim <namhyung@kernel.org>
Mon, 6 Apr 2026 06:23:33 +0000 (23:23 -0700)
commitc9ef786c0970991578397043f1c819229e2b7197
treeb09d783b040faabdacf4c1a833bfda6e2c5c506e
parentaeae075a0352eb6ab363fb1910f209eaa296a175
perf cgroup: Update metric leader in evlist__expand_cgroup

When the evlist is expanded the metric leader wasn't being updated. As
the original evsel is deleted this creates a use-after-free in
stat-shadow's prepare_metric. This was detected running the "perf stat
--bpf-counters --for-each-cgroup test" with sanitizers.

The change itself puts the copied evsel into the priv field (known
unused because of evsel__clone use) and then in a second pass over the
list updates the copied values using the priv pointer.

Fixes: d1c5a0e86a4e ("perf stat: Add --for-each-cgroup option")
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Sun Jian <sun.jian.kdev@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/util/cgroup.c