All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Andrey Grodzovsky" <andrey.grodzovsky@crowdstrike.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 5/5] selftests/bpf: Cover BPF program dynamic loading
Date: Wed, 26 Aug 2026 18:33:51 +0000	[thread overview]
Message-ID: <20260826183351.92BE31F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260826181825.1826541-6-andrey.grodzovsky@crowdstrike.com>

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] Calling `bpf_program__load_dynamically()` multiple times on the same program overwrites `prog->fd` and leaks the previously loaded BPF program's file descriptor.
- [Medium] bpf_link leaked on error paths leaves system-wide raw tracepoint active.
- [Low] Multi-line comments do not follow the mandatory BPF subsystem style.
- [Low] `dynamicload_verify_override()` is skipped entirely if the preceding `test_dynamicload` logic encounters a failure.
- [Low] Missing early return check for state-altering assertion allows test execution to continue in an invalid state.
--

commit eb781cf99ff72cd5528638c785d25a5ff470c1c9
Author: Slava Imameev <slava.imameev@crowdstrike.com>

selftests/bpf: Cover BPF program dynamic loading

This commit adds load_type and dynamicload tests to verify the per-program load
type enum (disabled/auto/dynamic) and its transitions. It also tests the full
lifecycle of dynamic load/attach/reattach/unload.

> diff --git a/tools/testing/selftests/bpf/prog_tests/dynamicload.c b/tools/testing/selftests/bpf/prog_tests/dynamicload.c
> new file mode 100644
> index 0000000000000..799c43034ff92
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/dynamicload.c
> @@ -0,0 +1,222 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#include <test_progs.h>
> +#include <time.h>
> +#include "test_dynamicload.skel.h"
> +
> +/* prog4 is tagged __load_dynamic in the source instead of being set
> + * imperatively; verify that an explicit bpf_program__set_load_type() call
> + * before load overrides the tag's declarative default.
> + */

[Severity: Low]
This isn't a bug, but this multi-line comment does not follow the mandatory BPF
subsystem style, which requires the opening '/*' to be on its own line.

