diff options
Diffstat (limited to 'kernel/bpf/reuseport_array.c')
-rw-r--r-- | kernel/bpf/reuseport_array.c | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/kernel/bpf/reuseport_array.c b/kernel/bpf/reuseport_array.c index 18e225de80ff..50c083ba978c 100644 --- a/kernel/bpf/reuseport_array.c +++ b/kernel/bpf/reuseport_array.c | |||
@@ -151,7 +151,8 @@ static struct bpf_map *reuseport_array_alloc(union bpf_attr *attr) | |||
151 | { | 151 | { |
152 | int err, numa_node = bpf_map_attr_numa_node(attr); | 152 | int err, numa_node = bpf_map_attr_numa_node(attr); |
153 | struct reuseport_array *array; | 153 | struct reuseport_array *array; |
154 | u64 cost, array_size; | 154 | struct bpf_map_memory mem; |
155 | u64 array_size; | ||
155 | 156 | ||
156 | if (!capable(CAP_SYS_ADMIN)) | 157 | if (!capable(CAP_SYS_ADMIN)) |
157 | return ERR_PTR(-EPERM); | 158 | return ERR_PTR(-EPERM); |
@@ -159,24 +160,20 @@ static struct bpf_map *reuseport_array_alloc(union bpf_attr *attr) | |||
159 | array_size = sizeof(*array); | 160 | array_size = sizeof(*array); |
160 | array_size += (u64)attr->max_entries * sizeof(struct sock *); | 161 | array_size += (u64)attr->max_entries * sizeof(struct sock *); |
161 | 162 | ||
162 | /* make sure there is no u32 overflow later in round_up() */ | 163 | err = bpf_map_charge_init(&mem, array_size); |
163 | cost = array_size; | ||
164 | if (cost >= U32_MAX - PAGE_SIZE) | ||
165 | return ERR_PTR(-ENOMEM); | ||
166 | cost = round_up(cost, PAGE_SIZE) >> PAGE_SHIFT; | ||
167 | |||
168 | err = bpf_map_precharge_memlock(cost); | ||
169 | if (err) | 164 | if (err) |
170 | return ERR_PTR(err); | 165 | return ERR_PTR(err); |
171 | 166 | ||
172 | /* allocate all map elements and zero-initialize them */ | 167 | /* allocate all map elements and zero-initialize them */ |
173 | array = bpf_map_area_alloc(array_size, numa_node); | 168 | array = bpf_map_area_alloc(array_size, numa_node); |
174 | if (!array) | 169 | if (!array) { |
170 | bpf_map_charge_finish(&mem); | ||
175 | return ERR_PTR(-ENOMEM); | 171 | return ERR_PTR(-ENOMEM); |
172 | } | ||
176 | 173 | ||
177 | /* copy mandatory map attributes */ | 174 | /* copy mandatory map attributes */ |
178 | bpf_map_init_from_attr(&array->map, attr); | 175 | bpf_map_init_from_attr(&array->map, attr); |
179 | array->map.pages = cost; | 176 | bpf_map_charge_move(&array->map.memory, &mem); |
180 | 177 | ||
181 | return &array->map; | 178 | return &array->map; |
182 | } | 179 | } |