bpf: require CAP_NET_ADMIN when using devmap
authorJohn Fastabend <john.fastabend@gmail.com>
Wed, 18 Oct 2017 14:11:44 +0000 (07:11 -0700)
committerDavid S. Miller <davem@davemloft.net>
Fri, 20 Oct 2017 12:01:29 +0000 (13:01 +0100)
Devmap is used with XDP which requires CAP_NET_ADMIN so lets also
make CAP_NET_ADMIN required to use the map.

Signed-off-by: John Fastabend <john.fastabend@gmail.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
kernel/bpf/devmap.c

index 920428d84da23c224035bb82172c425e7aa0efae..52e0548ba548713b4e152b688f5597dcf91f2f88 100644 (file)
@@ -78,6 +78,9 @@ static struct bpf_map *dev_map_alloc(union bpf_attr *attr)
        int err = -EINVAL;
        u64 cost;
 
+       if (!capable(CAP_NET_ADMIN))
+               return ERR_PTR(-EPERM);
+
        /* check sanity of attributes */
        if (attr->max_entries == 0 || attr->key_size != 4 ||
            attr->value_size != 4 || attr->map_flags & ~BPF_F_NUMA_NODE)