Skip to content

Commit 6183f4d

Browse files
minhbq-99borkmann
authored andcommitted
bpf: Check for integer overflow when using roundup_pow_of_two()
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. Fixes: d5a3b1f ("bpf: introduce BPF_MAP_TYPE_STACK_TRACE") Signed-off-by: Bui Quang Minh <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 548f119 commit 6183f4d

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

kernel/bpf/stackmap.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ static struct bpf_map *stack_map_alloc(union bpf_attr *attr)
115115

116116
/* hash table size must be power of 2 */
117117
n_buckets = roundup_pow_of_two(attr->max_entries);
118+
if (!n_buckets)
119+
return ERR_PTR(-E2BIG);
118120

119121
cost = n_buckets * sizeof(struct stack_map_bucket *) + sizeof(*smap);
120122
cost += n_buckets * (value_size + sizeof(struct stack_map_bucket));

0 commit comments

Comments
 (0)