From: Jiri Olsa <olsajiri@gmail.com>
To: Fuyu Zhao <zhaofuyu@vivo.com>
Cc: bpf@vger.kernel.org, eddyz87@gmail.com,
andrii.nakryiko@gmail.com, alan.maguire@oracle.com,
Andrii Nakryiko <andrii@kernel.org>
Subject: Re: [PATCH bpf-next v7 1/2] libbpf: support selective kernel module BTF loading via bpf_object_open_opts
Date: Mon, 7 Sep 2026 10:33:30 +0200 [thread overview]
Message-ID: <ap522nLwOCK-BFJo@krava> (raw)
In-Reply-To: <20260907053847.1115-2-zhaofuyu@vivo.com>
On Mon, Sep 07, 2026 at 01:38:46PM +0800, Fuyu Zhao wrote:
SNIP
> static int load_module_btfs(struct bpf_object *obj)
> {
> struct bpf_btf_info info;
> @@ -5825,6 +5842,9 @@ static int load_module_btfs(struct bpf_object *obj)
> if (!kernel_supports(obj, FEAT_MODULE_BTF))
> return 0;
>
> + if (obj->btf_module_allowlist_cnt == 0)
> + return 0;
> +
> while (true) {
> err = bpf_btf_get_next_id(id, &id);
> if (err && errno == ENOENT)
> @@ -5867,6 +5887,11 @@ static int load_module_btfs(struct bpf_object *obj)
> continue;
> }
>
> + if (!is_btf_mod_allowed(obj, name)) {
> + close(fd);
> + continue;
> + }
> +
> btf = btf_get_from_fd(fd, obj->btf_vmlinux);
> err = libbpf_get_error(btf);
> if (err) {
> @@ -5891,6 +5916,10 @@ static int load_module_btfs(struct bpf_object *obj)
> break;
> }
> obj->btf_module_cnt++;
> +
> + if (obj->btf_module_allowlist &&
IIUC you don't need to check obj->btf_module_allowlist,
because obj->btf_module_allowlist_cnt is -1 by default?
> + obj->btf_module_allowlist_cnt == obj->btf_module_cnt)
> + break;
> }
>
> if (err) {
> @@ -8426,8 +8455,10 @@ static struct bpf_object *bpf_object_open(const char *path, const void *obj_buf,
> const struct bpf_object_open_opts *opts)
> {
> const char *kconfig, *btf_tmp_path, *token_path;
> + const char **mod_allow;
> + int mod_allow_cnt;
> struct bpf_object *obj;
> - int err;
> + int err, i, j;
> char *log_buf;
> size_t log_size;
> __u32 log_level;
> @@ -8470,6 +8501,22 @@ static struct bpf_object *bpf_object_open(const char *path, const void *obj_buf,
> if (token_path && strlen(token_path) >= PATH_MAX)
> return ERR_PTR(-ENAMETOOLONG);
>
> + mod_allow = OPTS_GET(opts, btf_module_allowlist, NULL);
> + mod_allow_cnt = OPTS_GET(opts, btf_module_allowlist_cnt, 0);
> +
> + if ((!mod_allow && mod_allow_cnt > 0) || mod_allow_cnt < 0)
> + return ERR_PTR(-EINVAL);
> +
> + for (i = 0; i < mod_allow_cnt; i++) {
> + if (!mod_allow[i] || !mod_allow[i][0])
> + return ERR_PTR(-EINVAL);
> +
> + for (j = 0; j < i; j++) {
> + if (strcmp(mod_allow[i], mod_allow[j]) == 0)
> + return ERR_PTR(-EINVAL);
> + }
do we care if user supplied same name multiple times?
thanks,
jirka
> + }
> +
> obj = bpf_object__new(path, obj_buf, obj_buf_sz, obj_name);
> if (IS_ERR(obj))
> return obj;
next prev parent reply other threads:[~2026-09-07 8:33 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-07 5:38 [PATCH bpf-next v7 0/2] libbpf: improve BPF load performance by selectively loading module BTFs Fuyu Zhao
2026-09-07 5:38 ` [PATCH bpf-next v7 1/2] libbpf: support selective kernel module BTF loading via bpf_object_open_opts Fuyu Zhao
2026-09-07 5:49 ` sashiko-bot
2026-09-09 14:08 ` Fuyu Zhao
2026-09-07 8:33 ` Jiri Olsa [this message]
2026-09-09 14:08 ` Fuyu Zhao
2026-09-07 5:38 ` [PATCH bpf-next v7 2/2] selftests/bpf: add tests for selective module BTF loading Fuyu Zhao
2026-09-07 5:51 ` sashiko-bot
2026-09-09 14:08 ` Fuyu Zhao
2026-09-07 8:34 ` Jiri Olsa
2026-09-09 14:13 ` Fuyu Zhao
2026-09-08 16:03 ` bot+bpf-ci
2026-09-09 14:13 ` Fuyu Zhao
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=ap522nLwOCK-BFJo@krava \
--to=olsajiri@gmail.com \
--cc=alan.maguire@oracle.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=eddyz87@gmail.com \
--cc=zhaofuyu@vivo.com \
/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