From: David Vernet <void@manifault.com>
To: bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev,
john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com,
haoluo@google.com, jolsa@kernel.org,
linux-kernel@vger.kernel.org, kernel-team@meta.com
Subject: [PATCH bpf-next v2 0/2] bpf: Allow invoking kfuncs from BPF_PROG_TYPE_SYSCALL progs
Date: Fri, 5 Apr 2024 09:30:39 -0500 [thread overview]
Message-ID: <20240405143041.632519-1-void@manifault.com> (raw)
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/20240404010308.334604-1-void@manifault.com/
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
--
2.44.0
next reply other threads:[~2024-04-05 14:30 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-05 14:30 David Vernet [this message]
2024-04-05 14:30 ` [PATCH bpf-next v2 1/2] bpf: Allow invoking kfuncs from BPF_PROG_TYPE_SYSCALL progs David Vernet
2024-04-05 14:30 ` [PATCH bpf-next v2 2/2] selftests/bpf: Verify calling core kfuncs from BPF_PROG_TYPE_SYCALL David Vernet
2024-04-05 18:00 ` [PATCH bpf-next v2 0/2] bpf: Allow invoking kfuncs from BPF_PROG_TYPE_SYSCALL progs patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240405143041.632519-1-void@manifault.com \
--to=void@manifault.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kernel-team@meta.com \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).