All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Toke Høiland-Jørgensen" <toke@toke.dk>
To: sashiko-reviews@lists.linux.dev
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v3 4/7] libbpf: Move bpf_object_prepare_token() to object creation
Date: Thu, 26 Nov 2026 20:44:07 +0100	[thread overview]
Message-ID: <87pkvrcr94.fsf@toke.dk> (raw)
In-Reply-To: <sashiko-outbox-235780@kernel.org>

sashiko-bot@kernel.org writes:

> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Low] libbpf: dead gen_loader check and host token probe in
>   bpf_object_open()
> --
>
> commit bfc72a1132d0b5606c8e46c132afab5bec32d57f
> 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() and closes any acquired token fd in
> bpf_object__gen_loader().
>
>> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
>> index 540daf7752b45..1f1569a35f92a 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;
>>  
>> @@ -9873,7 +9874,6 @@ static int bpf_object_prepare(struct bpf_object *obj, const char *target_btf_pat
>>  	}
>>  
>>  	err = bpf_object_check_gen_loader(obj);
>> -	err = err ? : bpf_object_prepare_token(obj);
>>  	err = err ? : bpf_object__probe_loading(obj);
>>  	err = err ? : bpf_object__load_vmlinux_btf(obj, false);
>>  	err = err ? : bpf_object__resolve_externs(obj, obj->kconfig);
>> @@ -10543,6 +10543,11 @@ int bpf_object__gen_loader(struct bpf_object *obj, struct gen_loader_opts *opts)
>>  	gen->opts = opts;
>>  	gen->swapped_endian = !is_native_endianness(obj);
>>  	obj->gen_loader = gen;
>> +	if (obj->token_fd) {
>> +		close(obj->token_fd);
>> +		obj->token_fd = 0;
>> +		obj->feat_cache->token_fd = 0;
>> +	}
>>  	return 0;
>>  }
>
> [Severity: Low]
> Does moving bpf_object_prepare_token() into bpf_object_open() make the
> obj->gen_loader check in bpf_object_prepare_token() unreachable and
> reintroduce host bpffs probing during offline loader generation?
>
> Commit d92defe04ad5 ("libbpf: Skip BPF token preparation when generating
> loader") added an early return on obj->gen_loader to
> bpf_object_prepare_token() so that offline loader generation (such as
> bpftool gen skeleton -L) would not probe /sys/fs/bpf or honor
> LIBBPF_BPF_TOKEN_PATH on the build host.  Because bpf_object_open() now
> calls bpf_object_prepare_token() before returning obj to the caller,
> bpf_object__gen_loader() cannot have been called yet and obj->gen_loader is
> always NULL there.  If LIBBPF_BPF_TOKEN_PATH or opts.bpf_token_path is set
> to a non-empty path that cannot be opened or does not allow token creation
> on the host, bpf_object_open() fails before bpf_object__gen_loader() can be
> reached.

I can remove the dead check for obj->gen_loader, but I don't think the
other issue is worth fixing; if someone explicitly sets a token path
during skeleton build and that makes the build fail, they can just...
not do that?

-Toke

  reply	other threads:[~2026-11-26 19:44 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 14:51 [PATCH bpf-next v3 0/7] Improvements to access module BTF with bpf_token Toke Høiland-Jørgensen
2026-11-26 14:51 ` [PATCH bpf-next v3 1/7] bpf: Relax BPF_*_GET_NEXT_ID permission checks to CAP_BPF and bpf_token Toke Høiland-Jørgensen
2026-11-26 15:19   ` bot+bpf-ci
2026-11-28  2:59   ` Alexei Starovoitov
2026-11-28 12:51     ` Toke Høiland-Jørgensen
2026-11-26 14:51 ` [PATCH bpf-next v3 2/7] libbpf: Add bpf_*_get_next_id_opts() functions Toke Høiland-Jørgensen
2026-11-26 14:51 ` [PATCH bpf-next v3 3/7] libbpf: Automatically set BPF_F_TOKEN_FD when getting BTF fd Toke Høiland-Jørgensen
2026-11-26 14:51 ` [PATCH bpf-next v3 4/7] libbpf: Move bpf_object_prepare_token() to object creation Toke Høiland-Jørgensen
2026-11-26 15:11   ` sashiko-bot
2026-11-26 19:44     ` Toke Høiland-Jørgensen [this message]
2026-11-26 15:47   ` bot+bpf-ci
2026-11-26 19:46     ` Toke Høiland-Jørgensen
2026-11-26 14:51 ` [PATCH bpf-next v3 5/7] libbpf: Pass in token_fd when iterating kernel BTF objects Toke Høiland-Jørgensen
2026-11-26 14:51 ` [PATCH bpf-next v3 6/7] selftests/bpf: Explicitly disable token in token/obj_priv_freplace_prog_fail test Toke Høiland-Jørgensen
2026-11-26 14:51 ` [PATCH bpf-next v3 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=87pkvrcr94.fsf@toke.dk \
    --to=toke@toke.dk \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.