summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2026-08-02 11:27:10 -0300
committerNamhyung Kim <namhyung@kernel.org>2026-08-05 11:20:02 -0700
commit60f2f5b7650bb8779af3087ef429fad4ed74a5c8 (patch)
treeac3df4cde0fba1cefd9ed0afecc75f4c54230ed9 /tools
parent01765b456f850aed7475b37111f1c50bf76aaf51 (diff)
perf header: Use write lock when translating BPF prog info pointers
write_bpf_prog_info() holds a read lock while temporarily mutating info_linear via bpil_addr_to_offs()/bpil_offs_to_addr(). Between these two calls, the pointers in info_linear contain file offsets instead of heap addresses. Concurrent readers holding the same read lock see the file offsets and dereference them as pointers. Use down_write()/up_write() instead of down_read()/up_read() to exclude concurrent readers during the addr-to-offset-to-addr translation window. Fixes: 63ac7968a1fb ("perf bpf: Save bpf_prog_info information as headers to perf.data") Reported-by: sashiko-bot <sashiko-bot@kernel.org> Cc: Song Liu <songliubraving@fb.com> Reviewed-by: Ian Rogers <irogers@google.com> Assisted-by: Claude:claude-opus-4.6 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/util/header.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index e90e541f546b..7db7da090a1e 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1120,7 +1120,8 @@ static int write_bpf_prog_info(struct feat_fd *ff __maybe_unused,
struct rb_node *next;
int ret = 0;
- down_read(&env->bpf_progs.lock);
+ /* write lock: bpil_addr_to_offs() temporarily mutates info_linear */
+ down_write(&env->bpf_progs.lock);
ret = do_write(ff, &env->bpf_progs.infos_cnt,
sizeof(env->bpf_progs.infos_cnt));
@@ -1150,7 +1151,7 @@ static int write_bpf_prog_info(struct feat_fd *ff __maybe_unused,
goto out;
}
out:
- up_read(&env->bpf_progs.lock);
+ up_write(&env->bpf_progs.lock);
return ret;
#else
pr_err("ERROR: Trying to write bpf_prog_info without libbpf support.\n");