]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
bpf: Remember BTF of inner maps.
authorAlexei Starovoitov <ast@kernel.org>
Thu, 15 Jul 2021 00:54:12 +0000 (17:54 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 15 Jul 2021 20:31:10 +0000 (22:31 +0200)
BTF is required for 'struct bpf_timer' to be recognized inside map value.
The bpf timers are supported inside inner maps.
Remember 'struct btf *' in inner_map_meta to make it available
to the verifier in the sequence:

struct bpf_map *inner_map = bpf_map_lookup_elem(&outer_map, ...);
if (inner_map)
    timer = bpf_map_lookup_elem(&inner_map, ...);

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Yonghong Song <yhs@fb.com>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Toke Høiland-Jørgensen <toke@redhat.com>
Link: https://lore.kernel.org/bpf/20210715005417.78572-7-alexei.starovoitov@gmail.com
kernel/bpf/map_in_map.c

index 890dfe14e7310835e276695cc6febc6fd22b4551..5cd8f52772790992aee5205ebc63966fcdcd89bf 100644 (file)
@@ -3,6 +3,7 @@
  */
 #include <linux/slab.h>
 #include <linux/bpf.h>
+#include <linux/btf.h>
 
 #include "map_in_map.h"
 
@@ -51,6 +52,10 @@ struct bpf_map *bpf_map_meta_alloc(int inner_map_ufd)
        inner_map_meta->max_entries = inner_map->max_entries;
        inner_map_meta->spin_lock_off = inner_map->spin_lock_off;
        inner_map_meta->timer_off = inner_map->timer_off;
+       if (inner_map->btf) {
+               btf_get(inner_map->btf);
+               inner_map_meta->btf = inner_map->btf;
+       }
 
        /* Misc members not needed in bpf_map_meta_equal() check. */
        inner_map_meta->ops = inner_map->ops;
@@ -66,6 +71,7 @@ struct bpf_map *bpf_map_meta_alloc(int inner_map_ufd)
 
 void bpf_map_meta_free(struct bpf_map *map_meta)
 {
+       btf_put(map_meta->btf);
        kfree(map_meta);
 }