]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
libbpf: Ensure new BTF objects inherit input endianness
authorTony Ambardar <tony.ambardar@gmail.com>
Fri, 30 Aug 2024 09:51:50 +0000 (02:51 -0700)
committerAndrii Nakryiko <andrii@kernel.org>
Fri, 30 Aug 2024 17:41:01 +0000 (10:41 -0700)
New split BTF needs to preserve base's endianness. Similarly, when
creating a distilled BTF, we need to preserve original endianness.

Fix by updating libbpf's btf__distill_base() and btf_new_empty() to retain
the byte order of any source BTF objects when creating new ones.

Fixes: ba451366bf44 ("libbpf: Implement basic split BTF support")
Fixes: 58e185a0dc35 ("libbpf: Add btf__distill_base() creating split BTF with distilled base BTF")
Reported-by: Song Liu <song@kernel.org>
Reported-by: Eduard Zingerman <eddyz87@gmail.com>
Suggested-by: Eduard Zingerman <eddyz87@gmail.com>
Signed-off-by: Tony Ambardar <tony.ambardar@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Tested-by: Alan Maguire <alan.maguire@oracle.com>
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/bpf/6358db36c5f68b07873a0a5be2d062b1af5ea5f8.camel@gmail.com/
Link: https://lore.kernel.org/bpf/20240830095150.278881-1-tony.ambardar@gmail.com
tools/lib/bpf/btf.c

index 32c00db3b91b9d1e91c8a0cb71fa2c263bcc459e..40aae244e35f7aa71c18f623519b2985a92f0b0d 100644 (file)
@@ -996,6 +996,7 @@ static struct btf *btf_new_empty(struct btf *base_btf)
                btf->base_btf = base_btf;
                btf->start_id = btf__type_cnt(base_btf);
                btf->start_str_off = base_btf->hdr->str_len;
+               btf->swapped_endian = base_btf->swapped_endian;
        }
 
        /* +1 for empty string at offset 0 */
@@ -5394,6 +5395,9 @@ int btf__distill_base(const struct btf *src_btf, struct btf **new_base_btf,
        new_base = btf__new_empty();
        if (!new_base)
                return libbpf_err(-ENOMEM);
+
+       btf__set_endianness(new_base, btf__endianness(src_btf));
+
        dist.id_map = calloc(n, sizeof(*dist.id_map));
        if (!dist.id_map) {
                err = -ENOMEM;