aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/bpf/syscall.c
diff options
context:
space:
mode:
authorJakub Kicinski <jakub.kicinski@netronome.com>2018-01-11 23:29:03 -0500
committerDaniel Borkmann <daniel@iogearbox.net>2018-01-14 17:36:29 -0500
commit1110f3a9bcf394c06b81a98206aee9b6860653c8 (patch)
treefb4c8c2a8d79c145ff7f997c7ddd6acdd3d51d4d /kernel/bpf/syscall.c
parentfdde5f3b6ba402908b9e289626e6d817852e8300 (diff)
bpf: add map_alloc_check callback
.map_alloc callbacks contain a number of checks validating user- -provided map attributes against constraints of a particular map type. For offloaded maps we will need to check map attributes without actually allocating any memory on the host. Add a new callback for validating attributes before any memory is allocated. This callback can be selectively implemented by map types for sharing code with offloads, or simply to separate the logical steps of validation and allocation. Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'kernel/bpf/syscall.c')
-rw-r--r--kernel/bpf/syscall.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 2bac0dc8baba..c0ac03a04880 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -96,16 +96,25 @@ static int check_uarg_tail_zero(void __user *uaddr,
96 96
97static struct bpf_map *find_and_alloc_map(union bpf_attr *attr) 97static struct bpf_map *find_and_alloc_map(union bpf_attr *attr)
98{ 98{
99 const struct bpf_map_ops *ops;
99 struct bpf_map *map; 100 struct bpf_map *map;
101 int err;
100 102
101 if (attr->map_type >= ARRAY_SIZE(bpf_map_types) || 103 if (attr->map_type >= ARRAY_SIZE(bpf_map_types))
102 !bpf_map_types[attr->map_type]) 104 return ERR_PTR(-EINVAL);
105 ops = bpf_map_types[attr->map_type];
106 if (!ops)
103 return ERR_PTR(-EINVAL); 107 return ERR_PTR(-EINVAL);
104 108
105 map = bpf_map_types[attr->map_type]->map_alloc(attr); 109 if (ops->map_alloc_check) {
110 err = ops->map_alloc_check(attr);
111 if (err)
112 return ERR_PTR(err);
113 }
114 map = ops->map_alloc(attr);
106 if (IS_ERR(map)) 115 if (IS_ERR(map))
107 return map; 116 return map;
108 map->ops = bpf_map_types[attr->map_type]; 117 map->ops = ops;
109 map->map_type = attr->map_type; 118 map->map_type = attr->map_type;
110 return map; 119 return map;
111} 120}