mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-30 12:13:51 -04:00
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>
This commit is contained in:
committed by
Namhyung Kim
parent
01765b456f
commit
60f2f5b765
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user