public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v3 4/4] selftests/bpf: Test verifier warning logging
Date: Sat, 18 Apr 2026 18:45:51 +0000	[thread overview]
Message-ID: <20260418184552.8C983C19424@smtp.kernel.org> (raw)
In-Reply-To: <20260418171701.610025-5-memxor@gmail.com>

Sashiko AI review found 1 potential issue(s):
- [Medium] The custom `libbpf_print_cb` unconditionally buffers all log levels into a fixed 4096-byte buffer, which will inevitably overflow during skeleton load and silently drop the expected verifier warnings.
--

commit 602c54794881684bfce8f29591c7e680ab7d51fe
Author: Kumar Kartikeya Dwivedi <memxor@gmail.com>

selftests/bpf: Test verifier warning logging

This commit adds test coverage for explicit verifier warning logging and 
libbpf's default warning flush path while keeping the warning bit private 
to the test.

> diff --git a/tools/testing/selftests/bpf/prog_tests/kfunc_implicit_args.c b/tools/testing/selftests/bpf/prog_tests/kfunc_implicit_args.c
> index 5e4793c9c29a0..f92a27d764557 100644
> --- a/tools/testing/selftests/bpf/prog_tests/kfunc_implicit_args.c
> +++ b/tools/testing/selftests/bpf/prog_tests/kfunc_implicit_args.c
> @@ -4,7 +4,99 @@
>  #include <test_progs.h>
>  #include "kfunc_implicit_args.skel.h"
>  
> +#define TEST_BPF_LOG_LEVEL_WARN	(1U << 4)
> +
> +static size_t libbpf_log_pos;
> +static char libbpf_log_buf[4096];
> +static bool libbpf_log_error;
> +
> +static int libbpf_print_cb(enum libbpf_print_level level, const char *fmt, va_list args)
> +{
> +	int emitted_cnt;
> +	size_t left_cnt;
> +
> +	(void)level;
> +
> +	left_cnt = sizeof(libbpf_log_buf) - libbpf_log_pos;
> +	emitted_cnt = vsnprintf(libbpf_log_buf + libbpf_log_pos, left_cnt, fmt, args);
> +	if (emitted_cnt < 0 || emitted_cnt + 1 > left_cnt) {
> +		libbpf_log_error = true;
> +		return 0;
> +	}

Since libbpf generates a high volume of LIBBPF_DEBUG and LIBBPF_INFO messages
during object load, will this unconditionally buffer all log levels and overflow
the 4096-byte buffer before the load completes?

If the buffer overflows, libbpf_log_error becomes true and subsequent messages
(including the expected verifier warnings flushed at the end of the load) will
be discarded.

Should this callback filter out non-warning levels to avoid filling the buffer
too quickly?

[ ... ]

> +static void test_default_warning_flush(void)
> +{
> +	libbpf_print_fn_t old_print_cb = libbpf_set_print(libbpf_print_cb);
> +	struct kfunc_implicit_args *skel = NULL;
> +	int err;
> +
> +	libbpf_log_pos = 0;
> +	libbpf_log_buf[0] = '\0';
> +	libbpf_log_error = false;
> +
> +	skel = kfunc_implicit_args__open();
> +	if (!ASSERT_OK_PTR(skel, "skel_open"))
> +		goto cleanup;
> +
> +	select_legacy_impl_prog(skel);
> +
> +	err = kfunc_implicit_args__load(skel);
> +	ASSERT_OK(err, "skel_load");
> +	ASSERT_FALSE(libbpf_log_error, "libbpf_log_error");

Will this assertion predictably fail due to the buffer overflow mentioned
above?

> +	ASSERT_OK_PTR(strstr(libbpf_log_buf, "-- BEGIN PROG LOAD WARNINGS --"), "warn_banner");
> +	ASSERT_OK_PTR(strstr(libbpf_log_buf,
> +			     "uses deprecated kfunc bpf_kfunc_implicit_arg_legacy_impl()"),
> +		      "warn_msg");
> +	ASSERT_NULL(strstr(libbpf_log_buf, "-- BEGIN PROG LOAD LOG --"), "no_verbose_log");
> +
> +cleanup:
> +	kfunc_implicit_args__destroy(skel);
> +	libbpf_set_print(old_print_cb);
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260418171701.610025-1-memxor@gmail.com?part=4

  reply	other threads:[~2026-04-18 18:45 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-18 17:16 [PATCH bpf-next v3 0/4] Add support to emit verifier warnings Kumar Kartikeya Dwivedi
2026-04-18 17:16 ` [PATCH bpf-next v3 1/4] bpf: Add support for verifier warning messages Kumar Kartikeya Dwivedi
2026-04-18 17:42   ` sashiko-bot
2026-04-18 20:33     ` Kumar Kartikeya Dwivedi
2026-04-20 13:37   ` Mykyta Yatsenko
2026-04-20 15:26     ` Kumar Kartikeya Dwivedi
2026-04-18 17:16 ` [PATCH bpf-next v3 2/4] bpf: Introduce __bpf_kfunc_mark_deprecated annotation Kumar Kartikeya Dwivedi
2026-04-18 18:06   ` sashiko-bot
2026-04-18 20:34     ` Kumar Kartikeya Dwivedi
2026-04-20 14:21   ` Mykyta Yatsenko
2026-04-20 15:27     ` Kumar Kartikeya Dwivedi
2026-04-20 18:15   ` David Faust
2026-04-20 18:19     ` Kumar Kartikeya Dwivedi
2026-04-18 17:16 ` [PATCH bpf-next v3 3/4] libbpf: Request verifier warnings for object loads Kumar Kartikeya Dwivedi
2026-04-18 18:35   ` sashiko-bot
2026-04-18 20:38     ` Kumar Kartikeya Dwivedi
2026-04-20 13:57   ` Mykyta Yatsenko
2026-04-20 15:23     ` Kumar Kartikeya Dwivedi
2026-04-20 15:49       ` Alexei Starovoitov
2026-04-18 17:16 ` [PATCH bpf-next v3 4/4] selftests/bpf: Test verifier warning logging Kumar Kartikeya Dwivedi
2026-04-18 18:45   ` sashiko-bot [this message]
2026-04-18 20:39     ` Kumar Kartikeya Dwivedi

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=20260418184552.8C983C19424@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=memxor@gmail.com \
    --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