public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiayuan Chen <jiayuan.chen@linux.dev>
To: Daniel Borkmann <daniel@iogearbox.net>, netdev@vger.kernel.org
Cc: Martin KaFai Lau <martin.lau@linux.dev>,
	John Fastabend <john.fastabend@gmail.com>,
	Stanislav Fomichev <sdf@fomichev.me>,
	Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	KP Singh <kpsingh@kernel.org>, Hao Luo <haoluo@google.com>,
	Jiri Olsa <jolsa@kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	Shuah Khan <shuah@kernel.org>, Jussi Maki <joamaki@gmail.com>,
	bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org,
	Nikolay Aleksandrov <razor@blackwall.org>
Subject: Re: [PATCH net v6 2/2] selftests/bpf: add test for xdp_master_redirect with bond not up
Date: Sat, 11 Apr 2026 08:51:31 +0800	[thread overview]
Message-ID: <dc734e36-e2e4-4932-aa6d-c9bb72eed64f@linux.dev> (raw)
In-Reply-To: <f8782293-1ec5-474d-b288-e2546016869b@iogearbox.net>


On 4/11/26 12:28 AM, Daniel Borkmann wrote:
> On 4/10/26 1:37 PM, Jiayuan Chen wrote:
>> Add a selftest that reproduces the null-ptr-deref in
>> bond_rr_gen_slave_id() when XDP redirect targets a bond device in
>> round-robin mode that was never brought up. The test verifies the fix
>> by ensuring no crash occurs.
>>
>> Test setup:
>> - bond0: active-backup mode, UP, with native XDP (enables
>>    bpf_master_redirect_enabled_key globally)
>> - bond1: round-robin mode, never UP
>> - veth1: slave of bond1, with generic XDP (XDP_TX)
>> - BPF_PROG_TEST_RUN with live frames triggers the redirect path
>>
>> Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
>
> I checked locally that this XDP test passes fine and triggers a NULL
> pointer deref without the fix.
>
> [...]
>> +    /* Attach generic XDP (XDP_TX) to veth1.
>> +     * When packets arrive at veth1 via netif_receive_skb, 
>> do_xdp_generic()
>> +     * runs this program. XDP_TX + bond slave triggers 
>> xdp_master_redirect().
>> +     */
>> +    xdp_tx_fd = bpf_program__fd(skeletons->xdp_tx->progs.xdp_tx);
>> +    if (!ASSERT_GE(xdp_tx_fd, 0, "xdp_tx prog_fd"))
>> +        goto out;
>
> nit: no need for the ASSERT_GE given the skeleton loaded, see also the 
> various
> other tests gathering bpf_program__fd().
>
>> +    err = bpf_xdp_attach(veth1_ifindex, xdp_tx_fd,
>> +                 XDP_FLAGS_SKB_MODE, NULL);
>> +    if (!ASSERT_OK(err, "attach generic XDP to veth1"))
>> +        goto out;
>> +
>> +    /* Run BPF_PROG_TEST_RUN with XDP_PASS live frames on veth1.
>> +     * XDP_PASS frames become SKBs with skb->dev = veth1, entering
>> +     * netif_receive_skb -> do_xdp_generic -> xdp_master_redirect.
>> +     * Without the fix, bond_rr_gen_slave_id() dereferences NULL
>> +     * rr_tx_counter and crashes.
>> +     */
>> +    xdp_pass_fd = 
>> bpf_program__fd(skeletons->xdp_dummy->progs.xdp_dummy_prog);
>> +    if (!ASSERT_GE(xdp_pass_fd, 0, "xdp_pass prog_fd"))
>> +        goto out;
>
> ditto, can be simplified a bit into:
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_bonding.c 
> b/tools/testing/selftests/bpf/prog_tests/xdp_bonding.c
> index 0d4ec1e5b401..c42488e445c2 100644
> --- a/tools/testing/selftests/bpf/prog_tests/xdp_bonding.c
> +++ b/tools/testing/selftests/bpf/prog_tests/xdp_bonding.c
> @@ -506,7 +506,7 @@ static void test_xdp_bonding_nested(struct 
> skeletons *skeletons)
>  static void test_xdp_bonding_redirect_no_up(struct skeletons *skeletons)
>  {
>      struct nstoken *nstoken = NULL;
> -    int xdp_pass_fd, xdp_tx_fd;
> +    int xdp_pass_fd;
>      int veth1_ifindex;
>      int err;
>      char pkt[ETH_HLEN + 1];
> @@ -555,11 +555,8 @@ static void 
> test_xdp_bonding_redirect_no_up(struct skeletons *skeletons)
>       * When packets arrive at veth1 via netif_receive_skb, 
> do_xdp_generic()
>       * runs this program. XDP_TX + bond slave triggers 
> xdp_master_redirect().
>       */
> -    xdp_tx_fd = bpf_program__fd(skeletons->xdp_tx->progs.xdp_tx);
> -    if (!ASSERT_GE(xdp_tx_fd, 0, "xdp_tx prog_fd"))
> -        goto out;
> -
> -    err = bpf_xdp_attach(veth1_ifindex, xdp_tx_fd,
> +    err = bpf_xdp_attach(veth1_ifindex,
> + bpf_program__fd(skeletons->xdp_tx->progs.xdp_tx),
>                   XDP_FLAGS_SKB_MODE, NULL);
>      if (!ASSERT_OK(err, "attach generic XDP to veth1"))
>          goto out;
> @@ -571,8 +568,6 @@ static void test_xdp_bonding_redirect_no_up(struct 
> skeletons *skeletons)
>       * rr_tx_counter and crashes.
>       */
>      xdp_pass_fd = 
> bpf_program__fd(skeletons->xdp_dummy->progs.xdp_dummy_prog);
> -    if (!ASSERT_GE(xdp_pass_fd, 0, "xdp_pass prog_fd"))
> -        goto out;
>
>      memset(pkt, 0, sizeof(pkt));
>      ctx_in.data_end = sizeof(pkt);
>
Hi daniel

Thanks for the review and for verifying the crash reproduces without the 
fix.

I've applied your suggestion.



      reply	other threads:[~2026-04-11  0:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-10 11:37 [PATCH net v6 0/2] net,bpf: fix null-ptr-deref in xdp_master_redirect() for bonding and add selftest Jiayuan Chen
2026-04-10 11:37 ` [PATCH net v6 1/2] net, bpf: fix null-ptr-deref in xdp_master_redirect() for down master Jiayuan Chen
2026-04-10 15:42   ` Daniel Borkmann
2026-04-10 11:37 ` [PATCH net v6 2/2] selftests/bpf: add test for xdp_master_redirect with bond not up Jiayuan Chen
2026-04-10 16:28   ` Daniel Borkmann
2026-04-11  0:51     ` Jiayuan Chen [this message]

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=dc734e36-e2e4-4932-aa6d-c9bb72eed64f@linux.dev \
    --to=jiayuan.chen@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=eddyz87@gmail.com \
    --cc=edumazet@google.com \
    --cc=haoluo@google.com \
    --cc=hawk@kernel.org \
    --cc=horms@kernel.org \
    --cc=joamaki@gmail.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=razor@blackwall.org \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=yonghong.song@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