diff options
Diffstat (limited to 'kernel/bpf/devmap.c')
-rw-r--r-- | kernel/bpf/devmap.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c index e093d9a2c4dd..e745d6a88224 100644 --- a/kernel/bpf/devmap.c +++ b/kernel/bpf/devmap.c | |||
@@ -69,7 +69,7 @@ static LIST_HEAD(dev_map_list); | |||
69 | 69 | ||
70 | static u64 dev_map_bitmap_size(const union bpf_attr *attr) | 70 | static u64 dev_map_bitmap_size(const union bpf_attr *attr) |
71 | { | 71 | { |
72 | return BITS_TO_LONGS(attr->max_entries) * sizeof(unsigned long); | 72 | return BITS_TO_LONGS((u64) attr->max_entries) * sizeof(unsigned long); |
73 | } | 73 | } |
74 | 74 | ||
75 | static struct bpf_map *dev_map_alloc(union bpf_attr *attr) | 75 | static struct bpf_map *dev_map_alloc(union bpf_attr *attr) |
@@ -78,6 +78,9 @@ static struct bpf_map *dev_map_alloc(union bpf_attr *attr) | |||
78 | int err = -EINVAL; | 78 | int err = -EINVAL; |
79 | u64 cost; | 79 | u64 cost; |
80 | 80 | ||
81 | if (!capable(CAP_NET_ADMIN)) | ||
82 | return ERR_PTR(-EPERM); | ||
83 | |||
81 | /* check sanity of attributes */ | 84 | /* check sanity of attributes */ |
82 | if (attr->max_entries == 0 || attr->key_size != 4 || | 85 | if (attr->max_entries == 0 || attr->key_size != 4 || |
83 | attr->value_size != 4 || attr->map_flags & ~BPF_F_NUMA_NODE) | 86 | attr->value_size != 4 || attr->map_flags & ~BPF_F_NUMA_NODE) |
@@ -111,8 +114,9 @@ static struct bpf_map *dev_map_alloc(union bpf_attr *attr) | |||
111 | err = -ENOMEM; | 114 | err = -ENOMEM; |
112 | 115 | ||
113 | /* A per cpu bitfield with a bit per possible net device */ | 116 | /* A per cpu bitfield with a bit per possible net device */ |
114 | dtab->flush_needed = __alloc_percpu(dev_map_bitmap_size(attr), | 117 | dtab->flush_needed = __alloc_percpu_gfp(dev_map_bitmap_size(attr), |
115 | __alignof__(unsigned long)); | 118 | __alignof__(unsigned long), |
119 | GFP_KERNEL | __GFP_NOWARN); | ||
116 | if (!dtab->flush_needed) | 120 | if (!dtab->flush_needed) |
117 | goto free_dtab; | 121 | goto free_dtab; |
118 | 122 | ||