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 v4 4/6] libbpf: Pass in token_fd when iterating kernel BTF objects
Date: Mon, 30 Nov 2026 11:38:00 +0000	[thread overview]
Message-ID: <sashiko-outbox-240964@kernel.org> (raw)
In-Reply-To: <20261130-bpf-relax-get-next-id-v4-4-807e2b53cc22@toke.dk>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] libbpf: commit message mismatch with EINVAL handling in
  load_module_btfs()
--

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

libbpf: Pass in token_fd when iterating kernel BTF objects

This commit passes obj->token_fd to bpf_btf_get_next_id_opts() and
bpf_btf_get_fd_by_id_opts() when iterating and loading kernel module BTFs
in load_module_btfs().

> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 2aa3d3e33cc2d..ce748b8bde96e 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -6020,6 +6020,9 @@ static bool is_btf_mod_allowed(const struct bpf_object *obj, const char *name)
>  
>  static int load_module_btfs(struct bpf_object *obj)
>  {
> +	DECLARE_LIBBPF_OPTS(bpf_get_fd_by_id_opts, opts,
> +			    .open_flags = obj->token_fd ? BPF_F_TOKEN_FD : 0,
> +			    .token_fd = obj->token_fd);
>  	struct bpf_btf_info info;
>  	struct module_btf *mod_btf;
>  	struct btf *btf;
> @@ -6044,10 +6047,10 @@ static int load_module_btfs(struct bpf_object *obj)
>  		return 0;
>  
>  	while (true) {
> -		err = bpf_btf_get_next_id(id, &id);
> +		err = bpf_btf_get_next_id_opts(id, &id, &opts);
>  		if (err && errno == ENOENT)
>  			return 0;
> -		if (err && errno == EPERM) {
> +		if (err && (errno == EPERM || (errno == EINVAL && opts.token_fd))) {
>  			pr_debug("skipping module BTFs loading, missing privileges\n");
>  			return 0;
>  		}
> @@ -6057,10 +6060,14 @@ static int load_module_btfs(struct bpf_object *obj)
>  			return err;
>  		}
>  
> -		fd = bpf_btf_get_fd_by_id(id);
> +		fd = bpf_btf_get_fd_by_id_opts(id, &opts);
>  		if (fd < 0) {
>  			if (errno == ENOENT)
>  				continue; /* expected race: BTF was unloaded */
> +			if (errno == EPERM) {
> +				pr_debug("skipping module BTFs loading, missing privileges\n");
> +				return 0;
> +			}

[Severity: Low]
Does the commit message match how load_module_btfs() handles EINVAL?

The changelog states that on EINVAL from older kernels, load_module_btfs()
resets any tokens and tries again, but the code instead treats
(errno == EINVAL && opts.token_fd) the same as EPERM, logs a debug message
about missing privileges, and returns 0 without retrying.  The changelog
also does not mention the new EPERM check after
bpf_btf_get_fd_by_id_opts().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130-bpf-relax-get-next-id-v4-0-807e2b53cc22@toke.dk?part=4

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

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 11:26 [PATCH bpf-next v4 0/6] Improvements to access module BTF with bpf_token Toke Høiland-Jørgensen
2026-11-30 11:26 ` [PATCH bpf-next v4 1/6] bpf: Allow BPF_*_GET_NEXT_ID permission checks to pass " Toke Høiland-Jørgensen
2026-11-30 11:26 ` [PATCH bpf-next v4 2/6] libbpf: Add bpf_btf_get_next_id_opts() function Toke Høiland-Jørgensen
2026-11-30 11:27 ` [PATCH bpf-next v4 3/6] libbpf: Move bpf_object_prepare_token() to object creation Toke Høiland-Jørgensen
2026-11-30 11:42   ` sashiko-bot
2026-11-30 11:27 ` [PATCH bpf-next v4 4/6] libbpf: Pass in token_fd when iterating kernel BTF objects Toke Høiland-Jørgensen
2026-11-30 11:38   ` sashiko-bot [this message]
2026-11-30 11:49     ` Toke Høiland-Jørgensen
2026-11-30 11:27 ` [PATCH bpf-next v4 5/6] selftests/bpf: Explicitly disable token in token/obj_priv_freplace_prog_fail test Toke Høiland-Jørgensen
2026-11-30 11:27 ` [PATCH bpf-next v4 6/6] 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-240964@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