Skip to content

BPF verifier retval logic fixes

Andrii Nakryiko bpf 5 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. v5 Latest11 patches 0 repliesApplied 11/11
  2. v411 patches 1 replySuperseded
  3. v310 patches 9 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v210 patches10 repliesSuperseded
v110 patches16 repliesSuperseded

Changes in v5 from the cover letter

- fix timer_bad_ret test on no-alu32 flavor (CI);

Patches in v5 All 11 applied

#Subject and filesSizeRepliesApplied
1/11bpf: rearrange bpf_func_state fields to save a bit of memoryinclude/linux/bpf_verifier.h+2 -20 repliesApplied
2/11bpf: provide correct register name for exception callback retval checkkernel/bpf/verifier.c tools/testing/selftests/bpf/progs/exceptions_assert.c tools/testing/selftests/bpf/progs/exceptions_fail.c+8 -80 repliesApplied
3/11bpf: enforce precision of R0 on callback returnkernel/bpf/verifier.c+7 -00 repliesApplied
4/11bpf: enforce exact retval range on subprog/callback exitinclude/linux/bpf_verifier.h kernel/bpf/verifier.c+28 -120 repliesApplied
5/11selftests/bpf: add selftest validating callback result is enforcedtools/testing/selftests/bpf/progs/verifier_subprog_precision.c+50 -00 repliesApplied
6/11bpf: enforce precise retval range on program exitkernel/bpf/verifier.c tools/testing/selftests/bpf/progs/exceptions_assert.c tools/testing/selftests/bpf/progs/exceptions_fail.c +6 more+40 -380 repliesApplied
7/11bpf: unify async callback and program retval checkskernel/bpf/verifier.c+12 -180 repliesApplied
8/11bpf: enforce precision of R0 on program/async callback returnkernel/bpf/verifier.c+4 -00 repliesApplied
9/11selftests/bpf: validate async callback return value check correctnesstools/testing/selftests/bpf/progs/timer_failure.c+28 -80 repliesApplied
10/11selftests/bpf: adjust global_func15 test to validate prog exit precisiontools/testing/selftests/bpf/progs/test_global_func15.c+32 -00 repliesApplied
11/11bpf: simplify tnum output if a fully known constantkernel/bpf/log.c kernel/bpf/tnum.c tools/testing/selftests/bpf/progs/verifier_direct_packet_access.c +2 more+17 -100 repliesApplied

Reviews trailers per patch

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

PatchEduard ZingermanShung-Hsi Yu
1/11A-b
2/11A-b A-b
3/11A-b A-b
4/11A-b A-b
5/11A-b A-b
6/11A-b A-b
7/11A-b A-b
8/11A-b
9/11A-b
10/11A-b
11/11A-b

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

Read the v5 thread

Cover letter [PATCH v5 bpf-next 00/11] BPF verifier retval logic fixes

This patch set fixes BPF verifier logic around validating and enforcing return values for BPF programs that have specific range of expected return values. Both sync and async callbacks have similar logic and are fixes as well. A few tests are added that would fail without the fixes in this patch set.

Also, while at it, we update retval checking logic to use smin/smax range instead of tnum, avoiding future potential issues if expected range cannot be represented precisely by tnum (e.g., [0, 2] is not representable by tnum and is treated as [0, 3]).

There is a little bit of refactoring to unify async callback and program exit logic to avoid duplication of checks as much as possible.

v4->v5:
- fix timer_bad_ret test on no-alu32 flavor (CI);
v3->v4:
- add back bpf_func_state rearrangement patch;
- simplified patch #4 as suggested (Shung-Hsi);
v2->v3:
- more carefullly switch from umin/umax to smin/smax;
v1->v2:
- drop tnum from retval checks (Eduard);
- use smin/smax instead of umin/umax (Alexei).

Andrii Nakryiko (11):
bpf: rearrange bpf_func_state fields to save a bit of memory
bpf: provide correct register name for exception callback retval check
bpf: enforce precision of R0 on callback return
bpf: enforce exact retval range on subprog/callback exit selftests/bpf: add selftest validating callback result is enforced
bpf: enforce precise retval range on program exit
bpf: unify async callback and program retval checks
bpf: enforce precision of R0 on program/async callback return selftests/bpf: validate async callback return value check correctness selftests/bpf: adjust global_func15 test to validate prog exit
precision
bpf: simplify tnum output if a fully known constant

 include/linux/bpf_verifier.h                  |   9 +-
 kernel/bpf/log.c                              |  13 ++
 kernel/bpf/tnum.c                             |   6 -
 kernel/bpf/verifier.c                         | 120 ++++++++++--------
 .../selftests/bpf/progs/exceptions_assert.c   |   2 +-
 .../selftests/bpf/progs/exceptions_fail.c     |   2 +-
 .../selftests/bpf/progs/test_global_func15.c  |  34 ++++-
 .../selftests/bpf/progs/timer_failure.c       |  36 ++++--
 .../selftests/bpf/progs/user_ringbuf_fail.c   |   2 +-
 .../bpf/progs/verifier_cgroup_inv_retcode.c   |   8 +-
 .../bpf/progs/verifier_direct_packet_access.c |   2 +-
 .../selftests/bpf/progs/verifier_int_ptr.c    |   2 +-
 .../bpf/progs/verifier_netfilter_retcode.c    |   2 +-
 .../selftests/bpf/progs/verifier_stack_ptr.c  |   4 +-
 .../bpf/progs/verifier_subprog_precision.c    |  50 ++++++++
 15 files changed, 212 insertions(+), 80 deletions(-)
Signature · 1 line
2.34.1