Article View: linux.kernel.netdev
Article #22343Re: [PATCH net v2] bonding: unbind 802.3ad slaves on enslave failure
From: Nikolay Aleksandrov
Date: Wed, 25 Nov 2026 07:14
Date: Wed, 25 Nov 2026 07:14
124 lines
16076 bytes
16076 bytes
On 24/11/2026 04:41, Lin Jiapeng wrote:
> From: Lin Jiapeng <jiapenglin@tencent.com>
>
> The 802.3ad enslave path binds a slave before publishing it in the bond's
> slave list. The periodic state machine can select the port and attach it to
> a LAG while enslavement is in progress, including while NETDEV_CHANGEUPPER
> notifiers are running.
>
> If enslavement fails, rollback can free ad_slave_info without unbinding its
> port and leave later LAG processing with a dangling pointer. This affects
> both a failed upper-link notification and later failures such as
> bond_sysfs_slave_add(). A test-only kretprobe forces the latter to return
> -ENOMEM, after which KASAN reports:
> BUG: KASAN: slab-use-after-free in ad_agg_selection_logic+0x1a0d/0x1fa0
> Read of size 1 by task kworker/u16:0/13
> Freed by task 110:
> kfree
> slave_kobj_release
> kobject_put
> bond_enslave
>
> Drain the RX handler before unbinding so receive handlers cannot race with
> port->slave becoming NULL. Unbind before upper unlink when the link exists,
> and also unbind after an upper-link failure without repeating the unlink.
> Rebuild the slave array after aggregator changes and leave earlier
> unpublished failures unchanged.
>
> Fixes: 07699f9a7c8d ("bonding: add sysfs /slave dir for bond slave devices.")
> Reported-by: TencentOS Corvus AI <corvus@tencent.com>
> Link: https://lore.kernel.org/netdev/20261113130454.63032-1-ljp1205831794@gmail.com/
> ---
> v1 -> v2:
> - Drain the RX handler before unbinding to avoid NULL dereferences in the
> 802.3ad receive path.
> - Cover NETDEV_CHANGEUPPER failure after transient upper-link publication,
> without repeating upper-dev unlink.
> - Rebuild the 802.3ad slave array after rollback.
>
> drivers/net/bonding/bond_main.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
> index e9f5e753f677..7ca948bb27d0 100644
> --- a/drivers/net/bonding/bond_main.c
> +++ b/drivers/net/bonding/bond_main.c
> @@ -2355,10 +2355,21 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
> bond_sysfs_slave_del(new_slave);
>
> err_upper_unlink:
> + netdev_rx_handler_unregister(slave_dev);
> + if (BOND_MODE(bond) == BOND_MODE_8023AD)
> + bond_3ad_unbind_slave(new_slave);
> bond_upper_dev_unlink(bond, new_slave);
> + goto err_update_slave_arr;
>
> err_unregister:
> netdev_rx_handler_unregister(slave_dev);
> + if (BOND_MODE(bond) == BOND_MODE_8023AD)
> + bond_3ad_unbind_slave(new_slave);
> +
> +err_update_slave_arr:
> + if (BOND_MODE(bond) == BOND_MODE_8023AD &&
> + bond_update_slave_arr(bond, new_slave))
> + bond_slave_arr_work_rearm(bond, 0);
>
> err_detach:
> vlan_vids_del_by_dev(slave_dev, bond_dev);
>
> base-commit: 7e1392a42ea288d70a266f6553fe06f57f8647ea
This looks awful jumping around error labels and doing the same thing
at different places. Surely you could rearrange them better, maybe
something like this (untested, needs proper review):
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1888,10 +1888,11 @@
int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
struct netlink_ext_ack *extack)
{
+ const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
struct bonding *bond = netdev_priv(bond_dev);
- const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
struct slave *new_slave = NULL, *prev_slave;
struct sockaddr_storage ss;
+ bool upper_linked = false;
int res = 0, i;
if (slave_dev->type == ARPHRD_CAN ||
@@ -2246,13 +2247,14 @@
slave_dbg(bond_dev, slave_dev, "Error %d calling bond_master_upper_dev_link\n", res);
goto err_unregister;
}
+ upper_linked = true;
bond_lower_state_changed(new_slave);
res = bond_sysfs_slave_add(new_slave);
if (res) {
slave_dbg(bond_dev, slave_dev, "Error %d calling bond_sysfs_slave_add\n", res);
- goto err_upper_unlink;
+ goto err_unregister;
}
/* If the mode uses primary, then the following is handled by
@@ -2357,11 +2359,15 @@
err_sysfs_del:
bond_sysfs_slave_del(new_slave);
-err_upper_unlink:
- bond_upper_dev_unlink(bond, new_slave);
-
err_unregister:
netdev_rx_handler_unregister(slave_dev);
+ if (BOND_MODE(bond) == BOND_MODE_8023AD) {
+ bond_3ad_unbind_slave(new_slave);
+ if (bond_update_slave_arr(bond, new_slave))
+ bond_slave_arr_work_rearm(bond, 0);
+ }
+ if (upper_linked)
+ bond_upper_dev_unlink(bond, new_slave);
err_detach:
vlan_vids_del_by_dev(slave_dev, bond_dev);
Technical Details
Message-ID:
<654889ea-3b83-4fd4-b283-184f87b3d208@blackwall.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-371087-linux-kernel-netdev=dewy.ruReferences:
<20261124024319.52145-1-ljp1205831794@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-371087-linux-kernel-netdev=dewy.ru
From: razor@blackwall.org (Nikolay Aleksandrov)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2] bonding: unbind 802.3ad slaves on enslave failure
Date: Wed, 25 Nov 2026 09:14:17 +0200
Organization: Usenet Network
Message-ID: <654889ea-3b83-4fd4-b283-184f87b3d208@blackwall.org>
References: <20261124024319.52145-1-ljp1205831794@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
logging-data="142359"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:0NKkAOmXXup3cllX1ts1Amjg+jA= sha256:2xZffIKVR6DA9n50K0KHGeDgCH6f1l16nln663+ImSk=
sha1:eQbfHy0kP22LTBPcBoiapPZ9hoM= sha256:ZsGgy86Y808Z0NpyYmFlSLbKtb5/6ScX/nyvRXYQ3io=
Content-Language: en-US, bg
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id D8AFC125E40; Wed, 25 Nov 2026 10:14:39 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.05
X-Spam-Status: No, score=-3.05 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=blackwall.org
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id aB578lfrzS06;
Wed, 25 Nov 2026 10:14:36 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-371087-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=blackwall.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id 8D9B0125E3F; Wed, 25 Nov 2026 10:14:26 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by tor.lore.kernel.org (Postfix) with ESMTP id F2AFE37A2D; Wed, 25 Nov 2026 07:14:24 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1795590864;
b=pAHQOLI+AWixZxgvjdlwmt0ml7C+/aYL7RkiIGUKTB/WiZmIZaaLAGXc1su9JepRE7LG
3+DmEGOfu2gv0pOOcaozt2UUC2CBy3TxFxEIq9bvHQ/4usZ0jUp//2IkrtywlooCLPYzH
Wfu+7vLOySE5kqHlXNp1vAney9Wea3ChDbnhd+k9ZjRzebyEB74XL4UUsttoY8S9B0mYk
E/SZMN/dYy1xQ4p2bwbljnLutSPKQ7m6Rej1w/iCluPQhLVL2HcGYbA8lsVO8o+vim9Nd
+RYWCnjk89g9hOAhA38tMkxRWK7FbWx658jAh7dsF8fH3MBpeVGEhWjpm2tkAF7qh2A==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795590864;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
X-Gm-Gg:X-Received:Received:Message-ID:Date:X-Mailing-List:List-Id:
List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
Precedence:MIME-Version:User-Agent:Subject:Content-Language:To:Cc:
References:From:In-Reply-To:Content-Type:Content-Transfer-Encoding;
bh=OS4S/3wgJzlNANveRHhJ0JCqQT7lj4OoQJmmJFDLZnQ=;
b=H6if1mmHdup6erEKI8SoMPQM8WJpySsCA+5lyrgQu+DEQEl//ts2QxbSaZiWeVcshYci
rMQveceXdExRMu9b5NHaNMofIX86VoR90ypWIP1W8rfNA1EYNICwh7QNgfl1ClDaW9y9Z
cxRg2/Zc6NBSBoyWe5roXGiY0sqoIKs3HOg5R+8ObxH7L3MBUta0uf+b1J2VC1s9MzWdj
RzbUISytiWx1ZZ9znzlJOQEX1ofBVsZfh1mEhlS4QzXt2M6TpIsFs4KPdGxt3yKWAMLA0
0JqDhyGVwuMHiBXgB1FAnayNvnqx1Dl9MDzQ6H6o7BiInz/yEXPuawDddj5ccJhe6jg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=blackwall.org header.i=@blackwall.org header.a=rsa-sha256 header.s=google header.b=Y7d+PtKP;
dmarc=none header.from=blackwall.org;
spf=none smtp.mailfrom=blackwall.org;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 6D137606A32C;
Wed, 25 Nov 2026 07:14:24 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=blackwall.org header.i=@blackwall.org header.a=rsa-sha256 header.s=google header.b=Y7d+PtKP
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.42
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1795590863;
b=Xn0Jj3o4sRWQ30n8m6S5pXiiFr4f+FZR1db6k1ty87rKSPGbhqDTl1ZEC0QzE4/v1cL2
8BHK7R7giRkoLQBLmkNe9ShALsflmTuSLT64WQjBzzqDvv0vFQLth/oL/dEUU6H0oI29O
dMCy4SiQsVDI9Hq9U7aEw7Nqg+3PuhQ8Ra2K8PNIRKBTssCvNRtd7Hrb8PKkzXRmgMaeV
vkwJrHmt5TvSR4LT8XQK0qi3bWkHxYnX68f0FTDfj2BdI7Q0SqxBvl6LxnT5NVoccWJGC
c1PSyabLUM4wxk/cMuHzyG4C5cUybFJRBXw5yPaqWLRjvGbLom1Rtau3secayGUUwUA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795590863;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
Message-ID:Date:MIME-Version:User-Agent:Subject:Content-Language:To:
Cc:References:From:In-Reply-To:Content-Type:
Content-Transfer-Encoding;
bh=OS4S/3wgJzlNANveRHhJ0JCqQT7lj4OoQJmmJFDLZnQ=;
b=aK4kU8v5jaMydSiPvYw1Jii+CMvG5DDxjGG8AFI+zN40E4MXGWl476Ghs7pEJfzR4YWL
u1jfxU/MiPHvt7G47fXP+dPulndFi0NHXRkeq1KBW8ZTV5JIvkFzTIiglkRE0r2HHSmDm
2nScbdWfQ0vkfhiV2xW4FXqC9M/an23PhlIY0a9ofwOTNCQlidOoRj1D3GIGb5vtZrsIZ
zrtyAtr8TjUzsGXcq9BPIxaIBgFdmIq1KbeIMRnD2EMy8wF3zRCltyEbM2WdqruF4/QHU
4G4GUTmxwJ3sKNAL+spkpq6U2al4uv3Eghsn0OIXLtqctSjl36Be6bj1rtiSKJdkkjA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=none header.from=blackwall.org;
spf=none smtp.mailfrom=blackwall.org;
dkim=pass header.d=blackwall.org header.i=@blackwall.org header.a=rsa-sha256 header.s=google header.b=Y7d+PtKP;
arc=none smtp.remote-ip=209.85.128.42
X-Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D0A6606A68B
for <netdev@vger.kernel.org>; Wed, 25 Nov 2026 07:14:21 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2D0A6606A68B
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=blackwall.org
X-Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=blackwall.org
X-Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-4bb77a462c6so46883855e9.1
for <netdev@vger.kernel.org>; Tue, 24 Nov 2026 23:14:21 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=blackwall.org; s=google; t=1795590860; x=1796195660; darn=vger.kernel.org;
h=content-transfer-encoding:content-type:in-reply-to:from:references
:cc:to:content-language:subject:user-agent:mime-version:date
:message-id:from:to:cc:subject:date:message-id:reply-to:content-type;
bh=OS4S/3wgJzlNANveRHhJ0JCqQT7lj4OoQJmmJFDLZnQ=;
b=Y7d+PtKPrZc9qrL8ruw1v2fnEiDIJp/Oiw2UpSegR2quLKxNQMSfHY8uFKTccIL/4R
LryGVJ39a7dQhuuNh96TtjzmrNy6WXtuaXlWmHSDUtsvgdqUe/iV0pQxxrUKTcdi6d/G
JzgjhkCIGo991kVo+5OuxAOat0SDzClE4Q7lxRlHMmYqBEdV4IJioU1kPuJyz6zX0Wjh
wkt2/sPUo2ko3roosjYwPxD7nOOlOm+xiYO/8xs5reM3rtyZrIj2XhlrBVNrD266dGbM
ycDAljyKKsdUTSXsstGvHR6kbQTTMw67gMFKXtXTLQfS6ny3OhYLy/FzBbUdHy0Yv2/+
Upow==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1795590860; x=1796195660;
h=content-transfer-encoding:content-type:in-reply-to:from:references
:cc:to:content-language:subject:user-agent:mime-version:date
:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=OS4S/3wgJzlNANveRHhJ0JCqQT7lj4OoQJmmJFDLZnQ=;
b=nWwSiuHrvjguw8Tl8IajFOQPR0HNWckjve4N5KPwn7tZewYQKTpmXdqdtkc/l5DQI4
/o9seS+e0taQUcchT0SZyDVA2EjYsvJFTxFmQFDmJL6vpXsnkbxcYLLD3pxJzAFt4ouo
4adIodFXbOt0ewBc3mQFc8V9jo4ODbv27+2hwjJ8kBhFfwJnSBt0XirmWDWEtycCrj2N
nGKfHTZEpy+AsIyN+s1PldyjL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4fbe with SMTP id 5b1f17b1804b1-4bb88805c26mr301676605e9.8.1795590859967;
Tue, 24 Nov 2026 23:14:19 -0800 (PST)
X-Received: from [192.168.0.161] (78-154-14-127.ip.btc-net.bg. [78.154.14.127])
by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb853a9846sm582103175e9.11.2026.11.24.23.14.18
(version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
Tue, 24 Nov 2026 23:14:19 -0800 (PST)
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-User-Agent: Mozilla Thunderbird
X-Cc: Lin Jiapeng <jiapenglin@tencent.com>,
TencentOS Corvus AI <corvus@tencent.com>
X-In-Reply-To: <20261124024319.52145-1-ljp1205831794@gmail.com>