提交 2b969b41 编写于 作者: T Toke Høiland-Jørgensen 提交者: Zheng Zengkai

libbpf: Ignore STT_SECTION symbols in 'maps' section

mainline inclusion
from mainline-5.16-rc1
commit c3e8c44a
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=c3e8c44a90631d2479fec6ecc6ba37e3188f487d

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

When parsing legacy map definitions, libbpf would error out when
encountering an STT_SECTION symbol. This becomes a problem because some
versions of binutils will produce SECTION symbols for every section when
processing an ELF file, so BPF files run through 'strip' will end up with
such symbols, making libbpf refuse to load them.

There's not really any reason why erroring out is strictly necessary, so
change libbpf to just ignore SECTION symbols when parsing the ELF.
Signed-off-by: NToke Høiland-Jørgensen <toke@redhat.com>
Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210927205810.715656-1-toke@redhat.com
(cherry picked from commit c3e8c44a)
Signed-off-by: NWang Yufen <wangyufen@huawei.com>
上级 f1dc7899
...@@ -1867,6 +1867,8 @@ static int bpf_object__init_user_maps(struct bpf_object *obj, bool strict) ...@@ -1867,6 +1867,8 @@ static int bpf_object__init_user_maps(struct bpf_object *obj, bool strict)
continue; continue;
if (sym.st_shndx != obj->efile.maps_shndx) if (sym.st_shndx != obj->efile.maps_shndx)
continue; continue;
if (GELF_ST_TYPE(sym.st_info) == STT_SECTION)
continue;
map = bpf_object__add_map(obj); map = bpf_object__add_map(obj);
if (IS_ERR(map)) if (IS_ERR(map))
...@@ -1879,8 +1881,7 @@ static int bpf_object__init_user_maps(struct bpf_object *obj, bool strict) ...@@ -1879,8 +1881,7 @@ static int bpf_object__init_user_maps(struct bpf_object *obj, bool strict)
return -LIBBPF_ERRNO__FORMAT; return -LIBBPF_ERRNO__FORMAT;
} }
if (GELF_ST_TYPE(sym.st_info) == STT_SECTION if (GELF_ST_BIND(sym.st_info) == STB_LOCAL) {
|| GELF_ST_BIND(sym.st_info) == STB_LOCAL) {
pr_warn("map '%s' (legacy): static maps are not supported\n", map_name); pr_warn("map '%s' (legacy): static maps are not supported\n", map_name);
return -ENOTSUP; return -ENOTSUP;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册