Skip to content

Make check_func_arg type checks table driven

Lorenz Bauer bpf netdev 4 versions – Applied

Status from this message: Applied to bpf-next. Thanks!

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest posting 2/211 patches 5 repliesApplied
  2. v4 posting 1/211 patches 0 repliesSuperseded
  3. v311 patches 6 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v211 patches12 repliesSuperseded

Changes in v4 from the cover letter

- Output the desired type on BTF ID mismatch (Martin)

Patches in v4 posting 2/2 Applied

#Subject and filesSizeRepliesApplied
1/11btf: make btf_set_contains take a const pointerinclude/linux/bpf.h kernel/bpf/btf.c+2 -20 replies
2/11bpf: check scalar or invalid register in check_helper_mem_accesskernel/bpf/verifier.c+11 -130 replies
3/11btf: Add BTF_ID_LIST_SINGLE macroinclude/linux/btf_ids.h tools/include/linux/btf_ids.h+16 -00 replies
4/11bpf: allow specifying a BTF ID per argument in function protosinclude/linux/bpf.h kernel/bpf/bpf_inode_storage.c kernel/bpf/btf.c +6 more+58 -1030 replies
5/11bpf: make BTF pointer type checking generickernel/bpf/verifier.c+20 -180 replies
6/11bpf: make reference tracking generickernel/bpf/verifier.c+10 -160 replies
7/11bpf: make context access check generickernel/bpf/verifier.c+4 -30 replies
8/11bpf: set meta->raw_mode for pointers close to usekernel/bpf/verifier.c+5 -10 replies
9/11bpf: check ARG_PTR_TO_SPINLOCK register type in check_func_argkernel/bpf/verifier.c+14 -140 replies
10/11bpf: hoist type checking for nullable arg typeskernel/bpf/verifier.c+30 -340 replies
11/11bpf: use a table to drive helper arg type checksinclude/linux/bpf.h kernel/bpf/verifier.c+110 -745 replies

Reviews trailers per patch

All 11 patches have a Reviewed-by or Acked-by.

PatchAndrii NakryikoMartin KaFai Lau
1/11A-b
2/11A-b
3/11A-b
4/11A-b
5/11A-b
6/11A-b A-b
7/11A-b
8/11A-b
9/11A-b
10/11A-b A-b
11/11A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH RESEND bpf-next v4 00/11] Make check_func_arg type checks table driven

I'm not sure why, but I missed sending the patchset to netdev@ last week. I guess that is why it's slipped through the cracks.

Changes in v4:
- Output the desired type on BTF ID mismatch (Martin)

Changes in v3:
- Fix BTF_ID_LIST_SINGLE if BTF is disabled (Martin)
- Drop incorrect arg_btf_id in bpf_sk_storage.c (Martin)
- Check for arg_btf_id in check_func_proto (Martin)
- Drop incorrect PTR_TO_BTF_ID from fullsock_types (Martin)
- Introduce btf_seq_file_ids in bpf_trace.c to reduce duplication

Changes in v2:
- Make the series stand alone (Martin)
- Drop incorrect BTF_SET_START fix (Andrii)
- Only support a single BTF ID per argument (Martin)
- Introduce BTF_ID_LIST_SINGLE macro (Andrii)
- Skip check_ctx_reg iff register is NULL
- Change output of check_reg_type slightly, to avoid touching tests

Original cover letter:

Currently, check_func_arg has this pretty gnarly if statement that compares the valid arg_type with the actualy reg_type. Sprinkled in-between are checks for register_is_null, to short circuit these tests if we're dealing with a nullable arg_type. There is also some code for later bounds / access checking hidden away in there.

This series of patches refactors the function into something like this:

   if (reg_is_null && arg_type_is_nullable)
     skip type checking

do type checking, including BTF validation

do bounds / access checking

The type checking is now table driven, which makes it easy to extend the acceptable types. Maybe more importantly, using a table makes it easy to provide more helpful verifier output (see the last patch).

Lorenz Bauer (11):
btf: make btf_set_contains take a const pointer
bpf: check scalar or invalid register in check_helper_mem_access
btf: Add BTF_ID_LIST_SINGLE macro
bpf: allow specifying a BTF ID per argument in function protos
bpf: make BTF pointer type checking generic
bpf: make reference tracking generic
bpf: make context access check generic
bpf: set meta->raw_mode for pointers close to use
bpf: check ARG_PTR_TO_SPINLOCK register type in check_func_arg
bpf: hoist type checking for nullable arg types
bpf: use a table to drive helper arg type checks

 include/linux/bpf.h            |  21 +-
 include/linux/btf_ids.h        |   8 +
 kernel/bpf/bpf_inode_storage.c |   8 +-
 kernel/bpf/btf.c               |  15 +-
 kernel/bpf/stackmap.c          |   5 +-
 kernel/bpf/verifier.c          | 338 ++++++++++++++++++---------------
 kernel/trace/bpf_trace.c       |  15 +-
 net/core/bpf_sk_storage.c      |   8 +-
 net/core/filter.c              |  31 +--
 net/ipv4/bpf_tcp_ca.c          |  19 +-
 tools/include/linux/btf_ids.h  |   8 +
 11 files changed, 239 insertions(+), 237 deletions(-)
Signature · 1 line
2.25.1