libbpf: Don't return -EINVAL if hdr_len < offsetofend(core_relo_len)
authorYuntao Wang <ytcoode@gmail.com>
Mon, 4 Apr 2022 00:53:20 +0000 (08:53 +0800)
committerAndrii Nakryiko <andrii@kernel.org>
Mon, 4 Apr 2022 02:56:01 +0000 (19:56 -0700)
Since core relos is an optional part of the .BTF.ext ELF section, we should
skip parsing it instead of returning -EINVAL if header size is less than
offsetofend(struct btf_ext_header, core_relo_len).

Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20220404005320.1723055-1-ytcoode@gmail.com
tools/lib/bpf/btf.c

index 1383e26c5d1f131e44480425f5fbcec26e77f029..d124e9e533f019f96b82486988c244b9b8e91ad9 100644 (file)
@@ -2826,10 +2826,8 @@ struct btf_ext *btf_ext__new(const __u8 *data, __u32 size)
        if (err)
                goto done;
 
-       if (btf_ext->hdr->hdr_len < offsetofend(struct btf_ext_header, core_relo_len)) {
-               err = -EINVAL;
-               goto done;
-       }
+       if (btf_ext->hdr->hdr_len < offsetofend(struct btf_ext_header, core_relo_len))
+               goto done; /* skip core relos parsing */
 
        err = btf_ext_setup_core_relos(btf_ext);
        if (err)