Skip to content

Commit a316338

Browse files
borkmanndavem330
authored andcommitted
bpf: fix wrong exposure of map_flags into fdinfo for lpm
trie_alloc() always needs to have BPF_F_NO_PREALLOC passed in via attr->map_flags, since it does not support preallocation yet. We check the flag, but we never copy the flag into trie->map.map_flags, which is later on exposed into fdinfo and used by loaders such as iproute2. Latter uses this in bpf_map_selfcheck_pinned() to test whether a pinned map has the same spec as the one from the BPF obj file and if not, bails out, which is currently the case for lpm since it exposes always 0 as flags. Also copy over flags in array_map_alloc() and stack_map_alloc(). They always have to be 0 right now, but we should make sure to not miss to copy them over at a later point in time when we add actual flags for them to use. Fixes: b95a5c4 ("bpf: add a longest prefix match trie map implementation") Reported-by: Jarno Rajahalme <jarno@covalent.io> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 41703a7 commit a316338

File tree

3 files changed

+3
-0
lines changed

3 files changed

+3
-0
lines changed

kernel/bpf/arraymap.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ static struct bpf_map *array_map_alloc(union bpf_attr *attr)
8686
array->map.key_size = attr->key_size;
8787
array->map.value_size = attr->value_size;
8888
array->map.max_entries = attr->max_entries;
89+
array->map.map_flags = attr->map_flags;
8990
array->elem_size = elem_size;
9091

9192
if (!percpu)

kernel/bpf/lpm_trie.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ static struct bpf_map *trie_alloc(union bpf_attr *attr)
432432
trie->map.key_size = attr->key_size;
433433
trie->map.value_size = attr->value_size;
434434
trie->map.max_entries = attr->max_entries;
435+
trie->map.map_flags = attr->map_flags;
435436
trie->data_size = attr->key_size -
436437
offsetof(struct bpf_lpm_trie_key, data);
437438
trie->max_prefixlen = trie->data_size * 8;

kernel/bpf/stackmap.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ static struct bpf_map *stack_map_alloc(union bpf_attr *attr)
8888
smap->map.key_size = attr->key_size;
8989
smap->map.value_size = value_size;
9090
smap->map.max_entries = attr->max_entries;
91+
smap->map.map_flags = attr->map_flags;
9192
smap->n_buckets = n_buckets;
9293
smap->map.pages = round_up(cost, PAGE_SIZE) >> PAGE_SHIFT;
9394

0 commit comments

Comments
 (0)