[PATCH bpf-next v4 1/9] bpf: Resolve and cache fd_array objects at load time
Anton Protopopov
a.s.protopopov at gmail.com
Mon Jul 6 15:42:53 UTC 2026
On 26/07/06 03:56PM, Daniel Borkmann wrote:
> The fd_array passed to BPF_PROG_LOAD carries the map and module BTF file
> descriptors a program binds. The verifier reads it more than once during
> a load: process_fd_array() walks it to bind the maps and BTFs, and
> check_and_resolve_insns() and the kfunc BTF resolver later read it again
> to resolve the program's BPF_PSEUDO_MAP_IDX* and module kfunc refs.
>
> For signed BPF, we need these upfront in memory, thus resolve each fd to
> its object once and cache it by fd_array index, then bind that cached
> object for the rest of the load. env->fd_array becomes a small per-slot
> {map, btf} cache rather than a bpfptr_t; every later reference is then
> an in-bounds lookup of an already-resolved object, and an index outside
> the cache is rejected instead of read from user memory:
>
> - continuous (fd_array_cnt given): the caller declares the length and
> every entry is resolved and bound up front (used also by the BPF
> signed loader)
>
> - sparse (no fd_array_cnt): left as the legacy path with no fd_array
> cache; each reference reads its fd from the caller's fd_array and
> resolves it on the spot. Deduplication in used_maps and the kfunc BTF
> table keeps this correct, and only unsigned programs use this shape.
>
> Split these into separate helpers to make it easier to follow.
>
> Signed-off-by: Daniel Borkmann <daniel at iogearbox.net>
> Cc: Anton Protopopov <a.s.protopopov at gmail.com>
> ---
> include/linux/bpf_verifier.h | 22 +++-
> kernel/bpf/verifier.c | 223 +++++++++++++++++++++++++++--------
> 2 files changed, 193 insertions(+), 52 deletions(-)
Acked-by: Anton Protopopov <a.s.protopopov at gmail.com>
> [...]
> --
> 2.43.0
>
More information about the Linux-security-module-archive
mailing list