From nobody Fri Apr 17 01:42:38 2026 Received: from out-178.mta1.migadu.com (out-178.mta1.migadu.com [95.215.58.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F2D6E37C0ED; Tue, 24 Feb 2026 11:26:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771932385; cv=none; b=hND8bDNhx581fLokq0aFs3J2fvS7UXxZ/sPzL+igTa0ynuBkDH6WsM/Tu9lxMbphz+ikogldp0ZI6kJMiGPxRJmF6GJdY53S4pSmHZaM8gyV3FnlA/YH21eJQygVoYEtET0o4zZAvm5xwrzWLsjaBACiQqz5BFDREx9b3ZxAfOk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771932385; c=relaxed/simple; bh=jKGpRtkQmoW/eINjEEeqokeSEboufukG5iJM7QvxWh0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tvcjVKoOY2pOzR5qvwpwgmdRggse3hwa+rKzN5US9Jd2BtINAssKy4T2axbysB+pXVKmIwswKZKHqIR6GMOLkUx01IAEgT8iD7DIHDmzEYZYuRYbWGMQyakVGuGqCFY3k1Sy9VBMGbhpviXGdRXVCglBq/T/74vNb3+F58n98Ng= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=KdMRzram; arc=none smtp.client-ip=95.215.58.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="KdMRzram" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1771932381; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=C9tpplCFFUxBSafBcz5oJn5FmlATJrojlSyiIAZIo2Y=; b=KdMRzramMNNyoFSDwyRphg5gnvY3iXBbKZPBKhM7p/qNhi5CVmpDAad73Xf2qBPXAlI1NR tst3CG+ZlPeWnvuCODmSQA74++8DkYTlRIDCG8lAfwpKrdYakZBLhOt0IOAf6zg9gdaV+z Vxi9nP3KXi7qT5bEh02Fw5CvK4ZjLjg= From: Jiayuan Chen To: bpf@vger.kernel.org Cc: jiayuan.chen@linux.dev, jiayuan.chen@shopee.com, syzbot+80e046b8da2820b6ba73@syzkaller.appspotmail.com, Martin KaFai Lau , Daniel Borkmann , John Fastabend , Stanislav Fomichev , Alexei Starovoitov , Andrii Nakryiko , Eduard Zingerman , Song Liu , Yonghong Song , KP Singh , Hao Luo , Jiri Olsa , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jesper Dangaard Brouer , Shuah Khan , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Jussi Maki , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-rt-devel@lists.linux.dev Subject: [PATCH bpf v1 1/2] net/bpf: fix null-ptr-deref in xdp_master_redirect() for bonding Date: Tue, 24 Feb 2026 19:25:41 +0800 Message-ID: <20260224112545.37888-2-jiayuan.chen@linux.dev> In-Reply-To: <20260224112545.37888-1-jiayuan.chen@linux.dev> References: <20260224112545.37888-1-jiayuan.chen@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT From: Jiayuan Chen xdp_master_redirect() dereferences the master device pointer and calls ndo_xdp_get_xmit_slave() without checking whether the master is valid or running. When a bond device in round-robin mode has never been brought up, bond->rr_tx_counter is not allocated (only allocated in bond_open()). The XDP redirect path can still reach bond_rr_gen_slave_id() via xdp_master_redirect() =E2=86=92 bond_xdp_get_xmit_slave() =E2=86=92 bond_xdp_xmit_roundrobin_slave_get(), causing a null-ptr-deref on rr_tx_counter. bpf_master_redirect_enabled_key is a global static key. When any bond device has native XDP attached, this key is enabled system-wide, causing the XDP_TX =E2=86=92 xdp_master_redirect interception to fire for all bond slaves, even slaves of other bond devices that have never been opened. To trigger, the following conditions must be met: 1. A bond (bond0) with native XDP attached, enabling the global key 2. Another bond (bond1) in round-robin mode, never brought up 3. A slave (veth1) of bond1 with generic XDP returning XDP_TX 4. Packets hitting the generic XDP path on veth1 Add a check in xdp_master_redirect() to verify the master device is valid and running before proceeding with the redirect. This is semantically correct because redirecting to a non-running master is meaningless, and safe from a concurrency perspective because xdp_master_redirect() runs under RCU protection and the master's resources are not freed until after an RCU grace period. Fixes: 879af96ffd72 ("net, core: Add support for XDP redirection to slave d= evice") Reported-by: syzbot+80e046b8da2820b6ba73@syzkaller.appspotmail.com Closes: https://lore.kernel.org/all/698f84c6.a70a0220.2c38d7.00cc.GAE@googl= e.com/T/ Signed-off-by: Jiayuan Chen --- net/core/filter.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/core/filter.c b/net/core/filter.c index ba019ded773d..9a45dabd0044 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -4387,6 +4387,9 @@ u32 xdp_master_redirect(struct xdp_buff *xdp) struct net_device *master, *slave; =20 master =3D netdev_master_upper_dev_get_rcu(xdp->rxq->dev); + if (unlikely(!master || !netif_running(master))) + return XDP_TX; + slave =3D master->netdev_ops->ndo_xdp_get_xmit_slave(master, xdp); if (slave && slave !=3D xdp->rxq->dev) { /* The target device is different from the receiving device, so --=20 2.43.0 From nobody Fri Apr 17 01:42:38 2026 Received: from out-180.mta1.migadu.com (out-180.mta1.migadu.com [95.215.58.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 15A5837C108 for ; Tue, 24 Feb 2026 11:26:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771932397; cv=none; b=ANyGS14FKZIJ5JfAiZWiOX/RyCxmSNzAVSY7A4trv/NCnGTojhz6ExPARJ3gbue3X+U9uwxlevP0qdk5muoHsceAaQJk0OpluFZXoyDWHvsx+r5hMZD02ffuOAJZV3HLGRdHXE6cR6CdkyZqj3Vp77Rwn3IiVN1dSu/yjjEWtFY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771932397; c=relaxed/simple; bh=fYbwPjoB0B6WapO2IIEk5YfxUqhtJJwkyOAqKTNQ2iA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TQugliBo6EnRr+WXM0VfuQdxCp4kpLIOHHXSdfRwJFWjyyV1VppjlxOtm4UtkmCzZlBkwPBhSqTqIat1unNn2vrCAj5HA/oIYSMIeL71vuuVH8r/rJQvg6/YaJvJbJb4psPx3H80AF1sQtcuE0rDhG3ZiTEmww3aX3HDzcr0FO0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=SxTOGyFg; arc=none smtp.client-ip=95.215.58.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="SxTOGyFg" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1771932393; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HiIMuGQMxMcZdO73qW3Y4B5sJf41fthkzOkigm4psIA=; b=SxTOGyFgtoNgcpSf2Y16jDjtlgzxG17sA34xN5auAHOcP0ukOk0iOhiPGXK2XBfzDLd3xv dIF2OkWgMhF1Doesz3LajScgBZEUOAKQkUQ2kNO4xhn0Db0vhVgMT3KSOt+/xlxRhnlVQD 7voMovTUtgrgIe20qkNEHfanK20TPfs= From: Jiayuan Chen To: bpf@vger.kernel.org Cc: jiayuan.chen@linux.dev, jiayuan.chen@shopee.com, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jesper Dangaard Brouer , Shuah Khan , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Jussi Maki , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-rt-devel@lists.linux.dev Subject: [PATCH bpf v1 2/2] selftests/bpf: add test for xdp_master_redirect with bond not up Date: Tue, 24 Feb 2026 19:25:42 +0800 Message-ID: <20260224112545.37888-3-jiayuan.chen@linux.dev> In-Reply-To: <20260224112545.37888-1-jiayuan.chen@linux.dev> References: <20260224112545.37888-1-jiayuan.chen@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Jiayuan Chen Add a selftest that verifies xdp_master_redirect() does not crash when the bond master device has never been brought up. The test reproduces the null-ptr-deref in bond_rr_gen_slave_id() by: 1. Creating bond0 (active-backup, UP) with native XDP attached to enable the global bpf_master_redirect_enabled_key 2. Creating bond1 (round-robin, never UP) with veth1 enslaved 3. Attaching generic XDP (XDP_TX) to veth1 4. Running BPF_PROG_TEST_RUN with live frames and XDP_PASS on veth1 to inject packets into the generic XDP path Without the fix in xdp_master_redirect(), step 4 causes a kernel crash. Signed-off-by: Jiayuan Chen --- .../selftests/bpf/prog_tests/xdp_bonding.c | 101 +++++++++++++++++- 1 file changed, 99 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_bonding.c b/tools/t= esting/selftests/bpf/prog_tests/xdp_bonding.c index fb952703653e..a5b15e464018 100644 --- a/tools/testing/selftests/bpf/prog_tests/xdp_bonding.c +++ b/tools/testing/selftests/bpf/prog_tests/xdp_bonding.c @@ -191,13 +191,18 @@ static int bonding_setup(struct skeletons *skeletons,= int mode, int xmit_policy, return -1; } =20 -static void bonding_cleanup(struct skeletons *skeletons) +static void link_cleanup(struct skeletons *skeletons) { - restore_root_netns(); while (skeletons->nlinks) { skeletons->nlinks--; bpf_link__destroy(skeletons->links[skeletons->nlinks]); } +} + +static void bonding_cleanup(struct skeletons *skeletons) +{ + restore_root_netns(); + link_cleanup(skeletons); ASSERT_OK(system("ip link delete bond1"), "delete bond1"); ASSERT_OK(system("ip link delete veth1_1"), "delete veth1_1"); ASSERT_OK(system("ip link delete veth1_2"), "delete veth1_2"); @@ -493,6 +498,95 @@ static void test_xdp_bonding_nested(struct skeletons *= skeletons) system("ip link del bond_nest2"); } =20 +/* + * Test that XDP redirect via xdp_master_redirect() does not crash when + * the bond master device is not up. When bond is in round-robin mode but + * never opened, rr_tx_counter is NULL. + */ +static void test_xdp_bonding_redirect_no_up(struct skeletons *skeletons) +{ + struct nstoken *nstoken =3D NULL; + int xdp_pass_fd, xdp_tx_fd; + int veth1_ifindex; + int err; + char pkt[ETH_HLEN + 1]; + struct xdp_md ctx_in =3D {}; + + DECLARE_LIBBPF_OPTS(bpf_test_run_opts, opts, + .data_in =3D &pkt, + .data_size_in =3D sizeof(pkt), + .ctx_in =3D &ctx_in, + .ctx_size_in =3D sizeof(ctx_in), + .flags =3D BPF_F_TEST_XDP_LIVE_FRAMES, + .repeat =3D 1, + .batch_size =3D 1, + ); + + /* We can't use bonding_setup() because bond will be active */ + SYS(out, "ip netns add ns_rr_no_up"); + nstoken =3D open_netns("ns_rr_no_up"); + if (!ASSERT_OK_PTR(nstoken, "open ns_rr_no_up")) + goto out; + + /* bond0: active-backup, UP with slave veth0. + * Attaching native XDP to bond0 enables bpf_master_redirect_enabled_key + * globally. + */ + SYS(out, "ip link add bond0 type bond mode active-backup"); + SYS(out, "ip link add veth0 type veth peer name veth0p"); + SYS(out, "ip link set veth0 master bond0"); + SYS(out, "ip link set bond0 up"); + SYS(out, "ip link set veth0p up"); + + /* bond1: round-robin, never UP -> rr_tx_counter stays NULL */ + SYS(out, "ip link add bond1 type bond mode balance-rr"); + SYS(out, "ip link add veth1 type veth peer name veth1p"); + SYS(out, "ip link set veth1 master bond1"); + + veth1_ifindex =3D if_nametoindex("veth1"); + if (!ASSERT_GT(veth1_ifindex, 0, "veth1_ifindex")) + goto out; + + /* Attach native XDP to bond0 -> enables global redirect key */ + if (xdp_attach(skeletons, skeletons->xdp_tx->progs.xdp_tx, "bond0")) + goto out; + + /* 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 =3D bpf_program__fd(skeletons->xdp_tx->progs.xdp_tx); + if (!ASSERT_GE(xdp_tx_fd, 0, "xdp_tx prog_fd")) + goto out; + + err =3D 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 =3D 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 =3D bpf_program__fd(skeletons->xdp_dummy->progs.xdp_dummy_pro= g); + if (!ASSERT_GE(xdp_pass_fd, 0, "xdp_pass prog_fd")) + goto out; + + memset(pkt, 0, sizeof(pkt)); + ctx_in.data_end =3D sizeof(pkt); + ctx_in.ingress_ifindex =3D veth1_ifindex; + + err =3D bpf_prog_test_run_opts(xdp_pass_fd, &opts); + ASSERT_OK(err, "xdp_pass test_run should not crash"); + +out: + link_cleanup(skeletons); + close_netns(nstoken); + SYS_NOFAIL("ip netns del ns_rr_no_up"); +} + static void test_xdp_bonding_features(struct skeletons *skeletons) { LIBBPF_OPTS(bpf_xdp_query_opts, query_opts); @@ -680,6 +774,9 @@ void serial_test_xdp_bonding(void) if (test__start_subtest("xdp_bonding_redirect_multi")) test_xdp_bonding_redirect_multi(&skeletons); =20 + if (test__start_subtest("xdp_bonding_redirect_no_up")) + test_xdp_bonding_redirect_no_up(&skeletons); + out: xdp_dummy__destroy(skeletons.xdp_dummy); xdp_tx__destroy(skeletons.xdp_tx); --=20 2.43.0