bpf: Add more WARN_ON_ONCE checks for mismatched alloc and free
authorHou Tao <houtao1@huawei.com>
Sat, 21 Oct 2023 01:49:59 +0000 (09:49 +0800)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 26 Oct 2023 12:23:33 +0000 (14:23 +0200)
commitc421c12586b3f00fb96b5c9af15c9a051a9090b1
tree93527c11d4684d0c5dc602a575bd7dc90d2cf320
parent22360fad5889cbefe1eca695b0cc0273ab280b56
bpf: Add more WARN_ON_ONCE checks for mismatched alloc and free

There are two possible mismatched alloc and free cases in BPF memory
allocator:

1) allocate from cache X but free by cache Y with a different unit_size
2) allocate from per-cpu cache but free by kmalloc cache or vice versa

So add more WARN_ON_ONCE checks in free_bulk() and __free_by_rcu() to
spot these mismatched alloc and free early.

Signed-off-by: Hou Tao <houtao1@huawei.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20231021014959.3563841-1-houtao@huaweicloud.com
kernel/bpf/memalloc.c