Skip to content

bpf: Allow invoking kfuncs from BPF_PROG_TYPE_SYSCALL progs

David Vernet 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 0 repliesApplied 2/2
  2. v12 patches 8 repliesSuperseded

Changes in v2 from the cover letter

- Create new verifier_kfunc_prog_types testcase meant to specifically validate calling core kfuncs from various program types. Remove the macros and testcases that had been added to the task, cgrp, and cpumask kfunc testcases (Andrii and Yonghong)

Patches in v2 All 2 applied

#Subject and filesSizeRepliesApplied
1/2bpf: Allow invoking kfuncs from BPF_PROG_TYPE_SYSCALL progskernel/bpf/cpumask.c kernel/bpf/helpers.c+2 -00 repliesApplied
2/2selftests/bpf: Verify calling core kfuncs from BPF_PROG_TYPE_SYCALLtools/testing/selftests/bpf/prog_tests/verifier_kfunc_prog_types.c tools/testing/selftests/bpf/progs/cgrp_kfunc_common.h tools/testing/selftests/bpf/progs/task_kfunc_common.h +1 more+132 -20 repliesApplied

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchYonghong SongAndrii Nakryiko
1/2A-b A-b
2/2A-b

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: Allow invoking kfuncs from BPF_PROG_TYPE_SYSCALL progs

Currently, a set of core BPF kfuncs (e.g. bpf_task_*, bpf_cgroup_*, bpf_cpumask_*, etc) cannot be invoked from BPF_PROG_TYPE_SYSCALL programs. The whitelist approach taken for enabling kfuncs makes sense:
it not safe to call these kfuncs from every program type. For example, it may not be safe to call bpf_task_acquire() in an fentry to free_task().

BPF_PROG_TYPE_SYSCALL, on the other hand, is a perfectly safe program type from which to invoke these kfuncs, as it's a very controlled environment, and we should never be able to run into any of the typical problems such as recursive invoations, acquiring references on freeing kptrs, etc. Being able to invoke these kfuncs would be useful, as BPF_PROG_TYPE_SYSCALL can be invoked with BPF_PROG_RUN, and would therefore enable user space programs to synchronously call into BPF to manipulate these kptrs.

---

v1: https://lore.kernel.org/all/[email protected]/
v1 -> v2:

- Create new verifier_kfunc_prog_types testcase meant to specifically validate calling core kfuncs from various program types. Remove the macros and testcases that had been added to the task, cgrp, and cpumask kfunc testcases (Andrii and Yonghong)

David Vernet (2):
bpf: Allow invoking kfuncs from BPF_PROG_TYPE_SYSCALL progs selftests/bpf: Verify calling core kfuncs from BPF_PROG_TYPE_SYCALL

 kernel/bpf/cpumask.c                          |   1 +
 kernel/bpf/helpers.c                          |   1 +
 .../prog_tests/verifier_kfunc_prog_types.c    |  11 ++
 .../selftests/bpf/progs/cgrp_kfunc_common.h   |   2 +-
 .../selftests/bpf/progs/task_kfunc_common.h   |   2 +-
 .../bpf/progs/verifier_kfunc_prog_types.c     | 119 ++++++++++++++++++
 6 files changed, 134 insertions(+), 2 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/verifier_kfunc_prog_types.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_kfunc_prog_types.c
Signature · 1 line
2.44.0