From: Jay Vosburgh <jv@jvosburgh.net>
To: Jiayuan Chen <jiayuan.chen@linux.dev>
Cc: netdev@vger.kernel.org, jiayuna.chen@linux.dev,
jiayuna.chen@shopee.com, Jiayuan Chen <jiayuan.chen@shopee.com>,
syzbot+80e046b8da2820b6ba73@syzkaller.appspotmail.com,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Jesper Dangaard Brouer <hawk@kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
Stanislav Fomichev <sdf@fomichev.me>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Martin KaFai Lau <martin.lau@linux.dev>,
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>, Shuah Khan <shuah@kernel.org>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Clark Williams <clrkwllms@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Jussi Maki <joamaki@gmail.com>,
linux-kernel@vger.kernel.org, bpf@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-rt-devel@lists.linux.dev
Subject: Re: [PATCH net v3 1/2] bonding: fix null-ptr-deref in bond_rr_gen_slave_id()
Date: Fri, 27 Feb 2026 19:01:47 -0800 [thread overview]
Message-ID: <999129.1772247707@famine> (raw)
In-Reply-To: <20260228021918.141002-2-jiayuan.chen@linux.dev>
Jiayuan Chen <jiayuan.chen@linux.dev> wrote:
>From: Jiayuan Chen <jiayuan.chen@shopee.com>
>
>bond_rr_gen_slave_id() dereferences bond->rr_tx_counter without a NULL
>check. rr_tx_counter is a per-CPU counter only allocated in bond_open()
>when the bond mode is round-robin. If the bond device was never brought
>up, rr_tx_counter remains NULL, causing a null-ptr-deref.
>
>The XDP redirect path can reach this code even when the bond is not up:
>bpf_master_redirect_enabled_key is a global static key, so when any bond
>device has native XDP attached, the XDP_TX -> xdp_master_redirect()
>interception is enabled for all bond slaves system-wide. This allows the
>path xdp_master_redirect() -> bond_xdp_get_xmit_slave() ->
>bond_xdp_xmit_roundrobin_slave_get() -> bond_rr_gen_slave_id() to be
>reached on a bond that was never opened.
>
>The normal TX path (bond_xmit_roundrobin) is not affected because TX
>requires the bond to be UP, which guarantees rr_tx_counter is allocated.
>However, bond_xmit_get_slave() (ndo_get_xmit_slave) has the same code
>pattern via bond_xmit_roundrobin_slave_get() and could theoretically
>hit the same issue.
As a practical matter, though, I don't think the
ndo_get_xmit_slave path can actually hit the issue, as that looks to
only be called from Infiniband, which is only supported in bonding for
active-backup mode.
>Fix this by allocating rr_tx_counter unconditionally in bond_init()
>(ndo_init), which is called by register_netdevice() and covers both
>device creation paths (bond_create() and bond_newlink()). This also
>handles the case where bond mode is changed to round-robin after device
>creation. The conditional allocation in bond_open() is removed. Since
>bond_destructor() already unconditionally calls
>free_percpu(bond->rr_tx_counter), the lifecycle is clean: allocate at
>ndo_init, free at destructor.
>
>Fixes: 879af96ffd72 ("net, core: Add support for XDP redirection to slave device")
>Reported-by: syzbot+80e046b8da2820b6ba73@syzkaller.appspotmail.com
>Closes: https://lore.kernel.org/all/698f84c6.a70a0220.2c38d7.00cc.GAE@google.com/T/
>Signed-off-by: Jiayuan Chen <jiayuan.chen@shopee.com>
My only concern is that this will waste a percpu u32 per bond
device for the majority of bonding use cases (which use modes other than
balance-rr), which could be a few hundred bytes on a large machine.
Does everything work reliably if the rr_tx_counter allocation
happens conditionally on mode == BOND_MODE_ROUNDROBIN in bond_setup, as
well as in bond_option_mode_set?
-J
>---
> drivers/net/bonding/bond_main.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
>diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
>index 78cff904cdc3..9f63f67d8418 100644
>--- a/drivers/net/bonding/bond_main.c
>+++ b/drivers/net/bonding/bond_main.c
>@@ -4279,12 +4279,6 @@ static int bond_open(struct net_device *bond_dev)
> struct list_head *iter;
> struct slave *slave;
>
>- if (BOND_MODE(bond) == BOND_MODE_ROUNDROBIN && !bond->rr_tx_counter) {
>- bond->rr_tx_counter = alloc_percpu(u32);
>- if (!bond->rr_tx_counter)
>- return -ENOMEM;
>- }
>-
> /* reset slave->backup and slave->inactive */
> if (bond_has_slaves(bond)) {
> bond_for_each_slave(bond, slave, iter) {
>@@ -6411,6 +6405,12 @@ static int bond_init(struct net_device *bond_dev)
> if (!bond->wq)
> return -ENOMEM;
>
>+ bond->rr_tx_counter = alloc_percpu(u32);
>+ if (!bond->rr_tx_counter) {
>+ destroy_workqueue(bond->wq);
>+ return -ENOMEM;
>+ }
>+
> bond->notifier_ctx = false;
>
> spin_lock_init(&bond->stats_lock);
>--
>2.43.0
>
---
-Jay Vosburgh, jv@jvosburgh.net
next prev parent reply other threads:[~2026-02-28 3:01 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-28 2:19 [PATCH net v3 0/2] net,bpf: fix null-ptr-deref in xdp_master_redirect() for bonding and add selftest Jiayuan Chen
2026-02-28 2:19 ` [PATCH net v3 1/2] bonding: fix null-ptr-deref in bond_rr_gen_slave_id() Jiayuan Chen
2026-02-28 3:01 ` Jay Vosburgh [this message]
2026-02-28 3:36 ` Jiayuan Chen
2026-03-02 8:10 ` Sebastian Andrzej Siewior
2026-03-02 10:15 ` Jiayuan Chen
2026-03-04 2:38 ` Jay Vosburgh
2026-02-28 2:19 ` [PATCH net v3 2/2] selftests/bpf: add test for xdp_master_redirect with bond not up Jiayuan Chen
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=999129.1772247707@famine \
--to=jv@jvosburgh.net \
--cc=andrew+netdev@lunn.ch \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bigeasy@linutronix.de \
--cc=bpf@vger.kernel.org \
--cc=clrkwllms@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=jiayuan.chen@linux.dev \
--cc=jiayuan.chen@shopee.com \
--cc=jiayuna.chen@linux.dev \
--cc=jiayuna.chen@shopee.com \
--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=linux-rt-devel@lists.linux.dev \
--cc=martin.lau@linux.dev \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rostedt@goodmis.org \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=syzbot+80e046b8da2820b6ba73@syzkaller.appspotmail.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.