On 32-bit architecture, roundup_pow_of_two() can return 0 when the argument has upper most bit set due to resulting 1UL << 32. Add a check for this case.
Showing the changes to kernel/bpf/stackmap.c (1 of 1 file). Show all
Unified · Split
| @@ -115,6 +115,8 @@ static struct bpf_map *stack_map_alloc(union bpf_attr *attr) · 114 unmodified lines | |||
| 115 | 115 | ||
| 116 | /* hash table size must be power of 2 */ | 116 | /* hash table size must be power of 2 */ |
| 117 | n_buckets = roundup_pow_of_two(attr->max_entries); | 117 | n_buckets = roundup_pow_of_two(attr->max_entries); |
| 118 | if (!n_buckets) | ||
| 119 | return ERR_PTR(-E2BIG); | ||
| 118 | 120 | ||
| 119 | cost = n_buckets * sizeof(struct stack_map_bucket *) + sizeof(*smap); | 121 | cost = n_buckets * sizeof(struct stack_map_bucket *) + sizeof(*smap); |
| 120 | cost += n_buckets * (value_size + sizeof(struct stack_map_bucket)); | 122 | cost += n_buckets * (value_size + sizeof(struct stack_map_bucket)); |