diff options
Diffstat (limited to 'kernel/bpf/hashtab.c')
-rw-r--r-- | kernel/bpf/hashtab.c | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c index 0f2708fde5f7..d92e05d9979b 100644 --- a/kernel/bpf/hashtab.c +++ b/kernel/bpf/hashtab.c | |||
@@ -360,14 +360,8 @@ static struct bpf_map *htab_map_alloc(union bpf_attr *attr) | |||
360 | else | 360 | else |
361 | cost += (u64) htab->elem_size * num_possible_cpus(); | 361 | cost += (u64) htab->elem_size * num_possible_cpus(); |
362 | 362 | ||
363 | if (cost >= U32_MAX - PAGE_SIZE) | 363 | /* if map size is larger than memlock limit, reject it */ |
364 | /* make sure page count doesn't overflow */ | 364 | err = bpf_map_charge_init(&htab->map.memory, cost); |
365 | goto free_htab; | ||
366 | |||
367 | htab->map.pages = round_up(cost, PAGE_SIZE) >> PAGE_SHIFT; | ||
368 | |||
369 | /* if map size is larger than memlock limit, reject it early */ | ||
370 | err = bpf_map_precharge_memlock(htab->map.pages); | ||
371 | if (err) | 365 | if (err) |
372 | goto free_htab; | 366 | goto free_htab; |
373 | 367 | ||
@@ -376,7 +370,7 @@ static struct bpf_map *htab_map_alloc(union bpf_attr *attr) | |||
376 | sizeof(struct bucket), | 370 | sizeof(struct bucket), |
377 | htab->map.numa_node); | 371 | htab->map.numa_node); |
378 | if (!htab->buckets) | 372 | if (!htab->buckets) |
379 | goto free_htab; | 373 | goto free_charge; |
380 | 374 | ||
381 | if (htab->map.map_flags & BPF_F_ZERO_SEED) | 375 | if (htab->map.map_flags & BPF_F_ZERO_SEED) |
382 | htab->hashrnd = 0; | 376 | htab->hashrnd = 0; |
@@ -409,6 +403,8 @@ free_prealloc: | |||
409 | prealloc_destroy(htab); | 403 | prealloc_destroy(htab); |
410 | free_buckets: | 404 | free_buckets: |
411 | bpf_map_area_free(htab->buckets); | 405 | bpf_map_area_free(htab->buckets); |
406 | free_charge: | ||
407 | bpf_map_charge_finish(&htab->map.memory); | ||
412 | free_htab: | 408 | free_htab: |
413 | kfree(htab); | 409 | kfree(htab); |
414 | return ERR_PTR(err); | 410 | return ERR_PTR(err); |