aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/bpf/stackmap.c
diff options
context:
space:
mode:
authorChenbo Feng <fengc@google.com>2017-10-18 16:00:22 -0400
committerDavid S. Miller <davem@davemloft.net>2017-10-20 08:32:59 -0400
commit6e71b04a82248ccf13a94b85cbc674a9fefe53f5 (patch)
tree45cab2ff677b04d921a2813738dc1ada8c07eaec /kernel/bpf/stackmap.c
parentaec72f3392b1d598a979e89c4fdb131965ae0ab3 (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/stackmap.c')
-rw-r--r--kernel/bpf/stackmap.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c
index 135be433e9a0..a15bc636cc98 100644
--- a/kernel/bpf/stackmap.c
+++ b/kernel/bpf/stackmap.c
@@ -11,6 +11,9 @@
11#include <linux/perf_event.h> 11#include <linux/perf_event.h>
12#include "percpu_freelist.h" 12#include "percpu_freelist.h"
13 13
14#define STACK_CREATE_FLAG_MASK \
15 (BPF_F_NUMA_NODE | BPF_F_RDONLY | BPF_F_WRONLY)
16
14struct stack_map_bucket { 17struct stack_map_bucket {
15 struct pcpu_freelist_node fnode; 18 struct pcpu_freelist_node fnode;
16 u32 hash; 19 u32 hash;
@@ -60,7 +63,7 @@ static struct bpf_map *stack_map_alloc(union bpf_attr *attr)
60 if (!capable(CAP_SYS_ADMIN)) 63 if (!capable(CAP_SYS_ADMIN))
61 return ERR_PTR(-EPERM); 64 return ERR_PTR(-EPERM);
62 65
63 if (attr->map_flags & ~BPF_F_NUMA_NODE) 66 if (attr->map_flags & ~STACK_CREATE_FLAG_MASK)
64 return ERR_PTR(-EINVAL); 67 return ERR_PTR(-EINVAL);
65 68
66 /* check sanity of attributes */ 69 /* check sanity of attributes */