perf bpf-utils: Harden get_bpf_prog_info_linear
authorIan Rogers <irogers@google.com>
Tue, 2 Sep 2025 18:17:13 +0000 (11:17 -0700)
committerNamhyung Kim <namhyung@kernel.org>
Tue, 2 Sep 2025 21:55:32 +0000 (14:55 -0700)
commit01be43f2a0eaeed83e94dee054742f37625c86d9
tree91f1796daaa4780465347395909d358118efaf21
parent1654a0e4d576d9e43fbb10ccf6a1b307c5c18566
perf bpf-utils: Harden get_bpf_prog_info_linear

In get_bpf_prog_info_linear two calls to bpf_obj_get_info_by_fd are
made, the first to compute memory requirements for a struct perf_bpil
and the second to fill it in. Previously the code would warn when the
second call didn't match the first. Such races can be common place in
things like perf test, whose perf trace tests will frequently load BPF
programs. Rather than a debug message, return actual errors for this
case. Out of paranoia also validate the read bpf_prog_info array
value. Change the type of ptr to avoid mismatched pointer type
compiler warnings. Add some additional debug print outs and sanity
asserts.

Closes: https://lore.kernel.org/lkml/CAP-5=fWJQcmUOP7MuCA2ihKnDAHUCOBLkQFEkQES-1ZZTrgf8Q@mail.gmail.com/
Fixes: 6ac22d036f86 ("perf bpf: Pull in bpf_program__get_prog_info_linear()")
Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20250902181713.309797-4-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/util/bpf-utils.c