Re: [PATCH bpf-next v3 4/4] selftests/bpf: Test verifier warning logging

sashiko-bot
2026-04-18T18:45:52Z

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