diff options
author | Chenbo Feng <fengc@google.com> | 2017-10-18 16:00:22 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2017-10-20 08:32:59 -0400 |
commit | 6e71b04a82248ccf13a94b85cbc674a9fefe53f5 (patch) | |
tree | 45cab2ff677b04d921a2813738dc1ada8c07eaec /kernel/bpf/arraymap.c | |
parent | aec72f3392b1d598a979e89c4fdb131965ae0ab3 (diff) |
bpf: Add file mode configuration into bpf maps
Introduce the map read/write flags to the eBPF syscalls that returns the
map fd. The flags is used to set up the file mode when construct a new
file descriptor for bpf maps. To not break the backward capability, the
f_flags is set to O_RDWR if the flag passed by syscall is 0. Otherwise
it should be O_RDONLY or O_WRONLY. When the userspace want to modify or
read the map content, it will check the file mode to see if it is
allowed to make the change.
Signed-off-by: Chenbo Feng <fengc@google.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'kernel/bpf/arraymap.c')
-rw-r--r-- | kernel/bpf/arraymap.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c index 68d866628be0..988c04c91e10 100644 --- a/kernel/bpf/arraymap.c +++ b/kernel/bpf/arraymap.c | |||
@@ -19,6 +19,9 @@ | |||
19 | 19 | ||
20 | #include "map_in_map.h" | 20 | #include "map_in_map.h" |
21 | 21 | ||
22 | #define ARRAY_CREATE_FLAG_MASK \ | ||
23 | (BPF_F_NUMA_NODE | BPF_F_RDONLY | BPF_F_WRONLY) | ||
24 | |||
22 | static void bpf_array_free_percpu(struct bpf_array *array) | 25 | static void bpf_array_free_percpu(struct bpf_array *array) |
23 | { | 26 | { |
24 | int i; | 27 | int i; |
@@ -56,7 +59,8 @@ static struct bpf_map *array_map_alloc(union bpf_attr *attr) | |||
56 | 59 | ||
57 | /* check sanity of attributes */ | 60 | /* check sanity of attributes */ |
58 | if (attr->max_entries == 0 || attr->key_size != 4 || | 61 | if (attr->max_entries == 0 || attr->key_size != 4 || |
59 | attr->value_size == 0 || attr->map_flags & ~BPF_F_NUMA_NODE || | 62 | attr->value_size == 0 || |
63 | attr->map_flags & ~ARRAY_CREATE_FLAG_MASK || | ||
60 | (percpu && numa_node != NUMA_NO_NODE)) | 64 | (percpu && numa_node != NUMA_NO_NODE)) |
61 | return ERR_PTR(-EINVAL); | 65 | return ERR_PTR(-EINVAL); |
62 | 66 | ||