History

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.

Bui Quang Minh committed 5 years ago

Commit 6183f4d1 parent 548f1191 file · +2 −0Browse files

Showing the changes to kernel (1 of 1 file). Show all

Unified · Split

kernel/bpf/stackmap.c+2−0
@@ -115,6 +115,8 @@ static struct bpf_map *stack_map_alloc(union bpf_attr *attr) · 114 unmodified lines
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));

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t