From: sashiko-bot@kernel.org
To: "Jiri Olsa" <jolsa@kernel.org>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 3/4] libbpf: Detect BPF_TRACE_UPROBE support
Date: Tue, 03 Nov 2026 09:54:15 +0000 [thread overview]
Message-ID: <sashiko-outbox-194982@kernel.org> (raw)
In-Reply-To: <20261103093400.112178-4-jolsa@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] libbpf: broken BPF_TRACE_UPROBE detection in probe_kern_uprobe_attach_type()
--
commit daaaf792d9bbc9ce6b848daf8f14739d2eddbab7
Author: Jiri Olsa <jolsa@kernel.org>
libbpf: Detect BPF_TRACE_UPROBE support
This commit probes whether the kernel supports BPF_TRACE_UPROBE as the
expected attach type for BPF_PROG_TYPE_KPROBE programs and sets it for
uprobe, uretprobe, and usdt sections when supported.
> diff --git a/tools/lib/bpf/features.c b/tools/lib/bpf/features.c
> index adb5d2e7fdfa2..175d96c0a5012 100644
> --- a/tools/lib/bpf/features.c
> +++ b/tools/lib/bpf/features.c
> @@ -318,6 +318,24 @@ static int probe_kern_exp_attach_type(int token_fd)
> return probe_fd(fd);
> }
>
> +static int probe_kern_uprobe_attach_type(int token_fd)
> +{
> + LIBBPF_OPTS(bpf_prog_load_opts, opts,
> + .expected_attach_type = BPF_TRACE_UPROBE,
> + .token_fd = token_fd,
> + .prog_flags = token_fd ? BPF_F_TOKEN_FD : 0,
> + );
> + struct bpf_insn insns[] = {
> + BPF_MOV64_IMM(BPF_REG_0, 0),
> + BPF_EXIT_INSN(),
> + };
> + int fd;
> +
> + fd = bpf_prog_load(BPF_PROG_TYPE_KPROBE, NULL, "GPL", insns,
> + ARRAY_SIZE(insns), &opts);
> + return probe_fd(fd);
> +}
[Severity: Medium]
Does probe_kern_uprobe_attach_type() actually detect whether the running
kernel supports BPF_TRACE_UPROBE?
In kernel/bpf/syscall.c, bpf_prog_load() does not reject
attr->expected_attach_type >= __MAX_BPF_ATTACH_TYPE, and
bpf_prog_load_check_attach() has no case for BPF_PROG_TYPE_KPROBE, so it
falls through to the default branch and returns 0:
kernel/bpf/syscall.c:bpf_prog_load_check_attach() {
...
case BPF_PROG_TYPE_SYSCALL:
case BPF_PROG_TYPE_EXT:
if (expected_attach_type)
return -EINVAL;
fallthrough;
default:
return 0;
}
}
Because BPF_PROG_LOAD has accepted any expected_attach_type value for
BPF_PROG_TYPE_KPROBE since Linux 4.17 (when token_fd is 0),
probe_kern_uprobe_attach_type() will return 1 even on older kernels that do
not know about BPF_TRACE_UPROBE.
When bpf_object__load() -> bpf_object_load_prog() ->
libbpf_prepare_prog_load() then sets prog->expected_attach_type and
opts->expected_attach_type to BPF_TRACE_UPROBE on those older kernels:
tools/lib/bpf/libbpf.c:libbpf_prepare_prog_load() {
...
if ((def & SEC_UPROBE) && kernel_supports(prog->obj, FEAT_UPROBE_ATTACH_TYPE)) {
prog->expected_attach_type = BPF_TRACE_UPROBE;
opts->expected_attach_type = BPF_TRACE_UPROBE;
}
...
}
can this cause regressions for existing programs? For example:
1. In kernel/bpf/core.c, bpf_prog_map_compatible() requires matching
expected_attach_type values for BPF_MAP_TYPE_PROG_ARRAY:
kernel/bpf/core.c:bpf_prog_map_compatible() {
...
if (ret &&
map->map_type == BPF_MAP_TYPE_PROG_ARRAY &&
map->owner->expected_attach_type != fp->expected_attach_type)
ret = false;
...
}
Sharing a tail-call map between a SEC("uprobe") program (loaded with
expected_attach_type == BPF_TRACE_UPROBE) and a SEC("kprobe") program
(loaded with expected_attach_type == 0) will now fail.
2. Callers checking bpf_program__expected_attach_type() will observe
BPF_TRACE_UPROBE on kernels that neither enforce uprobe-only attach nor
disable the private stack for BPF_TRACE_UPROBE.
3. If FEAT_UPROBE_ATTACH_TYPE is cached without a token and later used when
loading a program with a BPF token on kernels 6.9+ prior to
BPF_TRACE_UPROBE, bpf_token_allow_prog_type() in kernel/bpf/token.c will
reject the load because attach_type >= __MAX_BPF_ATTACH_TYPE.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261103093400.112178-1-jolsa@kernel.org?part=3
next prev parent reply other threads:[~2026-11-03 9:54 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 9:33 [PATCH bpf-next 0/4] bpf: Disable private stacks for uprobe programs Jiri Olsa
2026-11-03 9:33 ` [PATCH bpf-next 1/4] bpf: Disable private stack " Jiri Olsa
2026-11-03 9:33 ` [PATCH bpf-next 2/4] bpf: Add BPF_TRACE_UPROBE attach type Jiri Olsa
2026-11-03 9:59 ` sashiko-bot
2026-11-03 9:33 ` [PATCH bpf-next 3/4] libbpf: Detect BPF_TRACE_UPROBE support Jiri Olsa
2026-11-03 9:54 ` sashiko-bot [this message]
2026-11-03 9:34 ` [PATCH bpf-next 4/4] selftests/bpf: Verify classic uprobe attach types Jiri Olsa
2026-11-03 9:56 ` sashiko-bot
2026-11-04 4:33 ` [PATCH bpf-next 0/4] bpf: Disable private stacks for uprobe programs Alexei Starovoitov
2026-11-04 14:17 ` Jiri Olsa
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=sashiko-outbox-194982@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=jolsa@kernel.org \
--cc=sashiko-reviews@lists.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