Re: [PATCH bpf-next v3 3/6] libbpf: Resolve kfunc variants by prototype
From: bot+bpf-ci
Date: Tue Nov 24 2026 - 18:40:16 EST
> libbpf: Resolve kfunc variants by prototype
TL;DR: The stricter struct-name check in libbpf kfunc resolution may make
programs using UAPI aliases (e.g. struct __sk_buff in bpf_dynptr_from_skb)
fail to load with -EINVAL on v6.3-v6.10 kernels.
> diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
> --- a/tools/lib/bpf/btf.c
> +++ b/tools/lib/bpf/btf.c
[ ... ]
> +static int kfunc_type_match(const struct btf *a, __u32 a_id,
> + const struct btf *b, __u32 b_id, int depth)
> +{
[ ... ]
> + switch (kind) {
> + case BTF_KIND_STRUCT:
> + case BTF_KIND_UNION: {
> + const char *an = btf__name_by_offset(a, at->name_off);
> + const char *bn = btf__name_by_offset(b, bt->name_off);
> + size_t name_len = bpf_core_essential_name_len(an);
> +
> + return name_len == bpf_core_essential_name_len(bn) &&
> + strncmp(an, bn, name_len) == 0;
> + }
Can this break loading of existing programs on older kernels? Before this
patch, bpf_object__resolve_ksym_func_btf_id() used
bpf_core_types_are_compat(), which treats any two structs as compatible
without comparing names.
Until commit cce4c40b9606 ("bpf: treewide: Align kfunc signatures to
prog point-of-view"), several kfuncs were defined with kernel-facing
types, while BPF programs declared them with UAPI types:
-__bpf_kfunc int bpf_dynptr_from_skb(struct sk_buff *skb, u64 flags,
-__bpf_kfunc int bpf_dynptr_from_xdp(struct xdp_buff *xdp, u64 flags,
-__bpf_kfunc int bpf_dynptr_adjust(struct bpf_dynptr_kern *ptr, u32 start, u32 end)
-__bpf_kfunc int bpf_verify_pkcs7_signature(struct bpf_dynptr_kern *data_ptr,
and tools/testing/selftests/bpf/bpf_kfuncs.h still has:
extern int bpf_dynptr_from_skb(struct __sk_buff *skb, __u64 flags,
struct bpf_dynptr *ptr__uninit) __ksym;
The commit message of cce4c40b9606 says "It wasn't an issue before, as the
verifier allows aliased types." A vmlinux.h generated on v6.11 or later
declares them the same way.
On a v6.3 to v6.10 kernel, this now goes:
bpf_object__resolve_ksym_func_btf_id()
-> find_kfunc_btf_id(): one candidate, bpf_dynptr_from_skb
-> btf_kfunc_proto_match() -> kfunc_type_match(FUNC_PROTO)
-> param 0: PTR -> STRUCT "__sk_buff" vs STRUCT "sk_buff"
essential name lengths 9 != 7 -> return 0
-> nr_cands == 1, kfunc_id == 0 -> return -EINVAL
so bpf_object__load() fails with -EINVAL, where the old code resolved the
same declaration on the same kernel. For a __weak declaration the kfunc
now stays unresolved silently, so bpf_ksym_exists() is false on kernels
that do provide the kfunc.
The commit message says "a declaration with an outdated struct name no
longer resolves" and uses bpf_cpumask_populate() as the example. There the
kernel changed which type it accepts. Here the declaration is not
outdated: it uses the UAPI alias that the verifier accepts on those kernels.
Nothing later in the series (ea0b8db17e5e, 7848a838c614, 88fb7cd2ca9c)
seems to handle these aliases. Will existing binaries that load today on
still-supported LTS kernels start failing after a libbpf upgrade?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/45506767613