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

Kumar Kartikeya Dwivedi <[email protected]>
Newsgroups dev.linux.lists.sashiko,org.kernel.vger.bpf
Message-ID <CAP01T75a_-GkmOvQSjcsziSTEFYgn8X-_zn8haLvh4OhoJ0f1A@mail.gmail.com>
On Sat, 18 Apr 2026 at 19:45, <[email protected]> wrote:
>
> 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 <[email protected]>
>
> 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?

Perhaps, I will check and adjust if necessary.

>
> [ ... ]
>
> > +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?

No, it's a non-common case.

>
> > +     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/[email protected]?part=4
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.