From: "Toke Høiland-Jørgensen" <toke@redhat.com>
To: sashiko-reviews@lists.linux.dev
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 2/4] bpf: selftests: Check for flag presence in bpf_program__flags()
Date: Tue, 01 Sep 2026 10:02:59 +0200 [thread overview]
Message-ID: <87y0dlv1os.fsf@toke.dk> (raw)
In-Reply-To: <20260831134450.680941F000E9@smtp.kernel.org>
sashiko-bot@kernel.org writes:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] Missing NULL pointer check on the result of bpf_object__next_program() causes a potential test crash.
> --
>
> commit 357b58adee859a9375d4063d6f64aa4a923e7790
> Author: Toke Høiland-Jørgensen <toke@redhat.com>
>
> bpf: selftests: Check for flag presence in bpf_program__flags()
>
> This commit adds checks to verify that the BPF_F_XDP_HAS_FRAGS and
> BPF_F_SLEEPABLE flags are correctly exposed by bpf_program__flags(). It
> introduces assertions in multiple selftests immediately after retrieving
> the BPF program structures.
>
>> diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_frags.c b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_frags.c
>> index fce203640f8cf..a894b1ab46f4e 100644
>> --- a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_frags.c
>> +++ b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_frags.c
>> @@ -18,6 +18,9 @@ static void test_xdp_update_frags(void)
>> return;
>>
>> prog = bpf_object__next_program(obj, NULL);
>> + ASSERT_EQ(bpf_program__flags(prog) & BPF_F_XDP_HAS_FRAGS,
>> + BPF_F_XDP_HAS_FRAGS, "frags in program flags");
>> +
>
> [Severity: Medium]
> What happens if bpf_object__next_program() returns a NULL pointer here?
>
> The prog pointer is passed directly to bpf_program__flags(), which
> unconditionally dereferences it. While the object file is expected to contain
> programs during normal builds, if it does not, could this cause the test suite
> to hard crash with a segmentation fault instead of failing gracefully?
>
> Prior to this patch, a NULL prog would be handled more safely, as the later
> call to bpf_program__fd() explicitly checks for NULL and returns an error
> code.
>
> Does it make sense to add a check like ASSERT_OK_PTR(prog, "prog") before
> accessing its flags?
No. This won't happen, and existing code already use the pointer without
checking it.
-Toke
next prev parent reply other threads:[~2026-09-01 8:09 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 13:26 [PATCH bpf-next v2 1/4] libbpf: Move section-defined program flags to prog_flags Toke Høiland-Jørgensen
2026-08-31 13:26 ` [PATCH bpf-next v2 2/4] bpf: selftests: Check for flag presence in bpf_program__flags() Toke Høiland-Jørgensen
2026-08-31 13:44 ` sashiko-bot
2026-09-01 8:02 ` Toke Høiland-Jørgensen [this message]
2026-08-31 14:18 ` bot+bpf-ci
2026-09-01 8:03 ` Toke Høiland-Jørgensen
2026-08-31 13:26 ` [PATCH bpf-next v2 3/4] bpftool: Set BPF_F_XDP_DEV_BOUND_ONLY flag non-destructively Toke Høiland-Jørgensen
2026-08-31 13:39 ` Larysa Zaremba
2026-08-31 13:26 ` [PATCH bpf-next v2 4/4] selftests/bpf: Set BPF program flags non-destructively Toke Høiland-Jørgensen
2026-08-31 14:18 ` bot+bpf-ci
2026-09-01 8:11 ` Toke Høiland-Jørgensen
2026-08-31 14:32 ` [PATCH bpf-next v2 1/4] libbpf: Move section-defined program flags to prog_flags bot+bpf-ci
2026-09-01 8:30 ` Toke Høiland-Jørgensen
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=87y0dlv1os.fsf@toke.dk \
--to=toke@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox