aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/bpf/syscall.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/bpf/syscall.c')
-rw-r--r--kernel/bpf/syscall.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index e2aeb5e89f44..bfcde949c7f8 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -28,6 +28,7 @@
28#include <linux/timekeeping.h> 28#include <linux/timekeeping.h>
29#include <linux/ctype.h> 29#include <linux/ctype.h>
30#include <linux/btf.h> 30#include <linux/btf.h>
31#include <linux/nospec.h>
31 32
32#define IS_FD_ARRAY(map) ((map)->map_type == BPF_MAP_TYPE_PROG_ARRAY || \ 33#define IS_FD_ARRAY(map) ((map)->map_type == BPF_MAP_TYPE_PROG_ARRAY || \
33 (map)->map_type == BPF_MAP_TYPE_PERF_EVENT_ARRAY || \ 34 (map)->map_type == BPF_MAP_TYPE_PERF_EVENT_ARRAY || \
@@ -104,12 +105,14 @@ const struct bpf_map_ops bpf_map_offload_ops = {
104static struct bpf_map *find_and_alloc_map(union bpf_attr *attr) 105static struct bpf_map *find_and_alloc_map(union bpf_attr *attr)
105{ 106{
106 const struct bpf_map_ops *ops; 107 const struct bpf_map_ops *ops;
108 u32 type = attr->map_type;
107 struct bpf_map *map; 109 struct bpf_map *map;
108 int err; 110 int err;
109 111
110 if (attr->map_type >= ARRAY_SIZE(bpf_map_types)) 112 if (type >= ARRAY_SIZE(bpf_map_types))
111 return ERR_PTR(-EINVAL); 113 return ERR_PTR(-EINVAL);
112 ops = bpf_map_types[attr->map_type]; 114 type = array_index_nospec(type, ARRAY_SIZE(bpf_map_types));
115 ops = bpf_map_types[type];
113 if (!ops) 116 if (!ops)
114 return ERR_PTR(-EINVAL); 117 return ERR_PTR(-EINVAL);
115 118
@@ -124,7 +127,7 @@ static struct bpf_map *find_and_alloc_map(union bpf_attr *attr)
124 if (IS_ERR(map)) 127 if (IS_ERR(map))
125 return map; 128 return map;
126 map->ops = ops; 129 map->ops = ops;
127 map->map_type = attr->map_type; 130 map->map_type = type;
128 return map; 131 return map;
129} 132}
130 133
@@ -897,11 +900,17 @@ static const struct bpf_prog_ops * const bpf_prog_types[] = {
897 900
898static int find_prog_type(enum bpf_prog_type type, struct bpf_prog *prog) 901static int find_prog_type(enum bpf_prog_type type, struct bpf_prog *prog)
899{ 902{
900 if (type >= ARRAY_SIZE(bpf_prog_types) || !bpf_prog_types[type]) 903 const struct bpf_prog_ops *ops;
904
905 if (type >= ARRAY_SIZE(bpf_prog_types))
906 return -EINVAL;
907 type = array_index_nospec(type, ARRAY_SIZE(bpf_prog_types));
908 ops = bpf_prog_types[type];
909 if (!ops)
901 return -EINVAL; 910 return -EINVAL;
902 911
903 if (!bpf_prog_is_dev_bound(prog->aux)) 912 if (!bpf_prog_is_dev_bound(prog->aux))
904 prog->aux->ops = bpf_prog_types[type]; 913 prog->aux->ops = ops;
905 else 914 else
906 prog->aux->ops = &bpf_offload_prog_ops; 915 prog->aux->ops = &bpf_offload_prog_ops;
907 prog->type = type; 916 prog->type = type;