libbpf: handle nulled-out program in struct_ops correctly
authorAndrii Nakryiko <andrii@kernel.org>
Sun, 28 Apr 2024 03:09:53 +0000 (20:09 -0700)
committerMartin KaFai Lau <martin.lau@kernel.org>
Mon, 29 Apr 2024 23:46:06 +0000 (16:46 -0700)
If struct_ops has one of program callbacks set declaratively and host
kernel is old and doesn't support this callback, libbpf will allow to
load such struct_ops as long as that callback was explicitly nulled-out
(presumably through skeleton). This is all working correctly, except we
won't reset corresponding program slot to NULL before bailing out, which
will lead to libbpf not detecting that BPF program has to be not
auto-loaded. Fix this by unconditionally resetting corresponding program
slot to NULL.

Fixes: c911fc61a7ce ("libbpf: Skip zeroed or null fields if not found in the kernel type.")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20240428030954.3918764-1-andrii@kernel.org
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
tools/lib/bpf/libbpf.c

index 97eb6e5dd7c8bdabd0c63cd815a49935642c2f1d..898d5d34ecea32221a4fcf9466886c1cb27b348f 100644 (file)
@@ -1148,6 +1148,7 @@ static int bpf_map__init_kern_struct_ops(struct bpf_map *map)
                         * presented in the kernel BTF.
                         */
                        if (libbpf_is_mem_zeroed(mdata, msize)) {
+                               st_ops->progs[i] = NULL;
                                pr_info("struct_ops %s: member %s not found in kernel, skipping it as it's set to zero\n",
                                        map->name, mname);
                                continue;