Skip to content

bpf: Keep target extended until its last freplace link detaches

[email protected] bpf lkml 2 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. v2 Latest2 patches 5 repliesApplied 2/2
  2. v12 patches 2 repliesSuperseded

Changes in v2 from the cover letter

- freplace_link_cnt is u16 instead of u64, per Alexei's review: it is bounded by BPF_MAX_SUBPROGS, which counts the entry function too, so up to 256 links, one past u8, and it sits in the padding next to stack_arg_sp_adjust, so bpf_prog_aux does not grow
- dropped the separate is_extended boolean, deriving the extended state from the count itself
- renamed bpf_freplace_check_tgt_prog() to bpf_freplace_link_tgt_prog(), it reserves the target on success
- dropped the WARN_ON_ONCE() on detach, per Leon's review: the count is paired by the link lifetime and the sibling prog_array_member_cnt decrement is not guarded either

Patches in v2 All 2 applied

#Subject and filesSizeRepliesApplied
1/2bpf: Keep target extended until its last freplace link detachesinclude/linux/bpf.h kernel/bpf/arraymap.c kernel/bpf/trampoline.c+7 -76 repliesApplied
2/2selftests/bpf: Verify is_extended with multiple freplace linkstools/testing/selftests/bpf/prog_tests/tailcalls.c tools/testing/selftests/bpf/progs/tailcall_freplace_multi.c+101 -01 replyApplied

Reviews trailers per patch

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

PatchJiri OlsaLeon Hwang
SeriesA-b
1/2A-b
2/2

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/2] bpf: Keep target extended until its last freplace link detaches

From: Yuan Chen <[email protected]>

is_extended is a plain boolean, but one target prog can carry several freplace links at the same time, one on its entry and one on a global subprogram. __bpf_trampoline_unlink_prog() cleared it whenever *any* of them detached, so with two links on one target, detaching one of them re-armed the unbounded tail call loop closed by commit d6083f040d5d ("bpf: Prevent tailcall infinite loop caused by freplace"):
a single BPF_PROG_TEST_RUN on the tail-called target then panics the kernel, reproduced on both bpf-next and master.

Patch 1 replaces the boolean with a count of the freplace links attached to each target prog, so the target stays extended until its last link detaches. Patch 2 adds a selftest covering the sequence.

Changes since v1:

- freplace_link_cnt is u16 instead of u64, per Alexei's review: it is bounded by BPF_MAX_SUBPROGS, which counts the entry function too, so up to 256 links, one past u8, and it sits in the padding next to stack_arg_sp_adjust, so bpf_prog_aux does not grow
- dropped the separate is_extended boolean, deriving the extended state from the count itself
- renamed bpf_freplace_check_tgt_prog() to bpf_freplace_link_tgt_prog(), it reserves the target on success
- dropped the WARN_ON_ONCE() on detach, per Leon's review: the count is paired by the link lifetime and the sibling prog_array_member_cnt decrement is not guarded either

Yuan Chen (2):
bpf: Keep target extended until its last freplace link detaches selftests/bpf: Verify is_extended with multiple freplace links

 include/linux/bpf.h                           |  4 +-
 kernel/bpf/arraymap.c                         |  2 +-
 kernel/bpf/trampoline.c                       |  8 +-
 .../selftests/bpf/prog_tests/tailcalls.c      | 74 +++++++++++++++++++
 .../bpf/progs/tailcall_freplace_multi.c       | 27 +++++++
 5 files changed, 108 insertions(+), 7 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/tailcall_freplace_multi.c
Signature · 1 line
2.54.0