From: sashiko-bot@kernel.org
To: "Alan Maguire" <alan.maguire@oracle.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v2 bpf-next 1/2] libbpf: Allow use of feature cache for non-token cases
Date: Thu, 13 Aug 2026 23:50:06 +0000 [thread overview]
Message-ID: <20260813235010.BB8F71F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260408105324.663280-2-alan.maguire@oracle.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] `bpf_object_prepare_token` unconditionally overwrites `obj->feat_cache` if BPF tokens are supported, leaking any custom cache set by `bpf_object_set_feat_cache` and causing test mocking to be environment-dependent.
--
--- Patch [1]: [PATCH v2 bpf-next 1/2] libbpf: Allow use of feature cache for non-token cases ---
commit 118614ae13eed03565933d30357d27d00e3145b4
Author: Alan Maguire <alan.maguire@oracle.com>
libbpf: Allow use of feature cache for non-token cases
This patch exposes a new internal API, bpf_object_set_feat_cache(),
allowing BPF selftests to assign a custom feature cache to a bpf_object.
This enables simulating missing kernel features to test BTF sanitization
fallback paths.
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 42bdba4efd0c6..b7b636786d387 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
[ ... ]
> @@ -5203,12 +5203,20 @@ bool kernel_supports(const struct bpf_object *obj, enum kern_feature_id feat_id)
> */
> return true;
>
> - if (obj->token_fd)
> + if (obj->feat_cache)
> return feat_supported(obj->feat_cache, feat_id);
>
> return feat_supported(NULL, feat_id);
> }
>
> +/* Used in testing to simulate missing features. */
> +void bpf_object_set_feat_cache(struct bpf_object *obj, struct kern_feature_cache *cache)
> +{
> + if (obj->feat_cache)
> + zfree(&obj->feat_cache);
> + obj->feat_cache = cache;
> +}
> +
[Severity: Medium]
If a test sets a custom cache using this function and then loads the object,
could bpf_object_prepare_token() overwrite and leak this custom cache if BPF
token creation succeeds?
Looking at bpf_object_prepare_token(), it unconditionally allocates a new
cache when token creation is successful:
tools/lib/bpf/libbpf.c:bpf_object_prepare_token() {
...
obj->feat_cache = calloc(1, sizeof(*obj->feat_cache));
if (!obj->feat_cache) {
close(token_fd);
return -ENOMEM;
}
...
}
Would this cause testing environments to behave non-deterministically?
It seems tests might successfully preserve the mock cache on systems without
token delegation (where bpf_token_create fails and returns early), but lose
the mocked state and leak the initially injected cache on systems with token
support.
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260408105324.663280-1-alan.maguire@oracle.com?part=1
next prev parent reply other threads:[~2026-08-13 23:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-08 10:53 [PATCH v2 bpf-next 0/2] selftests/bpf: Test BTF sanitization Alan Maguire
2026-04-08 10:53 ` [PATCH v2 bpf-next 1/2] libbpf: Allow use of feature cache for non-token cases Alan Maguire
2026-04-08 13:37 ` Jiri Olsa
2026-08-13 23:50 ` sashiko-bot [this message]
2026-04-08 10:53 ` [PATCH v2 bpf-next 2/2] selftests/bpf: Add BTF sanitize test covering BTF layout Alan Maguire
2026-04-08 12:53 ` Chengkaitao
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=20260813235010.BB8F71F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=alan.maguire@oracle.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox