BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/8] bpf: Fixes for may_goto, insn patching and iterator loops
@ 2026-09-24 23:31 Alexei Starovoitov
  2026-09-24 23:31 ` [PATCH bpf-next 1/8] bpf, x86: Fix timed may_goto with private stack Alexei Starovoitov
                   ` (9 more replies)
  0 siblings, 10 replies; 13+ messages in thread
From: Alexei Starovoitov @ 2026-09-24 23:31 UTC (permalink / raw)
  To: bpf; +Cc: daniel, andrii, eddyz87, memxor

From: Alexei Starovoitov <ast@kernel.org>

Fixes for four bugs in may_goto, in patching of insns and in
convergence of iterator loops, each followed by its tests.

Patch 1: arch_bpf_timed_may_goto() on x86 computes the address of count
and timestamp as rbp + offset. The prog with private stack keeps its
stack in r9, so bpf_check_timed_may_goto() reads and writes the kernel
stack, where r0-r5 have just been saved.

Patch 3: [ST, ST, first insn] that inits may_goto count and
[nospec, insn] move the insn down inside its own patch.
bpf_adj_branches() doesn't look inside the patch, so a call, ld_imm64
of a func or a jump that points backward lands short of its target
by the number of insns in front of it.

Patch 5: may_goto is expanded into a conditional jump with off + 5,
off + 2 or off - 1 stored into 16 bits without a range check.
may_goto +32763 jumps backward when it expires.

Patch 7: states_equal() matches ids through idmap, so the loop is
assumed to converge at bpf_iter_*_next() when the iterator was
destroyed and created again since the old state. The prog that never
ends is accepted.

On x86-64 without the fixes may_goto_priv_stack, may_goto_far/32767,
may_goto_far/-32768, both new tests of verifier_may_goto_1, "nospec in
front of a call" (unpriv) and four "iter: remake ... jump to next"
tests fail. With the fixes they pass.

veristat on selftests, 5477 progs: no prog changes its verdict except
the new "iter: remake" ones. Patch 7 adds insns to 16 progs that
call bpf_iter_*_next() in a loop: 11010007 -> 11011495 insns in total,
test_copy_from_user_dynptr 342 -> 470 is the largest in percent.

Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Alexei Starovoitov (8):
  bpf, x86: Fix timed may_goto with private stack
  selftests/bpf: Add test for timed may_goto with private stack
  bpf: Adjust pc-relative insn copied into its own patch
  selftests/bpf: Add tests for pc-relative insn copied into its own
    patch
  bpf: Fix overflow of jump offset in may_goto expansion
  selftests/bpf: Add tests for may_goto with far target
  bpf: Don't converge a loop on an iterator that was created anew
  selftests/bpf: Add tests for iterator created anew in its loop

 arch/x86/net/bpf_jit_comp.c                   |  12 +
 arch/x86/net/bpf_timed_may_goto.S             |  10 +-
 kernel/bpf/fixups.c                           | 123 ++++--
 kernel/bpf/states.c                           |  14 +-
 .../selftests/bpf/prog_tests/may_goto_far.c   |  92 +++++
 .../bpf/prog_tests/may_goto_priv_stack.c      |  41 ++
 tools/testing/selftests/bpf/progs/iters.c     | 382 ++++++++++++++++++
 .../selftests/bpf/progs/may_goto_priv_stack.c |  52 +++
 .../selftests/bpf/progs/verifier_may_goto_1.c | 121 ++++++
 .../selftests/bpf/progs/verifier_unpriv.c     |  37 ++
 10 files changed, 848 insertions(+), 36 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/may_goto_far.c
 create mode 100644 tools/testing/selftests/bpf/prog_tests/may_goto_priv_stack.c
 create mode 100644 tools/testing/selftests/bpf/progs/may_goto_priv_stack.c


base-commit: 93df8ae3267f19bf0c1135d26a0e21145dd0ea1c
-- 
2.55.0


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2026-09-25  1:31 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-24 23:31 [PATCH bpf-next 0/8] bpf: Fixes for may_goto, insn patching and iterator loops Alexei Starovoitov
2026-09-24 23:31 ` [PATCH bpf-next 1/8] bpf, x86: Fix timed may_goto with private stack Alexei Starovoitov
2026-09-24 23:31 ` [PATCH bpf-next 2/8] selftests/bpf: Add test for " Alexei Starovoitov
2026-09-24 23:31 ` [PATCH bpf-next 3/8] bpf: Adjust pc-relative insn copied into its own patch Alexei Starovoitov
2026-09-24 23:31 ` [PATCH bpf-next 4/8] selftests/bpf: Add tests for " Alexei Starovoitov
2026-09-24 23:31 ` [PATCH bpf-next 5/8] bpf: Fix overflow of jump offset in may_goto expansion Alexei Starovoitov
2026-09-24 23:31 ` [PATCH bpf-next 6/8] selftests/bpf: Add tests for may_goto with far target Alexei Starovoitov
2026-09-25  0:01   ` bot+bpf-ci
2026-09-25  0:11     ` Alexei Starovoitov
2026-09-24 23:31 ` [PATCH bpf-next 7/8] bpf: Don't converge a loop on an iterator that was created anew Alexei Starovoitov
2026-09-24 23:31 ` [PATCH bpf-next 8/8] selftests/bpf: Add tests for iterator created anew in its loop Alexei Starovoitov
2026-09-25  1:23 ` [PATCH bpf-next 0/8] bpf: Fixes for may_goto, insn patching and iterator loops Kumar Kartikeya Dwivedi
2026-09-25  1:30 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox