Article View: linux.kernel.netdev
Article #25750[PATCH net v4] bonding: unbind 802.3ad slaves on enslave failure
From: Lin Jiapeng
Date: Wed, 02 Dec 2026 11:10
Date: Wed, 02 Dec 2026 11:10
144 lines
16338 bytes
16338 bytes
From: Lin Jiapeng <jiapenglin@tencent.com>
The 802.3ad enslave path initializes each slave's LACP port while
assembling the bond. TencentOS Corvus AI found that an injected enslave
failure can leave the port attached after its slave is freed, causing a
KASAN use-after-free in ad_agg_selection_logic().
The bind precedes upper-device publication. During NETDEV_CHANGEUPPER or
a later fallible step such as bond_sysfs_slave_add(), the periodic state
machine can link the port into a LAG. The error unwind then unlinks the
slave and frees ad_slave_info without unbinding the port, so later LAG
processing dereferences freed memory. 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
Call Trace:
ad_agg_selection_logic+0x1a0d/0x1fa0
bond_3ad_state_machine_handler+0x116d/0x5250
Adding only a late unbind is insufficient because a failed upper-link
notification has already unlisted the slave, leaving an unlisted-but-bound
interval before that unbind runs.
Bind the port only after upper-link success. On later failures, drain the
RX handler, unbind while the slave is still listed, unlink it, re-evaluate
the carrier, and rebuild the slave array after aggregator changes.
Upper-link failures never bind the port, so they neither race with an
unlisted bound port nor emit a spurious LACPDU. Earlier unpublished
failures keep their previous behaviour.
With CONFIG_BONDING, CONFIG_VETH, CONFIG_USER_NS and CONFIG_NET_NS enabled,
an unprivileged user enters user and network namespaces, creates an 802.3ad
bond and a veth pair, and attempts to enslave the peer. A root-loaded,
test-only kretprobe makes bond_sysfs_slave_add() return -ENOMEM. Repeating
the attempt lets the 802.3ad worker select the port before rollback; the
unfixed kernel reports the above KASAN use-after-free, while the fixed
kernel returns -ENOMEM without it and a later normal enslave/release
succeeds.
Fixes: 07699f9a7c8d ("bonding: add sysfs /slave dir for bond slave devices.")
Reported-by: TencentOS Corvus AI <corvus@tencent.com>
Signed-off-by: Lin Jiapeng <jiapenglin@tencent.com>
---
v3 -> v4:
- Rebase onto current net/main. No functional change.
- Revise the commit message to document the configuration and steps needed
to reproduce the bug.
v3: https://lore.kernel.org/netdev/20261126082257.46411-1-ljp1205831794@gmail.com/
v2: https://lore.kernel.org/netdev/20261124024319.52145-1-ljp1205831794@gmail.com/
v1: https://lore.kernel.org/netdev/20261113130454.63032-1-ljp1205831794@gmail.com/
drivers/net/bonding/bond_main.c | 46 +++++++++++++++++++++------------
1 file changed, 29 insertions(+), 17 deletions(-)
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 042d7c75548f..950c04af762a 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1892,6 +1892,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_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 ||
@@ -2185,19 +2186,6 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
* aggregator
*/
bond_set_slave_inactive_flags(new_slave, BOND_SLAVE_NOTIFY_NOW);
- /* if this is the first slave */
- if (!prev_slave) {
- SLAVE_AD_INFO(new_slave)->id = 1;
- /* Initialize AD with the number of times that the AD timer is called in 1 second
- * can be called only after the mac address of the bond is set
- */
- bond_3ad_initialize(bond);
- } else {
- SLAVE_AD_INFO(new_slave)->id =
- SLAVE_AD_INFO(prev_slave)->id + 1;
- }
-
- bond_3ad_bind_slave(new_slave);
break;
case BOND_MODE_TLB:
case BOND_MODE_ALB:
@@ -2246,13 +2234,30 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
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);
+ if (BOND_MODE(bond) == BOND_MODE_8023AD) {
+ if (!prev_slave) {
+ SLAVE_AD_INFO(new_slave)->id = 1;
+ /* Initialize AD with the number of times that the AD
+ * timer is called in 1 second; can be called only after
+ * the mac address of the bond is set
+ */
+ bond_3ad_initialize(bond);
+ } else {
+ SLAVE_AD_INFO(new_slave)->id =
+ SLAVE_AD_INFO(prev_slave)->id + 1;
+ }
+
+ bond_3ad_bind_slave(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 +2362,18 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
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 (upper_linked) {
+ if (BOND_MODE(bond) == BOND_MODE_8023AD)
+ bond_3ad_unbind_slave(new_slave);
+ bond_upper_dev_unlink(bond, new_slave);
+ if (BOND_MODE(bond) == BOND_MODE_8023AD) {
+ bond_set_carrier(bond);
+ if (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: 0d39bf81267861742b80d5f1c52e8a63e9ca0ca1
--
2.55.0
Technical Details
Message-ID:
<20261202111120.99494-1-ljp1205831794@gmail.com>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375737-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375737-linux-kernel-netdev=dewy.ru
From: ljp1205831794@gmail.com (Lin Jiapeng)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v4] bonding: unbind 802.3ad slaves on enslave failure
Date: Wed, 2 Dec 2026 19:10:42 +0800
Organization: Usenet Network
Message-ID: <20261202111120.99494-1-ljp1205831794@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="1957305"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:YBuruNki3U7AWhRmUvl9Ga/KzzU= sha256:tZtdwVUfr5gmQjfwqs3DF7BTwoX5r4YfQ6cKVja/6sI=
sha1:n80acbXhS2mMi+CybO4Quh7R03A= sha256:uf9RtZZMx5Dx4x43fdsPMeeUKaqhU91fDy7NzNPN40w=
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 A54CC1175C3; Wed, 2 Dec 2026 14:12:04 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.149
X-Spam-Status: No, score=-3.149 tagged_above=-9999 required=6.31
tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001,
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]
autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
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 od8ktgt9S0p4;
Wed, 2 Dec 2026 14:11:56 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-375737-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id 7BAD3117590; Wed, 2 Dec 2026 14:11:48 +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 694D22667C; Wed, 2 Dec 2026 11:11:47 +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=1796209905;
b=CKpZ6mptxPs5KZool+yl0GEbkqLwhGmSy/bBmraMZf2PqRkEh7ZGzPChyW6G4mq5dIyf
1e8H+dRrRkTLHVfS4jebMam8m1J6n0AOhSt6PVaNnvkKkvQtSwa8diHKEOZZ/rR3lcuK5
4m1GwkqPwf5ATKS9ol+ldfcVxeO2xQxsPm2ogODtQr1Oey91BewTH2REYQFgaQFhON1aX
ouUMraWXlkrEzbRkF45OZJnCvArs4y6TIPCLILVb9hfHXBSG0wX98c1nM9RlJPvEUWasb
TNg/rODkj0u9+kLbg4b79XPGw/kjEfpF7U9/DBiP5QSiotvaBxRCPbTBjFsJBCswo/Q==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796209905;
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:From:To:Cc:Subject:Date:Message-ID:
X-Mailer:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version:
Content-Transfer-Encoding;
bh=ieKeIB75i6jLXxDNbxCGdiYwxO1Jah9ddLWViGjYfMQ=;
b=niaPLQpZY/7EHI5hCbuI9EaWKfvcWq1/FmUJ0UM5GdzCyS1q3+brDWY8vT6An3J6YARi
NLympgi/2eYLr2NuhKFAb+GKSRQ+UfPCbEsN2oGNAcM8yEg7mjKF4frzjGUBO+hBkz/Wg
k5gpc5bcEHDyAHaFpsVSAeCoIrzhjXhGo70Z6iLay1CgOu+2Iz/+/6ge8g9PEOcgUUtCr
n1bTjY4qmh+OJF+MQNzxmuul65v14UuNIGngE8WhcuUU63O7L2kLS+dqCHp/QilBBeSjB
I2Lfgnor3VxU+A5y7dJYROwHYe1kUhHAc3XzzZO8s8jd67lGM7ffD6aWq4xzGBJsgOQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=cNRDtwh5;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
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 02BD9606A32C;
Wed, 2 Dec 2026 11:11:45 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=cNRDtwh5
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.44
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1796209904;
b=ooW9ySL6ZHsh1yHQvOOwB6MRQ/oXxWi6vaCAUy+w+/D/ePB/wsCa5GtNp6Jmag/f67Tk
uwRsqMsyoAjL7l1KZFgeW5suAuXDyQoaXp0Nw4MZN7p/wP+AHeg6Xmd1MPu6qkvEr2eZZ
dWoAQy3sfZikXRKZcCMhYRx8AQ6R2Usbv1kzlDFNXMMJHCKheos5/yMN6HiKvaQolneWt
3Sgil+3w1k16aKcf65PFJ5B51AqJd6SD6zY/hgJBLjWEmqGBaSP57/inUVe0wLSCRlTas
W56HK2DR/12NB1ZoK+OqNDh1Rqs6nbpT0SMoo/r5z/oQftbPbuIvqu6RRQNtiDBbK2g==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796209904;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version:
Content-Transfer-Encoding;
bh=ieKeIB75i6jLXxDNbxCGdiYwxO1Jah9ddLWViGjYfMQ=;
b=Ndcw+Mj5Be+scPABwxgja0io8xPUmJ8rGpNS+cXcWMCr2wuBDCjWPwsbjReh8C8hM6aY
EwMyo3PyjFb/uoovd4VX3maJzb3HXP4rHKmItxRL7Syo6ZFYsNVGxsu2ptzoEMWJMT+7q
E2fhYdM7mT/Ght6QXYzHUUoN/BQPC/lUyED6343Vquc+YU4mJmU8ftt3JXSTvwpceVYd4
ceBmo22bqIJXkBqu2Xqq9/n0g/Dy9BB0p9/selQC2/vqTacpr7vwHkU2b7wSj9WJ2aMXC
wxhyjEhBI2jKocukw4RMccWZUJcmv+5foFxRon5mUYTUnl363TS+ePpLw2F5efJDcsg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=cNRDtwh5;
arc=none smtp.remote-ip=209.85.216.44
X-Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44])
(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 B6C73606A31A
for <netdev@vger.kernel.org>; Wed, 2 Dec 2026 11:11:43 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B6C73606A31A
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-3b413997581so8807412a91.2
for <netdev@vger.kernel.org>; Wed, 02 Dec 2026 03:11:43 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1796209903; x=1796814703; darn=vger.kernel.org;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:from:to:cc:subject:date:message-id:reply-to:content-type;
bh=ieKeIB75i6jLXxDNbxCGdiYwxO1Jah9ddLWViGjYfMQ=;
b=cNRDtwh5wSopy7/UyV83PDlEcQQzRaAwFmXai5E8esxK3kznIsIGo/Qg3k6YR/zcHW
gvV8M8qFeLhVHSCegDaejIVJgLDmta7gtHoNbPT50MNFfbo144BP/Y1o7bI+BNAQYdu7
LLN0ZVdlx07IGmjWaEyJVvYPoAu0Zig1vZE9NuK0XklCP/nWzfFTcpXAVZcegt4ebLRX
ZTMmzovb7h1WIM4LV67g+RJC0sYOHvAZnrl8NyqNctsP6pLRLZ2T/3BkQIwMF4KpNjAe
jpIuP1IBIr47JAjX6hvDRHFSChT1amT6OkhNyh8lfd7IzASxACsc+JiSCFZmchEkAHyE
SBUQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1796209903; x=1796814703;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=ieKeIB75i6jLXxDNbxCGdiYwxO1Jah9ddLWViGjYfMQ=;
b=cFe+hriy2jialYggKaDMpywXUga72oCAKxVZYtCuE8FuwlIayEj3Lawkyn17TE6f30
Raw0yBdHVm0Ex2+IBdDZ+hC6ySzUKlUpRlQE/YvkXMlHZwOiwjnIneBuGAMqGrTIW3V2
9iOUHfNbjELx+u1nDNNQR9BAc66Nbq8W+wSa/uenmuQj4wgP2KqZAn1xd6roKdpY0Wnz
w/LZkYCxHn8l5Z9S1stZwcIqyLrrcCqNyVTE4+ipW6O7/z2mnVe8a0bJ0xT7Fxp5EdWb
msrvnsF8dm7XYECpO9Lrn7R5u78gV/SlVPYSijy5nA+2f6p9GiwyAx0/xKcI5JFEn2oW
e0Mg==
X-Forwarded-Encrypted: i=1; AL+hErET497BkuAkDrq3ez0hO/RsyBKXJnWe0CHK4EEqQ0FmAv3XVlSeuIjnwOPsaiDTNOyF/8ByhC4=@vger.kernel.org
X-Gm-Message-State: APuU4Z+rPNJX/a5z1LZ1VcESRQG0OI6Q1qfzI3qbho5Xj6FgCd7Kmvba
Ntjg3ImPNx2qyaY8SnEQcAiKU9YBM72GxA7d7U7guE7r1zaxwtvoBtMS
X-Gm-Gg: AZFdTZem9lXooPCZ1dJVB/lDAXTX+UbuT6Xm7BUZDwXKOs3M4bXKFr9S0Oj8o6IEIr7
BQZzHTAD7AQxhhg+pCDbbE+FPIGvOeqXj2d2EqTvKAlVJ0sXgvMH1gzp4Qvh5geuhpOXnr7p61I
5nlf19xpbGF39bW4FeEYrGUB+7JgI3SbtZBhxiqYqYXDLGmjoQ+2Diow5LsMQwtonng5h/jM4gg
I4COTE+X3WowUFfW4NmZsRwmnpglremLV/l54gaH3/Jrh0D8Q40aoFqfPG9oL3VeA7V8N8UQ8wt
axK568YfVsf5/tRQ5CT5N7+3TeJY8y1X/oiUoxSVvzFMZnYziop3g58dINkrtEXQr5B/use5x+2
R+qWuPt2bW02EJCqo6z9JbuCox1/PlIwvdnrdiVQdoqwrsypobOctB27++ODfBeWFSqMfd8UKT/
fMqrgXwALnGLShhaHBS9Cb/q8sro1EI/GrYchSZtHF+Cwkt32766R+plnoRRQV5/q4xmxDUCmM/
QYD70Dn+eBeSHlAooRY9pP0rq/ngOfVAOTClQcX0BQjQT3u1kn5kPqC67vnRK4q4Gz79Myrs+E6
0ge66HJ1h/6dpIusoxWhbYhZMFiw1kjPKWXT1zdiHxkXHyGFUALIoOOQ1VmEF3dXVYnWDo32
X-Received: by 2002:a17:90b:2c87:b0:3b0:a37a:230a with SMTP id 98e67ed59e1d1-3b41c911819mr38036692a91.25.1796209902949;
Wed, 02 Dec 2026 03:11:42 -0800 (PST)
X-Received: from JIAPENGLIN-MC0.tencent.com ([43.132.141.24])
by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b44b6fe711sm28589288a91.1.2026.12.02.03.11.39
(version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);
Wed, 02 Dec 2026 03:11:41 -0800 (PST)
X-Cc: Lin Jiapeng <jiapenglin@tencent.com>,
TencentOS Corvus AI <corvus@tencent.com>
X-Mailer: git-send-email 2.55.0
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