Skip to content

bpf: Allow 'may_goto 0' instruction

Yonghong Song bpf 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest3 patches 4 repliesIn review
  2. v13 patches 5 repliesSuperseded

Changes in v2 from the cover letter

- Instead of a separate function, removing 'may_goto 0' in existing func opt_remove_nops().

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3bpf: Allow 'may_goto 0' instruction in verifierkernel/bpf/verifier.c+2 -31 reply
2/3bpf: Remove 'may_goto 0' instruction in opt_remove_nops()kernel/bpf/verifier.c+7 -23 replies
3/3selftests/bpf: Add some tests related to 'may_goto 0' insnstools/testing/selftests/bpf/prog_tests/verifier.c tools/testing/selftests/bpf/progs/verifier_may_goto_1.c tools/testing/selftests/bpf/progs/verifier_may_goto_2.c+129 -00 replies

Reviews trailers per patch

2 of 3 patches have a Reviewed-by or Acked-by.

PatchEduard ZingermanDaniel Borkmann
1/3A-b A-b
2/3
3/3A-b

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

Read the v2 thread

Cover letter [PATCH bpf-next v2 0/3] bpf: Allow 'may_goto 0' instruction

Emil Tsalapatis from Meta reported such a case where 'may_goto 0' insn is generated by clang-19 compiler and this caused verification failure since 'may_goto 0' is rejected by verifier.

In fact, 'may_goto 0' insn is actually a no-op and it won't hurt verification. The only side effect is that the verifier will convert the insn to a sequence of codes like
/* r10 - 8 stores the implicit loop count */
r11 = *(u64 *)(r10 -8)
if r11 == 0x0 goto pc+2
r11 -= 1
*(u64 *)(r10 -8) = r11

With this patch set 'may_goto 0' insns are allowed in verification which also removes those insns.

Changelogs:
v1 -> v2:
- Instead of a separate function, removing 'may_goto 0' in existing func opt_remove_nops().

Yonghong Song (3):
bpf: Allow 'may_goto 0' instruction in verifier
bpf: Remove 'may_goto 0' instruction in opt_remove_nops() selftests/bpf: Add some tests related to 'may_goto 0' insns

 kernel/bpf/verifier.c                         | 14 ++-
 .../selftests/bpf/prog_tests/verifier.c       |  4 +
 .../selftests/bpf/progs/verifier_may_goto_1.c | 97 +++++++++++++++++++
 .../selftests/bpf/progs/verifier_may_goto_2.c | 28 ++++++
 4 files changed, 138 insertions(+), 5 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_may_goto_1.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_may_goto_2.c
Signature · 1 line
2.43.5