From: Jiri Olsa <jolsa@kernel.org>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>
Cc: bpf@vger.kernel.org, Martin KaFai Lau <martin.lau@linux.dev>,
Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
HyeongJun An <sammiee5311@gmail.com>,
Christian Simon <simon@swine.de>
Subject: [PATCHv2 bpf-next 1/2] bpf: Reject multi kprobe programs in perf event attach
Date: Fri, 6 Nov 2026 17:40:42 +0100 [thread overview]
Message-ID: <20261106164043.546879-2-jolsa@kernel.org> (raw)
In-Reply-To: <20261106164043.546879-1-jolsa@kernel.org>
PERF_EVENT_IOC_SET_BPF allows attaching multi and session kprobe or
uprobe programs through the standard perf event path. These programs
require attach-specific run context, which this path does not provide.
Attaching them can also let a uprobe reach a private-stack program
through a tail call.
Reject multi and session programs in __perf_event_set_bpf_prog().
Keep the existing sleepable-program check for standard kprobe and
uprobe programs.
Suggested-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
kernel/events/core.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 457d75ea7142..919f43cdb473 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -11835,9 +11835,18 @@ static int __perf_event_set_bpf_prog(struct perf_event *event,
(is_syscall_tp && prog->type != BPF_PROG_TYPE_TRACEPOINT))
return -EINVAL;
- if (prog->type == BPF_PROG_TYPE_KPROBE && prog->sleepable && !is_uprobe)
+ if (prog->type == BPF_PROG_TYPE_KPROBE) {
/* only uprobe programs are allowed to be sleepable */
- return -EINVAL;
+ if (prog->sleepable && !is_uprobe)
+ return -EINVAL;
+
+ /* only standard kprobe/uprobe programs are allowed to attach */
+ if (prog->expected_attach_type == BPF_TRACE_KPROBE_MULTI ||
+ prog->expected_attach_type == BPF_TRACE_KPROBE_SESSION ||
+ prog->expected_attach_type == BPF_TRACE_UPROBE_MULTI ||
+ prog->expected_attach_type == BPF_TRACE_UPROBE_SESSION)
+ return -EINVAL;
+ }
if (prog->type == BPF_PROG_TYPE_TRACEPOINT && prog->sleepable) {
/*
--
2.43.0
next prev parent reply other threads:[~2026-11-06 16:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 16:40 [PATCHv2 bpf-next 0/2] bpf: Disable private stacks for uprobe programs Jiri Olsa
2026-11-06 16:40 ` Jiri Olsa [this message]
2026-11-06 16:40 ` [PATCHv2 bpf-next 2/2] bpf: Disable private stacks for untagged kprobe programs Jiri Olsa
2026-11-06 17:02 ` sashiko-bot
2026-11-06 17:17 ` bot+bpf-ci
2026-11-06 17:50 ` [PATCHv2 bpf-next 0/2] bpf: Disable private stacks for uprobe programs 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=20261106164043.546879-2-jolsa@kernel.org \
--to=jolsa@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=martin.lau@linux.dev \
--cc=sammiee5311@gmail.com \
--cc=simon@swine.de \
--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