bpf: Ensure unit_size is matched with slab cache object size
authorHou Tao <houtao1@huawei.com>
Fri, 8 Sep 2023 13:39:22 +0000 (21:39 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Mon, 11 Sep 2023 19:41:37 +0000 (12:41 -0700)
commitc930472552022bd09aab3cd946ba3f243070d5c7
treee38f453dca80f3838bd511a479362857907e1149
parentb1d53958b69312e43c118d4093d8f93d3f6f80af
bpf: Ensure unit_size is matched with slab cache object size

Add extra check in bpf_mem_alloc_init() to ensure the unit_size of
bpf_mem_cache is matched with the object_size of underlying slab cache.
If these two sizes are unmatched, print a warning once and return
-EINVAL in bpf_mem_alloc_init(), so the mismatch can be found early and
the potential issue can be prevented.

Suggested-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Hou Tao <houtao1@huawei.com>
Link: https://lore.kernel.org/r/20230908133923.2675053-4-houtao@huaweicloud.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/memalloc.c