bpf, btf: Check btf for register_bpf_struct_ops
authorGeliang Tang <tanggeliang@kylinos.cn>
Thu, 8 Feb 2024 06:24:23 +0000 (14:24 +0800)
committerMartin KaFai Lau <martin.lau@kernel.org>
Thu, 8 Feb 2024 19:37:49 +0000 (11:37 -0800)
Similar to the handling in the functions __register_btf_kfunc_id_set()
and register_btf_id_dtor_kfuncs(), this patch uses the newly added
helper check_btf_kconfigs() to handle module with its btf section
stripped.

While at it, the patch also adds the missed IS_ERR() check to fix the
commit f6be98d19985 ("bpf, net: switch to dynamic registration")

Fixes: f6be98d19985 ("bpf, net: switch to dynamic registration")
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Link: https://lore.kernel.org/r/69082b9835463fe36f9e354bddf2d0a97df39c2b.1707373307.git.tanggeliang@kylinos.cn
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
kernel/bpf/btf.c

index 61e51cf0a9956fff870ee8b6c65508cc4655c9b8..8e06d29961f1a4ff615b0c071cd12196f3b57bb2 100644 (file)
@@ -8882,7 +8882,9 @@ int __register_bpf_struct_ops(struct bpf_struct_ops *st_ops)
 
        btf = btf_get_module_btf(st_ops->owner);
        if (!btf)
-               return -EINVAL;
+               return check_btf_kconfigs(st_ops->owner, "struct_ops");
+       if (IS_ERR(btf))
+               return PTR_ERR(btf);
 
        log = kzalloc(sizeof(*log), GFP_KERNEL | __GFP_NOWARN);
        if (!log) {