From: sashiko-bot@kernel.org
To: "Andrey Grodzovsky" <andrey.grodzovsky@crowdstrike.com>,
bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v9 4/7] libbpf: BPF programs manual loading and attaching
Date: Thu, 29 Oct 2026 22:54:12 +0000 [thread overview]
Message-ID: <sashiko-outbox-190106@kernel.org> (raw)
In-Reply-To: <20261029223348.3730738-5-andrey.grodzovsky@crowdstrike.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] libbpf: bpf_map__init_kern_struct_ops() clobbers MANUAL load strategy
--
commit dc922049cb04bf1494a0c7805a4fd1d881505fad
Author: Slava Imameev <slava.imameev@crowdstrike.com>
libbpf: BPF programs manual loading and attaching
This commit adds support for BPF_PROG_LOAD_STRATEGY_MANUAL, allowing BPF
programs to be skipped during the initial bpf_object load and loaded or
unloaded on demand via bpf_program__load() and bpf_program__unload().
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index e2cea1bca1d2d..1a5b582d63b24 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
[ ... ]
> @@ -1227,6 +1228,14 @@ static int bpf_object_adjust_struct_ops_autoload(struct bpf_object *obj)
> if (prog->type != BPF_PROG_TYPE_STRUCT_OPS)
> continue;
>
> + /*
> + * If the user set the load strategy to MANUAL, don't guess it
> + * from map autocreate: a MANUAL program is loaded explicitly
> + * with bpf_program__load(), which rejects any other strategy.
> + */
> + if (prog->load_strategy == BPF_PROG_LOAD_STRATEGY_MANUAL)
> + continue;
[Severity: Medium]
Can bpf_map__init_kern_struct_ops() overwrite a struct_ops program's
BPF_PROG_LOAD_STRATEGY_MANUAL setting before this check in
bpf_object_adjust_struct_ops_autoload() is reached?
During bpf_object_prepare(), bpf_object__init_kern_struct_ops_maps() runs
immediately before bpf_object_adjust_struct_ops_autoload():
tools/lib/bpf/libbpf.c:bpf_object_prepare() {
...
err = err ? : bpf_object__init_kern_struct_ops_maps(obj);
err = err ? : bpf_object_adjust_struct_ops_autoload(obj);
...
}
Inside bpf_object__init_kern_struct_ops_maps() ->
bpf_map__init_kern_struct_ops(), if a callback member is absent in the
running kernel BTF (with a zeroed shadow field) or if its slot in a
struct_ops map's shadow struct was cleared or replaced, load_strategy is
unconditionally reset to BPF_PROG_LOAD_STRATEGY_DISABLED:
tools/lib/bpf/libbpf.c:bpf_map__init_kern_struct_ops() {
...
if (!kern_member) {
...
if (st_ops->progs[i]) {
st_ops->progs[i]->load_strategy = BPF_PROG_LOAD_STRATEGY_DISABLED;
st_ops->progs[i] = NULL;
}
...
}
...
if (btf_is_ptr(mtype)) {
prog = *(void **)mdata;
if (st_ops->progs[i] && st_ops->progs[i] != prog)
st_ops->progs[i]->load_strategy = BPF_PROG_LOAD_STRATEGY_DISABLED;
...
}
When a user sets BPF_PROG_LOAD_STRATEGY_MANUAL via
bpf_program__set_load_strategy(), those assignments clobber load_strategy to
BPF_PROG_LOAD_STRATEGY_DISABLED.
Then bpf_object_adjust_struct_ops_autoload() does not see
BPF_PROG_LOAD_STRATEGY_MANUAL, so it either leaves the program as
BPF_PROG_LOAD_STRATEGY_DISABLED (causing a subsequent bpf_program__load() to
fail with -EINVAL) or sets it to BPF_PROG_LOAD_STRATEGY_AUTO if another
autocreated struct_ops map still references it.
Should bpf_map__init_kern_struct_ops() preserve load_strategy when it is set
to BPF_PROG_LOAD_STRATEGY_MANUAL?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261029223348.3730738-1-andrey.grodzovsky@crowdstrike.com?part=4
next prev parent reply other threads:[~2026-10-29 22:54 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-29 22:33 [PATCH bpf-next v9 0/7] libbpf: BPF program manual loading Andrey Grodzovsky
2026-10-29 22:33 ` [PATCH bpf-next v9 1/7] libbpf: Reject gen_loader set after PREPARE step Andrey Grodzovsky
2026-10-29 22:33 ` [PATCH bpf-next v9 2/7] libbpf: Free func_info, line_info and subprogs in bpf_program__exit() Andrey Grodzovsky
2026-10-29 22:33 ` [PATCH bpf-next v9 3/7] libbpf: BPF program load strategy enum Andrey Grodzovsky
2026-10-29 22:33 ` [PATCH bpf-next v9 4/7] libbpf: BPF programs manual loading and attaching Andrey Grodzovsky
2026-10-29 22:54 ` sashiko-bot [this message]
2026-10-29 22:33 ` [PATCH bpf-next v9 5/7] libbpf: Support declarative manual load via SEC("!...") prefix Andrey Grodzovsky
2026-10-29 22:33 ` [PATCH bpf-next v9 6/7] selftests/bpf: Cover BPF program load strategies and manual loading Andrey Grodzovsky
2026-10-29 22:33 ` [PATCH bpf-next v9 7/7] selftests/bpf: Convert veristat to BPF_PROG_LOAD_STRATEGY_MANUAL Andrey Grodzovsky
2026-10-29 22:45 ` sashiko-bot
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-190106@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=andrey.grodzovsky@crowdstrike.com \
--cc=bpf@vger.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