BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Toke Høiland-Jørgensen" <toke@toke.dk>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 4/7] libbpf: Move bpf_object_prepare_token() to object creation
Date: Thu, 26 Nov 2026 13:38:05 +0000	[thread overview]
Message-ID: <sashiko-outbox-235632@kernel.org> (raw)
In-Reply-To: <20261126-bpf-relax-get-next-id-v2-4-039e92757f9c@toke.dk>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] libbpf: bpf_object_open() runs bpf_object_prepare_token()
  before gen_loader
--

commit c11c45202857082e826eb4bc3551463d49a2d5fa
Author: Toke Høiland-Jørgensen <toke@toke.dk>

libbpf: Move bpf_object_prepare_token() to object creation

This commit moves bpf_object_prepare_token() from bpf_object_prepare() to
bpf_object_open() so that the BPF token is available before loading the
object, such as during BTF access in bpf_program__set_attach_target().

> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 540daf7752b45..6d0e71aff3e14 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -9281,6 +9281,7 @@ static struct bpf_object *bpf_object_open(const char *path, const void *obj_buf,
>  	err = err ? : bpf_object__init_maps(obj, opts);
>  	err = err ? : bpf_object_init_progs(obj, opts);
>  	err = err ? : bpf_object__collect_relos(obj);
> +	err = err ? : bpf_object_prepare_token(obj);
>  	if (err)
>  		goto out;
>  

[Severity: Medium]
Does calling bpf_object_prepare_token() during bpf_object_open() bypass the
obj->gen_loader check added in d92defe04ad5 ("libbpf: Skip BPF token
preparation when generating loader")?

obj->gen_loader is only set when the caller invokes bpf_object__gen_loader()
on the already-opened object, so it is always NULL inside bpf_object_open():

tools/lib/bpf/libbpf.c:bpf_object_prepare_token() {
	...
	if (obj->gen_loader)
		return 0;
	...
}

If the host has a token-delegated bpffs mounted at /sys/fs/bpf (or
LIBBPF_BPF_TOKEN_PATH set), bpf_object_open() populates obj->token_fd and
bpf_object__gen_loader() does not clear it.  Subsequent calls to
bpf_object__create_map() and bpf_object_load_prog() then set BPF_F_TOKEN_FD
in the generated loader program's map_flags and prog_flags without a
runtime token_fd, causing the generated loader to fail at runtime.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-bpf-relax-get-next-id-v2-0-039e92757f9c@toke.dk?part=4

  reply	other threads:[~2026-11-26 13:38 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 13:20 [PATCH bpf-next v2 0/7] Improvements to access module BTF with bpf_token Toke Høiland-Jørgensen
2026-11-26 13:20 ` [PATCH bpf-next v2 1/7] bpf: Relax BPF_*_GET_NEXT_ID permission checks to CAP_BPF and bpf_token Toke Høiland-Jørgensen
2026-11-26 13:53   ` bot+bpf-ci
2026-11-26 13:21 ` [PATCH bpf-next v2 2/7] libbpf: Add bpf_*_get_next_id_opts() functions Toke Høiland-Jørgensen
2026-11-26 13:21 ` [PATCH bpf-next v2 3/7] libbpf: Automatically set BPF_F_TOKEN_FD when getting BTF fd Toke Høiland-Jørgensen
2026-11-26 13:21 ` [PATCH bpf-next v2 4/7] libbpf: Move bpf_object_prepare_token() to object creation Toke Høiland-Jørgensen
2026-11-26 13:38   ` sashiko-bot [this message]
2026-11-26 13:52     ` Toke Høiland-Jørgensen
2026-11-26 13:21 ` [PATCH bpf-next v2 5/7] libbpf: Pass in token_fd when iterating kernel BTF objects Toke Høiland-Jørgensen
2026-11-26 13:21 ` [PATCH bpf-next v2 6/7] selftests/bpf: Explicitly disable token in token/obj_priv_freplace_prog_fail test Toke Høiland-Jørgensen
2026-11-26 13:53   ` bot+bpf-ci
2026-11-26 13:21 ` [PATCH bpf-next v2 7/7] selftests/bpf: Add test for attaching fentry to a module with bpf_token Toke Høiland-Jørgensen

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-235632@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=toke@toke.dk \
    /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