Previously, I fixed a tailcall infinite loop issue caused by trampoline[0]. At this time, I fix a tailcall infinite loop issue caused by freplace. Since commit 1c123c567fb1 ("bpf: Resolve fext program type when checking map compatibility"), freplace prog is able to tail call its target prog. What happens when freplace prog attaches to its target prog's subprog and tail calls its target prog? The kernel will panic because TASK stack guard page was hit. The panic is fixed on both x64 and arm64[1]. Please check the corresponding patch to see the details. v1 -> v2: * Address comment from Eduard: * Explain why nop5 and xor/nop3 are swapped at prologue. * Address comment from Alexei: * Disallow attaching tail_call_reachable freplace prog to not-tail_call_reachable target in verifier. * Update "bpf, arm64: Fix tailcall infinite loop caused by freplace" with latest arm64 JIT code. Links: [0] https://lore.kernel.org/bpf/20230912150442.2009-1-hffilwlqm@xxxxxxxxx/ [1] https://github.com/kernel-patches/bpf/pull/7638 Leon Hwang (4): bpf, x64: Fix tailcall infinite loop caused by freplace bpf, arm64: Fix tailcall infinite loop caused by freplace selftests/bpf: Add testcases for another tailcall infinite loop fixing selftests/bpf: Fix verifier tailcall jit selftest arch/arm64/net/bpf_jit_comp.c | 44 +++- arch/x86/net/bpf_jit_comp.c | 26 ++- kernel/bpf/verifier.c | 6 + .../selftests/bpf/prog_tests/tailcalls.c | 216 +++++++++++++++++- .../tailcall_bpf2bpf_hierarchy_freplace.c | 30 +++ .../testing/selftests/bpf/progs/tc_bpf2bpf.c | 37 ++- .../bpf/progs/verifier_tailcall_jit.c | 4 +- 7 files changed, 344 insertions(+), 19 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/tailcall_bpf2bpf_hierarchy_freplace.c -- 2.44.0