提交 35a85550 编写于 作者: S Shung-Hsi Yu 提交者: Andrii Nakryiko

libbpf: Deal with section with no data gracefully

ELF section data pointer returned by libelf may be NULL (if section has
SHT_NOBITS), so null check section data pointer before attempting to
copy license and kversion section.

Fixes: cb1e5e96 ("bpf tools: Collect version and license from ELF sections")
Signed-off-by: NShung-Hsi Yu <shung-hsi.yu@suse.com>
Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20221012022353.7350-3-shung-hsi.yu@suse.com
上级 51deedc9
...@@ -1408,6 +1408,10 @@ static int bpf_object__check_endianness(struct bpf_object *obj) ...@@ -1408,6 +1408,10 @@ static int bpf_object__check_endianness(struct bpf_object *obj)
static int static int
bpf_object__init_license(struct bpf_object *obj, void *data, size_t size) bpf_object__init_license(struct bpf_object *obj, void *data, size_t size)
{ {
if (!data) {
pr_warn("invalid license section in %s\n", obj->path);
return -LIBBPF_ERRNO__FORMAT;
}
/* libbpf_strlcpy() only copies first N - 1 bytes, so size + 1 won't /* libbpf_strlcpy() only copies first N - 1 bytes, so size + 1 won't
* go over allowed ELF data section buffer * go over allowed ELF data section buffer
*/ */
...@@ -1421,7 +1425,7 @@ bpf_object__init_kversion(struct bpf_object *obj, void *data, size_t size) ...@@ -1421,7 +1425,7 @@ bpf_object__init_kversion(struct bpf_object *obj, void *data, size_t size)
{ {
__u32 kver; __u32 kver;
if (size != sizeof(kver)) { if (!data || size != sizeof(kver)) {
pr_warn("invalid kver section in %s\n", obj->path); pr_warn("invalid kver section in %s\n", obj->path);
return -LIBBPF_ERRNO__FORMAT; return -LIBBPF_ERRNO__FORMAT;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册