kernel_samsung_a53x/kernel/bpf
Toke Høiland-Jørgensen 736d05560d bpf: Fix DEVMAP_HASH overflow check on 32-bit arches
[ Upstream commit 281d464a34f540de166cee74b723e97ac2515ec3 ]

The devmap code allocates a number hash buckets equal to the next power
of two of the max_entries value provided when creating the map. When
rounding up to the next power of two, the 32-bit variable storing the
number of buckets can overflow, and the code checks for overflow by
checking if the truncated 32-bit value is equal to 0. However, on 32-bit
arches the rounding up itself can overflow mid-way through, because it
ends up doing a left-shift of 32 bits on an unsigned long value. If the
size of an unsigned long is four bytes, this is undefined behaviour, so
there is no guarantee that we'll end up with a nice and tidy 0-value at
the end.

Syzbot managed to turn this into a crash on arm32 by creating a
DEVMAP_HASH with max_entries > 0x80000000 and then trying to update it.
Fix this by moving the overflow check to before the rounding up
operation.

Fixes: 6f9d451ab1a3 ("xdp: Add devmap_hash map type for looking up devices by hashed index")
Link: https://lore.kernel.org/r/000000000000ed666a0611af6818@google.com
Reported-and-tested-by: syzbot+8cd36f6b65f3cafd400a@syzkaller.appspotmail.com
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Message-ID: <20240307120340.99577-2-toke@redhat.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Pu Lehui <pulehui@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-11-23 23:21:29 +01:00
..
preload Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
arraymap.c bpf: Add map and need_defer parameters to .map_fd_put_ptr() 2024-11-18 12:13:12 +01:00
bpf_inode_storage.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
bpf_iter.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
bpf_local_storage.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
bpf_lru_list.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
bpf_lru_list.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
bpf_lsm.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
bpf_struct_ops.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
bpf_struct_ops_types.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
btf.c bpf: Eliminate remaining "make W=1" warnings in kernel/bpf/btf.o 2024-11-23 23:20:08 +01:00
cgroup.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
core.c bpf: Detect IP == ksym.end as part of BPF program 2024-11-18 11:43:12 +01:00
cpumap.c bpf: report RCU QS in cpumap kthread 2024-11-19 08:45:00 +01:00
devmap.c bpf: Fix DEVMAP_HASH overflow check on 32-bit arches 2024-11-23 23:21:29 +01:00
disasm.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
disasm.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
dispatcher.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
hashtab.c bpf: Fix hashtab overflow check on 32-bit arches 2024-11-19 08:44:48 +01:00
helpers.c bpf: Fix bpf_strtol and bpf_strtoul helpers for 32bit 2024-11-23 23:21:24 +01:00
inode.c Revert "fs: add file and path permissions helpers" 2024-11-19 13:30:21 +01:00
local_storage.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
lpm_trie.c bpf, lpm: Fix check prefixlen before walking trie 2024-11-18 12:12:28 +01:00
Makefile Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
map_in_map.c bpf: Add map and need_defer parameters to .map_fd_put_ptr() 2024-11-18 12:13:12 +01:00
map_in_map.h bpf: Add map and need_defer parameters to .map_fd_put_ptr() 2024-11-18 12:13:12 +01:00
map_iter.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
net_namespace.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
offload.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
percpu_freelist.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
percpu_freelist.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
prog_iter.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
queue_stack_maps.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
reuseport_array.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ringbuf.c bpf: Fix overrunning reservations in ringbuf 2024-11-19 14:19:51 +01:00
stackmap.c bpf: Fix stackmap overflow check on 32-bit arches 2024-11-19 08:44:49 +01:00
syscall.c bpf: In bpf_task_fd_query use fget_task 2024-11-19 12:27:27 +01:00
sysfs_btf.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
task_iter.c file: Replace fcheck_files with files_lookup_fd_rcu 2024-11-19 12:27:27 +01:00
tnum.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
trampoline.c x86/ibt,ftrace: Search for __fentry__ location 2024-11-23 23:21:16 +01:00
verifier.c bpf: Allow reads from uninit stack 2024-11-19 14:19:46 +01:00