提交 2c4f6619 编写于 作者: A Andrii Nakryiko 提交者: Zheng Zengkai

libbpf: Fix logic for finding matching program for CO-RE relocation

mainline inclusion
from mainline-5.19-rc1
commit 966a7509
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5EUVD
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=966a7509325395c51c5f6d89e7352b0585e4804b

-------------------------------------------------

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: 9c82a63c ("libbpf: Fix CO-RE relocs against .text section")
Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20220426004511.2691730-4-andrii@kernel.org
(cherry picked from commit 966a7509)
Signed-off-by: NWang Yufen <wangyufen@huawei.com>
上级 b2c1cb0a
......@@ -5590,9 +5590,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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册