lkml.org 
[lkml]   [2021]   [Jan]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH] bpf: Check for integer overflow when using roundup_pow_of_two()
    Date
    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 <minhquangbui99@gmail.com>
    ---
    kernel/bpf/stackmap.c | 2 ++
    1 file changed, 2 insertions(+)

    diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c
    index aea96b638473..bfafbf115bf3 100644
    --- a/kernel/bpf/stackmap.c
    +++ b/kernel/bpf/stackmap.c
    @@ -115,6 +115,8 @@ static struct bpf_map *stack_map_alloc(union bpf_attr *attr)

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

    cost = n_buckets * sizeof(struct stack_map_bucket *) + sizeof(*smap);
    cost += n_buckets * (value_size + sizeof(struct stack_map_bucket));
    --
    2.17.1
    \
     
     \ /
      Last update: 2021-01-27 07:45    [W:4.011 / U:0.008 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site