public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Alan Maguire" <alan.maguire@oracle.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 3/6] libbpf: Add feature for kernel extended vlen/kind support
Date: Tue, 14 Apr 2026 21:58:18 +0000	[thread overview]
Message-ID: <20260414215818.AE5DEC19425@smtp.kernel.org> (raw)
In-Reply-To: <20260414195019.684531-4-alan.maguire@oracle.com>

Sashiko AI review found 3 potential issue(s):
- [High] The feature probe incorrectly relies on finding an unused enum (`btf_max`) in the `vmlinux` BTF, guaranteeing it will permanently fail and falsely reject valid BPF objects.
- [High] The feature probe violates libbpf's probe architecture by reading the multi-megabyte `vmlinux` BTF instead of using lightweight `bpf()` syscalls, breaking containers and unprivileged token delegation.
- [Medium] The feature probe propagates negative errors when `vmlinux` BTF is absent, unconditionally spamming application logs with multiple warnings.
--

commit 3e8277b7bc260bfb527a032e5667d3e2d753d156
Author: Alan Maguire <alan.maguire@oracle.com>

libbpf: Add feature for kernel extended vlen/kind support
    
This commit adds a new feature probe to detect whether the kernel supports
extended BTF vlen and kind. It does this by loading the vmlinux BTF and
searching for an enum named btf_max with a BTF_MAX_VLEN member greater
than 0xffff.

> diff --git a/tools/lib/bpf/features.c b/tools/lib/bpf/features.c
> index 4f19a0d79b0cf..4a75d6717bbbd 100644
> --- a/tools/lib/bpf/features.c
> +++ b/tools/lib/bpf/features.c

[ ... ]

> @@ -615,6 +615,42 @@ static int probe_kern_btf_layout(int token_fd)
>  						 (char *)layout, token_fd));
>  }
>  
> +static int probe_kern_btf_vlen_kind_extended(int token_fd)
> +{
> +	struct btf *btf;
> +	int ret = 0;
> +	__s32 id;
> +	int err;
> +
> +	btf = btf__load_vmlinux_btf();
> +	err = libbpf_get_error(btf);
> +	if (err)
> +		return err;

If /sys/kernel/btf/vmlinux does not exist, btf__load_vmlinux_btf() returns
a negative error code. By returning this error directly, won't the
feat_supported() cache layer log a warning message? This seems like it will
spam logs on systems without vmlinux BTF.

Also, since this probe ignores token_fd, does it break BPF token delegation
for unprivileged environments? This approach introduces a dependency on
vmlinux BTF and adds parsing latency, compared to a lightweight bpf() syscall
probe.

> +	id = btf__find_by_name_kind(btf, "btf_max", BTF_KIND_ENUM);
> +	if (id > 0) {
> +		const struct btf_type *t;
> +		const struct btf_enum *e;
> +		const char *name;
> +		__u32 i, vlen;
> +
> +		t = btf__type_by_id(btf, id);
> +		if (t) {
> +			vlen = btf_vlen(t);
> +
> +			for (i = 0, e = btf_enum(t); i < vlen; i++, e++) {
> +				name = btf__name_by_offset(btf, e->name_off);
> +				if (!name || strcmp(name, "BTF_MAX_VLEN") != 0)
> +					continue;
> +				if (e->val > 0xffff)
> +					ret = 1;
> +			}
> +		}
> +	}
> +	btf__free(btf);
> +
> +	return ret;
> +}

Is enum btf_max actually instantiated in kernel C code?

If it is only used as a header construct, won't it be absent from the DWARF
debug info and the vmlinux BTF? If so, this probe would always fail to find
it, causing libbpf to unconditionally reject extended vlen/kind BTFs even on
capable kernels.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260414195019.684531-1-alan.maguire@oracle.com?part=3

  parent reply	other threads:[~2026-04-14 21:58 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-14 19:50 [PATCH bpf-next 0/6] btf: Extend vlen, kind in struct btf_type Alan Maguire
2026-04-14 19:50 ` [PATCH bpf-next 1/6] bpf: Extend BTF UAPI vlen, kinds to use unused bits Alan Maguire
2026-04-14 20:42   ` bot+bpf-ci
2026-04-14 21:11   ` sashiko-bot
2026-04-15 15:48     ` Mykyta Yatsenko
2026-04-14 19:50 ` [PATCH bpf-next 2/6] libbpf: Adjust btf_vlen() to return a __u32 Alan Maguire
2026-04-14 21:39   ` sashiko-bot
2026-04-14 19:50 ` [PATCH bpf-next 3/6] libbpf: Add feature for kernel extended vlen/kind support Alan Maguire
2026-04-14 20:29   ` bot+bpf-ci
2026-04-14 21:58   ` sashiko-bot [this message]
2026-04-15  1:56   ` Alexei Starovoitov
2026-04-15 15:57   ` Mykyta Yatsenko
2026-04-16  8:57     ` Alan Maguire
2026-04-16 14:15       ` Alexei Starovoitov
2026-04-14 19:50 ` [PATCH bpf-next 4/6] bpftool: Support 24-bit vlen Alan Maguire
2026-04-14 22:12   ` sashiko-bot
2026-04-14 19:50 ` [PATCH bpf-next 5/6] selftests/bpf: Test BTF sanitization rejection for invalid vlen Alan Maguire
2026-04-14 22:26   ` sashiko-bot
2026-04-15 16:03     ` Mykyta Yatsenko
2026-04-14 19:50 ` [PATCH bpf-next 6/6] selftests/bpf: Fix up btf/invalid test for extended kind Alan Maguire
2026-04-14 22:32   ` 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=20260414215818.AE5DEC19425@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=alan.maguire@oracle.com \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko@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