提交 396d465c 编写于 作者: A Andrii Nakryiko 提交者: Zheng Zengkai

libbpf: Validate that .BTF and .BTF.ext sections contain data

mainline inclusion
from mainline-5.17-rc1
commit 62554d52
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=62554d52e71797eefa3fc15b54008038837bb2d4

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

.BTF and .BTF.ext ELF sections should have SHT_PROGBITS type and contain
data. If they are not, ELF is invalid or corrupted, so bail out.
Otherwise this can lead to data->d_buf being NULL and SIGSEGV later on.
Reported by oss-fuzz project.
Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
Acked-by: NYonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20211103173213.1376990-4-andrii@kernel.org
(cherry picked from commit 62554d52)
Signed-off-by: NWang Yufen <wangyufen@huawei.com>
上级 ab788aaa
...@@ -3228,8 +3228,12 @@ static int bpf_object__elf_collect(struct bpf_object *obj) ...@@ -3228,8 +3228,12 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
} else if (strcmp(name, MAPS_ELF_SEC) == 0) { } else if (strcmp(name, MAPS_ELF_SEC) == 0) {
obj->efile.btf_maps_shndx = idx; obj->efile.btf_maps_shndx = idx;
} else if (strcmp(name, BTF_ELF_SEC) == 0) { } else if (strcmp(name, BTF_ELF_SEC) == 0) {
if (sh->sh_type != SHT_PROGBITS)
return -LIBBPF_ERRNO__FORMAT;
btf_data = data; btf_data = data;
} else if (strcmp(name, BTF_EXT_ELF_SEC) == 0) { } else if (strcmp(name, BTF_EXT_ELF_SEC) == 0) {
if (sh->sh_type != SHT_PROGBITS)
return -LIBBPF_ERRNO__FORMAT;
btf_ext_data = data; btf_ext_data = data;
} else if (sh->sh_type == SHT_SYMTAB) { } else if (sh->sh_type == SHT_SYMTAB) {
/* already processed during the first pass above */ /* already processed during the first pass above */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册