bpf: Use array_map_meta_equal for percpu array inner map replacement
authorGuannan Wang <wgnbuaa@gmail.com>
Thu, 14 May 2026 07:44:54 +0000 (15:44 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 14 May 2026 15:18:50 +0000 (08:18 -0700)
commit593980175389a05793f6060aa20e626330960395
tree35a4bfb34d17e72b131c9fb87f7d9dbff0a8e954
parentd25e65a8b89725e9745bfc3acd738cdec3818a07
bpf: Use array_map_meta_equal for percpu array inner map replacement

percpu_array_map_ops.map_meta_equal points to the generic
bpf_map_meta_equal(), which does not compare max_entries.  When a
percpu array serves as an inner map, replacing it with one that has
fewer max_entries bypasses the check.  Since percpu_array_map_gen_lookup()
inlines the original template's index_mask as a JIT immediate, a lookup
on the replacement map can access pptrs[] out of bounds.

Point percpu_array_map_ops.map_meta_equal to array_map_meta_equal(),
which already enforces the max_entries equality check.

Add a selftest to verify that replacing a percpu array inner map with
a differently-sized one is rejected.

Fixes: db69718b8efa ("bpf: inline bpf_map_lookup_elem() for PERCPU_ARRAY maps")
Signed-off-by: Guannan Wang <wgnbuaa@gmail.com>
Acked-by: Mykyta Yatsenko <yatsenko@meta.com>
Link: https://lore.kernel.org/r/20260514074454.77491-1-wgnbuaa@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/arraymap.c
tools/testing/selftests/bpf/prog_tests/percpu_array_inner_map.c [new file with mode: 0644]