Skip to content

Fix global subprog PTR_TO_CTX arg handling

Andrii Nakryiko bpf 1 version 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

  1. v2 Latest4 patches 8 repliesApplied 4/4

Changes in v2 from the cover letter

- special-case typedef bpf_user_pt_regs_t handling for KPROBE programs,

Patches in v2 All 4 applied

#Subject and filesSizeRepliesApplied
1/4bpf: simplify btf_get_prog_ctx_type() into btf_is_prog_ctx_type()include/linux/btf.h kernel/bpf/btf.c kernel/bpf/verifier.c+22 -240 repliesApplied
2/4bpf: handle bpf_user_pt_regs_t typedef explicitly for PTR_TO_CTX global argkernel/bpf/btf.c+15 -06 repliesApplied
3/4bpf: don't infer PTR_TO_CTX for programs with unnamed context typekernel/bpf/btf.c tools/testing/selftests/bpf/progs/test_global_func_ctx_args.c+22 -00 repliesApplied
4/4selftests/bpf: add anonymous user struct as global subprog arg testtools/testing/selftests/bpf/progs/verifier_global_subprogs.c+29 -00 repliesApplied

Reviews trailers per patch

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

PatchJiri OlsaEduard Zingerman
SeriesA-b A-b
1/4
2/4
3/4
4/4

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 v2 bpf-next 0/4] Fix global subprog PTR_TO_CTX arg handling

Fix confusing and incorrect inference of PTR_TO_CTX argument type in BPF global subprogs. For some program types (iters, tracepoint, any program type that doesn't have fixed named "canonical" context type) when user uses (in a correct and valid way) a pointer argument to user-defined anonymous struct type, verifier will incorrectly assume that it has to be PTR_TO_CTX argument. While it should be just a PTR_TO_MEM argument with allowed size calculated from user-provided (even if anonymous) struct.

This did come up in practice and was very confusing to users, so let's prevent this going forward. We had to do a slight refactoring of btf_get_prog_ctx_type() to make it easy to support a special s390x KPROBE use cases. See details in respective patches.

v1->v2:
- special-case typedef bpf_user_pt_regs_t handling for KPROBE programs,

    fixing s390x after changes in patch #2.

Andrii Nakryiko (4):
bpf: simplify btf_get_prog_ctx_type() into btf_is_prog_ctx_type()
bpf: handle bpf_user_pt_regs_t typedef explicitly for PTR_TO_CTX
global arg
bpf: don't infer PTR_TO_CTX for programs with unnamed context type selftests/bpf: add anonymous user struct as global subprog arg test

 include/linux/btf.h                           | 17 ++++---
 kernel/bpf/btf.c                              | 45 +++++++++++++------
 kernel/bpf/verifier.c                         |  2 +-
 .../bpf/progs/test_global_func_ctx_args.c     | 19 ++++++++
 .../bpf/progs/verifier_global_subprogs.c      | 29 ++++++++++++
 5 files changed, 88 insertions(+), 24 deletions(-)
Signature · 1 line
2.39.3