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 e5d3de7cff2e..ebdef54bf7df 100644 --- a/kernel/bpf/devmap.c +++ b/kernel/bpf/devmap.c | |||
@@ -72,7 +72,7 @@ static LIST_HEAD(dev_map_list); | |||
72 | 72 | ||
73 | static u64 dev_map_bitmap_size(const union bpf_attr *attr) | 73 | static u64 dev_map_bitmap_size(const union bpf_attr *attr) |
74 | { | 74 | { |
75 | return BITS_TO_LONGS(attr->max_entries) * sizeof(unsigned long); | 75 | return BITS_TO_LONGS((u64) attr->max_entries) * sizeof(unsigned long); |
76 | } | 76 | } |
77 | 77 | ||
78 | static struct bpf_map *dev_map_alloc(union bpf_attr *attr) | 78 | static struct bpf_map *dev_map_alloc(union bpf_attr *attr) |
@@ -81,6 +81,9 @@ static struct bpf_map *dev_map_alloc(union bpf_attr *attr) | |||
81 | int err = -EINVAL; | 81 | int err = -EINVAL; |
82 | u64 cost; | 82 | u64 cost; |
83 | 83 | ||
84 | if (!capable(CAP_NET_ADMIN)) | ||
85 | return ERR_PTR(-EPERM); | ||
86 | |||
84 | /* check sanity of attributes */ | 87 | /* check sanity of attributes */ |
85 | if (attr->max_entries == 0 || attr->key_size != 4 || | 88 | if (attr->max_entries == 0 || attr->key_size != 4 || |
86 | attr->value_size != 4 || attr->map_flags & ~DEV_CREATE_FLAG_MASK) | 89 | attr->value_size != 4 || attr->map_flags & ~DEV_CREATE_FLAG_MASK) |
@@ -114,8 +117,9 @@ static struct bpf_map *dev_map_alloc(union bpf_attr *attr) | |||
114 | err = -ENOMEM; | 117 | err = -ENOMEM; |
115 | 118 | ||
116 | /* A per cpu bitfield with a bit per possible net device */ | 119 | /* A per cpu bitfield with a bit per possible net device */ |
117 | dtab->flush_needed = __alloc_percpu(dev_map_bitmap_size(attr), | 120 | dtab->flush_needed = __alloc_percpu_gfp(dev_map_bitmap_size(attr), |
118 | __alignof__(unsigned long)); | 121 | __alignof__(unsigned long), |
122 | GFP_KERNEL | __GFP_NOWARN); | ||
119 | if (!dtab->flush_needed) | 123 | if (!dtab->flush_needed) |
120 | goto free_dtab; | 124 | goto free_dtab; |
121 | 125 | ||