Skip to content

Fixes for bad PTR_TO_BTF_ID offset

Kumar Kartikeya Dwivedi bpf lkml llvm netfilter-devel 4 versions – Applied

Status from this message: This series was applied to bpf/bpf-next.git (master)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest8 patches 6 repliesApplied 8/8
  2. v38 patches 8 repliesSuperseded
  3. v28 patches 1 replySuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v16 patches18 repliesSuperseded

Changes in v4 from the cover letter

v3: https://lore.kernel.org/bpf/[email protected]

* Update commit message for __diag patch to say clang instead of LLVM (Nathan)
* Address nits for check_func_arg_reg_off (Martin)
* Add comment for fixed_off_ok case, remove is_kfunc check (Martin)

Patches in v4 All 8 applied

#Subject and filesSizeRepliesApplied
1/8bpf: Add check_func_arg_reg_off functioninclude/linux/bpf_verifier.h kernel/bpf/verifier.c+44 -280 repliesApplied
2/8bpf: Fix PTR_TO_BTF_ID var_off checkkernel/bpf/btf.c+6 -30 repliesApplied
3/8bpf: Disallow negative offset in check_ptr_off_regkernel/bpf/verifier.c tools/testing/selftests/bpf/verifier/bounds_deduction.c tools/testing/selftests/bpf/verifier/ctx.c+11 -50 repliesApplied
4/8bpf: Harden register offset checks for release helpers and kfuncsinclude/linux/bpf_verifier.h kernel/bpf/btf.c kernel/bpf/verifier.c+43 -180 repliesApplied
5/8compiler-clang.h: Add __diag infrastructure for clanginclude/linux/compiler-clang.h+22 -03 repliesApplied
6/8compiler_types.h: Add unified __diag_ignore_all for GCC/LLVMinclude/linux/compiler-clang.h include/linux/compiler-gcc.h include/linux/compiler_types.h+10 -02 repliesApplied
7/8bpf: Replace __diag_ignore with unified __diag_ignore_allnet/bpf/test_run.c net/netfilter/nf_conntrack_bpf.c+5 -40 repliesApplied
8/8selftests/bpf: Add tests for kfunc register offset checksnet/bpf/test_run.c tools/testing/selftests/bpf/verifier/calls.c+94 -00 repliesApplied

Reviews trailers per patch

None of the 8 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchMartin KaFai Lau
SeriesA-b
1/8
2/8
3/8
4/8
5/8
6/8
7/8
8/8

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 bpf-next v4 0/8] Fixes for bad PTR_TO_BTF_ID offset

This set fixes a bug related to bad var_off being permitted for kfunc call in case of PTR_TO_BTF_ID, consolidates offset checks for all register types allowed as helper or kfunc arguments into a common shared helper, and introduces a couple of other checks to harden the kfunc release logic and prevent future bugs. Some selftests are also included that fail in absence of these fixes, serving as demonstration of the issues being fixed.

Changelog:
----------
v3 -> v4:
v3: https://lore.kernel.org/bpf/[email protected]

* Update commit message for __diag patch to say clang instead of LLVM (Nathan)
* Address nits for check_func_arg_reg_off (Martin)
* Add comment for fixed_off_ok case, remove is_kfunc check (Martin)

v2 -> v3:
v2: https://lore.kernel.org/bpf/[email protected]

* Add my SoB to __diag for clang patch (Nathan)

v1 -> v2:
v1: https://lore.kernel.org/bpf/[email protected]

* Put reg->off check for release kfunc inside check_func_arg_reg_off, make the check a bit more readable
* Squash verifier selftests errstr update into patch 3 for bisect (Alexei)
* Include fix from Nathan for clang warning about missing prototypes
* Add unified __diag_ingore_all that works for both GCC/LLVM (Alexei)

Older discussion:

Kumar Kartikeya Dwivedi (7):
bpf: Add check_func_arg_reg_off function
bpf: Fix PTR_TO_BTF_ID var_off check
bpf: Disallow negative offset in check_ptr_off_reg
bpf: Harden register offset checks for release helpers and kfuncs compiler_types.h: Add unified __diag_ignore_all for GCC/LLVM
bpf: Replace __diag_ignore with unified __diag_ignore_all selftests/bpf: Add tests for kfunc register offset checks

Nathan Chancellor (1):
compiler-clang.h: Add __diag infrastructure for clang

 include/linux/bpf_verifier.h                  |  4 +
 include/linux/compiler-clang.h                | 25 +++++
 include/linux/compiler-gcc.h                  |  3 +
 include/linux/compiler_types.h                |  4 +
 kernel/bpf/btf.c                              | 40 ++++----
 kernel/bpf/verifier.c                         | 94 +++++++++++++------
 net/bpf/test_run.c                            | 15 ++-
 net/netfilter/nf_conntrack_bpf.c              |  5 +-
 .../selftests/bpf/verifier/bounds_deduction.c |  2 +-
 tools/testing/selftests/bpf/verifier/calls.c  | 83 ++++++++++++++++
 tools/testing/selftests/bpf/verifier/ctx.c    |  8 +-
 11 files changed, 230 insertions(+), 53 deletions(-)
Signature · 1 line
2.35.1