BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/2] bpf: Fix loop detection for re-arming async callbacks
@ 2026-09-23 14:01 Puranjay Mohan
  2026-09-23 14:01 ` [PATCH bpf-next 1/2] bpf: Look at frame 0 when telling async callback entries apart Puranjay Mohan
  2026-09-23 14:01 ` [PATCH bpf-next 2/2] selftests/bpf: Add timer tests for a re-arming callback with a loop Puranjay Mohan
  0 siblings, 2 replies; 4+ messages in thread
From: Puranjay Mohan @ 2026-09-23 14:01 UTC (permalink / raw)
  To: bpf
  Cc: Puranjay Mohan, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman,
	Kumar Kartikeya Dwivedi, Song Liu, Yonghong Song

is_state_visited() skips the infinite loop check when two states differ in
async_entry_cnt, since seeing the same state on a second entry into an
async callback is not a loop. It reads that from the innermost frame, but
push_async_cb() sets in_async_callback_fn and async_entry_cnt on the
callback's own frame, and setup_func_entry() copies neither, so a subprog
called by the callback carries neither.

A callback which re-arms itself and calls a subprog therefore has its two
entries compared at a loop inside that subprog, and is rejected:

  infinite loop detected at insn 57

Patch 1 reads both from frame 0, which push_async_cb() makes the callback's
frame at any call depth.

Patch 2 covers both directions: a timer callback which re-arms through
bpf_timer_set_callback() and reaches a bounded loop through a static
subprog, which fails to load without patch 1, and a callback which never
returns, which must still be rejected either way. Nothing covered an async
callback before, so neither direction was tested.

Puranjay Mohan (2):
  bpf: Look at frame 0 when telling async callback entries apart
  selftests/bpf: Add timer tests for a re-arming callback with a loop

 kernel/bpf/states.c                           |  4 +-
 .../testing/selftests/bpf/prog_tests/timer.c  | 33 ++++++++++++
 tools/testing/selftests/bpf/progs/timer.c     | 50 ++++++++++++++++++-
 .../selftests/bpf/progs/timer_failure.c       | 29 +++++++++++
 4 files changed, 113 insertions(+), 3 deletions(-)


base-commit: 91f8613d95ad8cd99d8baf094806d1ef98bc6380
-- 
2.53.0-Meta


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

end of thread, other threads:[~2026-09-24  5:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-23 14:01 [PATCH bpf-next 0/2] bpf: Fix loop detection for re-arming async callbacks Puranjay Mohan
2026-09-23 14:01 ` [PATCH bpf-next 1/2] bpf: Look at frame 0 when telling async callback entries apart Puranjay Mohan
2026-09-24  5:56   ` Alexei Starovoitov
2026-09-23 14:01 ` [PATCH bpf-next 2/2] selftests/bpf: Add timer tests for a re-arming callback with a loop Puranjay Mohan

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