> +static void dynamicload_verify_override(void)
> +{
[ ... ]
> +void test_dynamicload(void)
> +{
> +	struct bpf_link *link;
> +	struct test_dynamicload *skel;
> +	int err;
> +
> +	skel = test_dynamicload__open();
> +	if (!ASSERT_OK_PTR(skel, "skel_open"))
> +		return;
> +
> +	/* the __load_dynamic tag alone, with no imperative call, must set
> +	 * prog4's load type before it is ever touched below
> +	 */

[Severity: Low]
This isn't a bug, but this multi-line comment also does not follow the
mandatory BPF subsystem style.

[ ... ]
> +	/* attach prog3 */
> +	link = bpf_program__attach(skel->progs.prog3);
> +	if (!ASSERT_OK_PTR(link, "attach"))
> +		goto cleanup;
> +
> +	usleep(1);
> +
> +	if (!ASSERT_TRUE(skel->bss->prog3_called, "prog3_called"))
> +		goto cleanup;

[Severity: Medium]
Does this code leak the manually managed link object and leave the system-wide
raw tracepoint active if this assertion fails? The cleanup path only destroys
the skeleton, which doesn't track this standalone bpf_link object.

[ ... ]
> +	err = bpf_program__unload_dynamically(skel->progs.prog4);
> +	ASSERT_OK(err, "prog4_unload_dynamically");
> +
> +	test_dynamicload__destroy(skel);
> +
> +	/* separate scenario: imperative override of the declarative tag */
> +	dynamicload_verify_override();
> +	return;
> +
> +cleanup:
> +	test_dynamicload__destroy(skel);
> +}

[Severity: Low]
Is it intentional that dynamicload_verify_override() is skipped entirely if the
preceding test_dynamicload() logic encounters a failure and jumps to cleanup?
This could mask test coverage since it won't be reported as executed or skipped.

> diff --git a/tools/testing/selftests/bpf/prog_tests/load_type.c b/tools/testing/selftests/bpf/prog_tests/load_type.c
> new file mode 100644
> index 0000000000000..fc91f6666c506
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/load_type.c
> @@ -0,0 +1,167 @@
[ ... ]
> +	/* bpf_program__set_autoload() is a thin forwarder to set_load_type(),
> +	 * restricted to AUTO/DISABLED to preserve its original bool on/off
> +	 * meaning; it does change the load type of a program that isn't
> +	 * currently BPF_PROG_LOAD_TYPE_AUTO.
> +	 */

[Severity: Low]
This isn't a bug, but this multi-line comment does not follow the mandatory BPF
subsystem style, which requires the opening '/*' to be on its own line.

[ ... ]
> +	/* loaded program type cannot be changed */
> +	err = bpf_program__set_load_type(skel->progs.prog3, BPF_PROG_LOAD_TYPE_DISABLED);
> +	ASSERT_ERR(err, "set_load_type_after_load");
> +
> +	err = test_load_type__attach(skel);

[Severity: Low]
Should there be an early return check here? Without it, if the underlying API
mistakenly succeeds, the program's load state is incorrectly modified to
DISABLED and the test continues running, which could cause cascading and
confusing failures.

[ ... ]
> +	err = bpf_program__load_dynamically(skel->progs.prog3, 0);
> +	if (!ASSERT_OK(err, "load_dynamically_1"))
> +		goto cleanup;
> +
> +	err = bpf_program__load_dynamically(skel->progs.prog3, 0);
> +	if (!ASSERT_OK(err, "load_dynamically_2"))
> +		goto cleanup;

[Severity: High]
Does calling bpf_program__load_dynamically() multiple times on the same program
overwrite prog->fd and leak the previously loaded BPF program's file descriptor?
The test seems to actively rely on this behavior by loading the program twice
without an intervening unload.

> +
> +	/* attach prog3 */
> +	link = bpf_program__attach(skel->progs.prog3);
> +	if (!ASSERT_OK_PTR(link, "attach"))
> +		goto cleanup;
> +
> +	usleep(1);
> +
> +	if (!ASSERT_TRUE(skel->bss->prog3_called, "prog3_called_again"))
> +		goto cleanup;

[Severity: Medium]
Will this bypass bpf_link__destroy(link) and leak the system-wide tracepoint
attachment if the assertion fails and jumps to cleanup?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260826181825.1826541-1-andrey.grodzovsky@crowdstrike.com?part=5

  reply	other threads:[~2026-08-26 18:33 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-26 18:18 [PATCH bpf-next v2 0/5] libbpf: BPF program dynamic loading Andrey Grodzovsky
2026-08-26 18:18 ` [PATCH bpf-next v2 1/5] libbpf: BPF program load type enum Andrey Grodzovsky
2026-08-26 19:25   ` bot+bpf-ci
2026-09-11 23:43   ` Andrii Nakryiko
2026-08-26 18:18 ` [PATCH bpf-next v2 2/5] libbpf: BPF programs dynamic loading and attaching Andrey Grodzovsky
2026-08-26 18:33   ` sashiko-bot
2026-08-26 19:38   ` bot+bpf-ci
2026-09-11 23:44   ` Andrii Nakryiko
2026-09-17  0:39     ` Andrey Grodzovsky
2026-09-17 21:51       ` Andrii Nakryiko
2026-09-18 18:29         ` Andrey Grodzovsky
2026-08-26 18:18 ` [PATCH bpf-next v2 3/5] libbpf: Convert bpf_program__set_autoload() to load-type enum Andrey Grodzovsky
2026-08-26 18:34   ` sashiko-bot
2026-08-26 19:25   ` bot+bpf-ci
2026-09-11 23:44   ` Andrii Nakryiko
2026-09-17  0:03     ` Andrey Grodzovsky
2026-08-26 18:18 ` [PATCH bpf-next v2 4/5] libbpf: Support declarative dynamic load via BTF decl_tag Andrey Grodzovsky
2026-08-26 18:33   ` sashiko-bot
2026-08-26 19:25   ` bot+bpf-ci
2026-08-26 18:18 ` [PATCH bpf-next v2 5/5] selftests/bpf: Cover BPF program dynamic loading Andrey Grodzovsky
2026-08-26 18:33   ` sashiko-bot [this message]
2026-08-26 19:25   ` bot+bpf-ci
2026-09-11 23:44   ` Andrii Nakryiko
2026-09-17  0:04     ` Andrey Grodzovsky
2026-09-11 23:43 ` [PATCH bpf-next v2 0/5] libbpf: " Andrii Nakryiko
2026-09-17  0:45   ` Andrey Grodzovsky
2026-09-18  0:49     ` Andrey Grodzovsky
2026-09-22 16:36       ` Andrii Nakryiko

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=20260826183351.92BE31F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=andrey.grodzovsky@crowdstrike.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 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.