Following discussion in the "bpf: tail calls in sleepable programs" [1],
this series extends __bpf_prog_map_compatible() with additional per-program
compatibility checks.

The series validates these attributes:

* kprobe_write_ctx: for uprobe programs that can update pt_regs.
* call_get_func_ip: for tracing programs using bpf_get_func_ip().
* call_session_cookie: for fsession programs using bpf_session_cookie().
* call_session_is_return: for fsession programs using bpf_session_is_return().

For each attribute, prog_array compatibility is one-way:
programs without the requirement are rejected when tail-calling into
programs that require it.

This keeps tail-call runtime assumptions consistent. For example,
call_get_func_ip programs rely on func_ip metadata prepared on trampoline
stack; tail-calling from a !call_get_func_ip program into such a callee can
produce invalid func_ip values. The same class of issue applies to
call_session_cookie and call_session_is_return.

Links:
[1] https://lore.kernel.org/bpf/[email protected]/

Leon Hwang (8):
  bpf: Add fsession to verbose log in check_get_func_ip()
  bpf: Disallow !kprobe_write_ctx progs tail-calling kprobe_write_ctx
    progs
  bpf: Disallow !call_get_func_ip progs tail-calling call_get_func_ip
    progs
  bpf: Disallow !call_session_cookie progs tail-calling
    call_session_cookie progs
  bpf: Disallow !call_session_is_return progs tail-calling
    call_session_is_return progs
  selftests/bpf: Add a test to verify kprobe_write_ctx compatibility
    enforcement
  selftests/bpf: Add a test to verify call_get_func_ip compatibility
    enforcement
  selftests/bpf: Add a test to verify session-kfunc compatibility
    enforcement

 include/linux/bpf.h                           | 11 +++--
 kernel/bpf/core.c                             | 15 ++++++
 kernel/bpf/verifier.c                         |  4 +-
 .../selftests/bpf/prog_tests/attach_probe.c   | 44 +++++++++++++++++
 .../selftests/bpf/prog_tests/fsession_test.c  | 47 +++++++++++++++++++
 .../bpf/prog_tests/get_func_ip_test.c         | 46 ++++++++++++++++++
 .../selftests/bpf/progs/fsession_test.c       |  6 +++
 .../selftests/bpf/progs/get_func_ip_test.c    |  6 +++
 .../selftests/bpf/progs/kprobe_write_ctx.c    |  6 +++
 9 files changed, 181 insertions(+), 4 deletions(-)

-- 
2.52.0


Reply via email to