diff options
Diffstat (limited to 'kernel/bpf/arraymap.c')
| -rw-r--r-- | kernel/bpf/arraymap.c | 20 | 
1 files changed, 8 insertions, 12 deletions
diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c index a2ac051c342f..3d55d95dcf49 100644 --- a/kernel/bpf/arraymap.c +++ b/kernel/bpf/arraymap.c @@ -11,7 +11,6 @@   */  #include <linux/bpf.h>  #include <linux/err.h> -#include <linux/vmalloc.h>  #include <linux/slab.h>  #include <linux/mm.h>  #include <linux/filter.h> @@ -56,7 +55,7 @@ static struct bpf_map *array_map_alloc(union bpf_attr *attr)  	    attr->value_size == 0 || attr->map_flags)  		return ERR_PTR(-EINVAL); -	if (attr->value_size >= 1 << (KMALLOC_SHIFT_MAX - 1)) +	if (attr->value_size > KMALLOC_MAX_SIZE)  		/* if value_size is bigger, the user space won't be able to  		 * access the elements.  		 */ @@ -74,14 +73,10 @@ static struct bpf_map *array_map_alloc(union bpf_attr *attr)  	if (array_size >= U32_MAX - PAGE_SIZE)  		return ERR_PTR(-ENOMEM); -  	/* allocate all map elements and zero-initialize them */ -	array = kzalloc(array_size, GFP_USER | __GFP_NOWARN); -	if (!array) { -		array = vzalloc(array_size); -		if (!array) -			return ERR_PTR(-ENOMEM); -	} +	array = bpf_map_area_alloc(array_size); +	if (!array) +		return ERR_PTR(-ENOMEM);  	/* copy mandatory map attributes */  	array->map.map_type = attr->map_type; @@ -97,7 +92,7 @@ static struct bpf_map *array_map_alloc(union bpf_attr *attr)  	if (array_size >= U32_MAX - PAGE_SIZE ||  	    elem_size > PCPU_MIN_UNIT_SIZE || bpf_array_alloc_percpu(array)) { -		kvfree(array); +		bpf_map_area_free(array);  		return ERR_PTR(-ENOMEM);  	}  out: @@ -262,7 +257,7 @@ static void array_map_free(struct bpf_map *map)  	if (array->map.map_type == BPF_MAP_TYPE_PERCPU_ARRAY)  		bpf_array_free_percpu(array); -	kvfree(array); +	bpf_map_area_free(array);  }  static const struct bpf_map_ops array_ops = { @@ -319,7 +314,8 @@ static void fd_array_map_free(struct bpf_map *map)  	/* make sure it's empty */  	for (i = 0; i < array->map.max_entries; i++)  		BUG_ON(array->ptrs[i] != NULL); -	kvfree(array); + +	bpf_map_area_free(array);  }  static void *fd_array_map_lookup_elem(struct bpf_map *map, void *key)  |