bpf: remove obsolete KMALLOC_MAX_SIZE restriction on array map value size

Bugzilla: https://bugzilla.redhat.com/2137876

commit 63b8ce77b15ebf69c4b0ef4b87451e2626aa3c43
Author: Andrii Nakryiko <andrii@kernel.org>
Date:   Thu Jul 14 22:31:45 2022 -0700

    bpf: remove obsolete KMALLOC_MAX_SIZE restriction on array map value size
    
    Syscall-side map_lookup_elem() and map_update_elem() used to use
    kmalloc() to allocate temporary buffers of value_size, so
    KMALLOC_MAX_SIZE limit on value_size made sense to prevent creation of
    array map that won't be accessible through syscall interface.
    
    But this limitation since has been lifted by relying on kvmalloc() in
    syscall handling code. So remove KMALLOC_MAX_SIZE, which among other
    things means that it's possible to have BPF global variable sections
    (.bss, .data, .rodata) bigger than 8MB now. Keep the sanity check to
    prevent trivial overflows like round_up(map->value_size, 8) and restrict
    value size to <= INT_MAX (2GB).
    
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/r/20220715053146.1291891-4-andrii@kernel.org
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Signed-off-by: Artem Savkov <asavkov@redhat.com>
This commit is contained in:
Artem Savkov 2022-10-31 13:05:13 +01:00
parent 9c61d13ab3
commit 29c6780e09
1 changed files with 2 additions and 4 deletions

View File

@ -70,10 +70,8 @@ int array_map_alloc_check(union bpf_attr *attr)
attr->map_flags & BPF_F_PRESERVE_ELEMS)
return -EINVAL;
if (attr->value_size > KMALLOC_MAX_SIZE)
/* if value_size is bigger, the user space won't be able to
* access the elements.
*/
/* avoid overflow on round_up(map->value_size) */
if (attr->value_size > INT_MAX)
return -E2BIG;
return 0;