libbpf: only reset sec_def handler when necessary
authorAndrii Nakryiko <andrii@kernel.org>
Fri, 7 Jul 2023 23:11:56 +0000 (16:11 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Sun, 9 Jul 2023 01:29:53 +0000 (18:29 -0700)
commitc628747cc8800cf6d33d09f7f42c8b6f91e64dc7
tree73fdc51650ffd450e906045b5851d0f8f419ffe1
parent856fe03d929205b4c8c8fa51296342cd85592e3f
libbpf: only reset sec_def handler when necessary

Don't reset recorded sec_def handler unconditionally on
bpf_program__set_type(). There are two situations where this is wrong.

First, if the program type didn't actually change. In that case original
SEC handler should work just fine.

Second, catch-all custom SEC handler is supposed to work with any BPF
program type and SEC() annotation, so it also doesn't make sense to
reset that.

This patch fixes both issues. This was reported recently in the context
of breaking perf tool, which uses custom catch-all handler for fancy BPF
prologue generation logic. This patch should fix the issue.

  [0] https://lore.kernel.org/linux-perf-users/ab865e6d-06c5-078e-e404-7f90686db50d@amd.com/

Fixes: d6e6286a12e7 ("libbpf: disassociate section handler on explicit bpf_program__set_type() call")
Reported-by: Ravi Bangoria <ravi.bangoria@amd.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Stanislav Fomichev <sdf@google.com>
Link: https://lore.kernel.org/r/20230707231156.1711948-1-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/lib/bpf/libbpf.c