]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
bpf: fix wrong exposure of map_flags into fdinfo for lpm
authorDaniel Borkmann <daniel@iogearbox.net>
Wed, 24 May 2017 23:05:08 +0000 (01:05 +0200)
committerDavid S. Miller <davem@davemloft.net>
Thu, 25 May 2017 17:44:28 +0000 (13:44 -0400)
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: b95a5c4db09b ("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>
kernel/bpf/arraymap.c
kernel/bpf/lpm_trie.c
kernel/bpf/stackmap.c

index 5e00b2333c26e3256a6f4dc51a2a58011a2c9db6..172dc8ee0e3bda95c39f7e037e7a33baf8012214 100644 (file)
@@ -86,6 +86,7 @@ static struct bpf_map *array_map_alloc(union bpf_attr *attr)
        array->map.key_size = attr->key_size;
        array->map.value_size = attr->value_size;
        array->map.max_entries = attr->max_entries;
+       array->map.map_flags = attr->map_flags;
        array->elem_size = elem_size;
 
        if (!percpu)
index 39cfafd895b80d2f0fb5054626af001949a8ad98..b09185f0f17d3428ac445de2ed52756004ca5368 100644 (file)
@@ -432,6 +432,7 @@ static struct bpf_map *trie_alloc(union bpf_attr *attr)
        trie->map.key_size = attr->key_size;
        trie->map.value_size = attr->value_size;
        trie->map.max_entries = attr->max_entries;
+       trie->map.map_flags = attr->map_flags;
        trie->data_size = attr->key_size -
                          offsetof(struct bpf_lpm_trie_key, data);
        trie->max_prefixlen = trie->data_size * 8;
index 4dfd6f2ec2f9725681f490971e60acc8033c64b6..31147d730abf532cc8f10efc9a871b5dd498928d 100644 (file)
@@ -88,6 +88,7 @@ static struct bpf_map *stack_map_alloc(union bpf_attr *attr)
        smap->map.key_size = attr->key_size;
        smap->map.value_size = value_size;
        smap->map.max_entries = attr->max_entries;
+       smap->map.map_flags = attr->map_flags;
        smap->n_buckets = n_buckets;
        smap->map.pages = round_up(cost, PAGE_SIZE) >> PAGE_SHIFT;