From: sashiko-bot@kernel.org
To: "Emil Tsalapatis" <emil@etsalapatis.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v4 3/3] selftests/bpf: libarena: parallel test harness and spmc parallel selftest
Date: Fri, 05 Jun 2026 22:28:51 +0000 [thread overview]
Message-ID: <20260605222851.EF9351F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260605222020.5231-4-emil@etsalapatis.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Missing file descriptor (FD) validation after manual program lookups.
--
commit f9cb27c914dcd0d4f6eca457c86b2aac266e34a4
Author: Emil Tsalapatis <emil@etsalapatis.com>
selftests/bpf: libarena: parallel test harness and spmc parallel selftest
Add a parallel test for the SPMC Lev-Chase workstealing queue. The queue
is built to be wait-free even when there are multiple consumers, and
the parallel selftest provides a signal on whether the queue behaves
correctly when stress tested.
> diff --git a/tools/testing/selftests/bpf/prog_tests/libarena.c b/tools/testing/selftests/bpf/prog_tests/libarena.c
> index 81bdb084c2715..aa2070f8be825 100644
> --- a/tools/testing/selftests/bpf/prog_tests/libarena.c
> +++ b/tools/testing/selftests/bpf/prog_tests/libarena.c
> @@ -27,6 +27,177 @@ static void run_libarena_test(struct libarena *skel, struct bpf_program *prog,
>
> }
>
> +static void *run_libarena_parallel_prog(void *arg)
> +{
> + struct bpf_program *prog = arg;
> +
> + return (void *)(long)libarena_run_prog(bpf_program__fd(prog));
[Severity: Medium]
Should we validate the file descriptor returned by bpf_program__fd here?
The program is manually looked up via bpf_object__find_program_by_name
in run_libarena_parallel_test_workers before being passed to this thread
worker. When using manual lookups instead of auto-generated skeleton fields,
the program pointer could be valid while the underlying program is invalid,
resulting in a negative FD.
An ASSERT_GE check for the file descriptor could prevent unexpected behavior.
> +}
> +
> +/* Max suffix is ceil((lg 2^32) / (lg 10)) + sizeof("__") = 10 + 2 = 12. */
> +#define MAX_PARTEST_SUFFIX (12)
> +#define MAX_PARTEST_NAME (1024)
> +#define MAX_PARTEST_PREFIX (MAX_PARTEST_NAME - MAX_PARTEST_SUFFIX)
> +
> +static int run_libarena_parallel_fini(struct libarena *skel, const char *name,
> + size_t prefixlen)
> +{
> + char tdname[MAX_PARTEST_NAME];
> + struct bpf_program *fini_prog;
> + int ret;
> +
> + ret = snprintf(tdname, sizeof(tdname), "%.*s__fini", (int)prefixlen, name);
> + if (!ASSERT_LT(ret, sizeof(tdname), "partest fini name"))
> + return -ENAMETOOLONG;
> +
> + fini_prog = bpf_object__find_program_by_name(skel->obj, tdname);
> + if (!ASSERT_TRUE(fini_prog, "partest fini prog"))
> + return -ENOENT;
> +
> + ret = libarena_run_prog(bpf_program__fd(fini_prog));
[Severity: Medium]
Does this missing file descriptor check risk passing a negative FD to
libarena_run_prog?
Similar to the above, we manually look up fini_prog. Checking the return
value of bpf_program__fd with ASSERT_GE before using it would align with
the BPF selftest guidelines for manual lookups.
> + ASSERT_OK(ret, tdname);
> +
> + return ret;
> +}
[ ... ]
> +static bool libarena_parallel_test_enabled(struct libarena *skel,
> + const char *prefix,
> + size_t prefixlen)
> +{
> + struct bpf_program *prog;
> + char progname[MAX_PARTEST_NAME];
> + int ret;
> +
> + ret = snprintf(progname, sizeof(progname), "%.*s__enabled", (int)prefixlen,
> + prefix);
> + if (!ASSERT_LT(ret, sizeof(progname), "partest enabled name"))
> + return false;
> +
> + prog = bpf_object__find_program_by_name(skel->obj, progname);
> + if (!prog)
> + return true;
> +
> + ret = libarena_run_prog(bpf_program__fd(prog));
[Severity: Medium]
Should we verify that the FD returned by bpf_program__fd is non-negative
before executing it?
Because progname is dynamically constructed and manually looked up, we do
not have the same FD validity guarantees as we do for auto-generated
skeleton fields.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260605222020.5231-1-emil@etsalapatis.com?part=3
next prev parent reply other threads:[~2026-06-05 22:28 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-05 22:20 [PATCH bpf-next v4 0/3] selftests/bpf: libarena: Add initial data structures Emil Tsalapatis
2026-06-05 22:20 ` [PATCH bpf-next v4 1/3] selftests/bpf: libarena: Add rbtree data structure Emil Tsalapatis
2026-06-05 22:30 ` sashiko-bot
2026-06-05 23:01 ` Emil Tsalapatis
2026-06-05 22:51 ` bot+bpf-ci
2026-06-05 22:20 ` [PATCH bpf-next v4 2/3] selftests/bpf: libarena: Add spmc queue " Emil Tsalapatis
2026-06-05 22:51 ` bot+bpf-ci
2026-06-05 22:20 ` [PATCH bpf-next v4 3/3] selftests/bpf: libarena: parallel test harness and spmc parallel selftest Emil Tsalapatis
2026-06-05 22:28 ` sashiko-bot [this message]
2026-06-05 22:51 ` bot+bpf-ci
2026-06-06 3:40 ` [PATCH bpf-next v4 0/3] selftests/bpf: libarena: Add initial data structures patchwork-bot+netdevbpf
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=20260605222851.EF9351F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=emil@etsalapatis.com \
--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