Skip to content

Commit

Permalink
libbpf: Fix logic for finding matching program for CO-RE relocation
Browse files Browse the repository at this point in the history
[ Upstream commit 966a750 ]

Fix the bug in bpf_object__relocate_core() which can lead to finding
invalid matching BPF program when processing CO-RE relocation. IF
matching program is not found, last encountered program will be assumed
to be correct program and thus error detection won't detect the problem.

Fixes: 9c82a63 ("libbpf: Fix CO-RE relocs against .text section")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20220426004511.2691730-4-andrii@kernel.org
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
anakryiko authored and gregkh committed Jun 9, 2022
1 parent 97b56f1 commit ab88c8d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tools/lib/bpf/libbpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -5928,9 +5928,10 @@ bpf_object__relocate_core(struct bpf_object *obj, const char *targ_btf_path)
*/
prog = NULL;
for (i = 0; i < obj->nr_programs; i++) {
prog = &obj->programs[i];
if (strcmp(prog->sec_name, sec_name) == 0)
if (strcmp(obj->programs[i].sec_name, sec_name) == 0) {
prog = &obj->programs[i];
break;
}
}
if (!prog) {
pr_warn("sec '%s': failed to find a BPF program\n", sec_name);
Expand Down

0 comments on commit ab88c8d

Please sign in to comment.