diff options
author | Anay Wadhera <awadhera@berkeley.edu> | 2021-05-20 21:56:42 -0700 |
---|---|---|
committer | Michael Bestas <mkbestas@lineageos.org> | 2022-04-19 00:49:44 +0300 |
commit | 980add4490a19cbf5b73938a2b52278bf3ba8266 (patch) | |
tree | 15c00972b8b0ce7350ae981514632bcd3e314d14 | |
parent | f0233b20e68109b50f8530b14e6e8eebc40d3fcd (diff) |
Revert "bpf, array: fix overflow in max_entries and undefined behavior in index_mask"
This reverts commit 095b0ba360ff9a86c592c1293602d42a9297e047.
Signed-off-by: Chatur27 <jasonbright2709@gmail.com>
-rw-r--r-- | kernel/bpf/arraymap.c | 17 |
1 files changed, 2 insertions, 15 deletions
diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c index 3608fa1aec8a..56f8a8306a49 100644 --- a/kernel/bpf/arraymap.c +++ b/kernel/bpf/arraymap.c @@ -23,7 +23,6 @@ static struct bpf_map *array_map_alloc(union bpf_attr *attr) u32 elem_size, array_size, index_mask, max_entries; bool unpriv = !capable(CAP_SYS_ADMIN); struct bpf_array *array; - u64 mask64; /* check sanity of attributes */ if (attr->max_entries == 0 || attr->key_size != 4 || @@ -39,25 +38,13 @@ static struct bpf_map *array_map_alloc(union bpf_attr *attr) elem_size = round_up(attr->value_size, 8); max_entries = attr->max_entries; + index_mask = roundup_pow_of_two(max_entries) - 1; - /* On 32 bit archs roundup_pow_of_two() with max_entries that has - * upper most bit set in u32 space is undefined behavior due to - * resulting 1U << 32, so do it manually here in u64 space. - */ - mask64 = fls_long(max_entries - 1); - mask64 = 1ULL << mask64; - mask64 -= 1; - - index_mask = mask64; - if (unpriv) { + if (unpriv) /* round up array size to nearest power of 2, * since cpu will speculate within index_mask limits */ max_entries = index_mask + 1; - /* Check for overflows. */ - if (max_entries < attr->max_entries) - return ERR_PTR(-E2BIG); - } /* check round_up into zero and u32 overflow */ if (elem_size == 0 || |