From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796286605; b=YKInBXFy4XXStk92NpDB4xr+9i/UrGDWv3dErYDnn84koPNF/emcDhgONUbqTIyfDs6u fXjWIYRrp5QrOg0vHQCTnOsm70osvP7y7JxlzpFihqbJZX3MfAfsy6D9bXoyVtonP9E3F OLf7PuN3H4UZ/F4mqoG9A9tVttb6Q4CKAnUAFKCXtHF7aaR9BISDIXiUomG2gTQgrnFQH Hi6ntZLlQpz1wNf05sEfcFC79pKB/YMhb1Kl++ox54QNb9hesHAPAaarVzjm1yxNCGyXG 25cZD07Ffl/+y6uaraD3Rpsw9mwOqn3GPFCY4f7dSmqqhiLAb6gup69z7U4cbfxsECQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796286605; 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:To:Cc:References:From: In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=vGL+pDMFltXINor2s7gPvNaTc86I6IHQHcTWvavC0vE=; b=ifnCtOBR8wZ94pwwBXm3krbYvFNuZStmUD58tJB3bPXKwGiwGNXxQ8f3m2RoZ9dILEqR u7wJhxGSjAHLFEWPAY5N22yk+jTSAfBhx44mSyWgvuAGs8K3FxfcYl81+4Pzj/wezk5IH jgC1qYPlQyKXEGN5a0HvcOj8XqfPgrTkrY9KM8kpLAMRpK4yvJ9rDnYU2fWscMqvwXIlF f60+gLYPqG8qTELRfwgGOCq81p/ekiV4reCudMYH5sIRbHbJ3rkefKLnnGsIrKGOjPyBC csLwMijwbrun9CAUB0Pz+DJeeAh6KCJMfszpSV7wEEAeYyzxdSWZ2tlKhVBPkr+GwZg== 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=PdVB065K; arc=none smtp.remote-ip=209.85.216.52 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (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 64E36606A32F for ; Thu, 3 Dec 2026 08:30:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 64E36606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com 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=PdVB065K Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-3ae691283ecso431469a91.0 for ; Thu, 03 Dec 2026 00:30:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796286605; x=1796891405; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from:references :cc:to:subject:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to:content-type; bh=vGL+pDMFltXINor2s7gPvNaTc86I6IHQHcTWvavC0vE=; b=PdVB065Kwl1wdEQ1j9KropY+VtbyfnyBH4I8pMsNQn39/8iOgCVxO09ixD8DiNf9V5 NMrwGLnQt5C5h4SZjokjQNAvI39B+p8CRaFEf4e6dn4FsN+5hSd+UfwDFjepUBaj1VuD cpO3j44bs20Z+RO2/tt1fSYAN4WUerT9RNSutadaKaXWUpLDd4csHEcnSXQ9psu7y6/J c9YrLtGvqXiWsvjlBHlZ75KBrDki+L7zTYlpr3NcwDx2iahX7Pti6jkOcY9NouPIXq2O s+C8H1CuDGaILI+XneeNEEfVihj7KYg1qcJqIt7HB8CJmO9LsI6FgIfBRkU61qZ0sAbB PV4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796286605; x=1796891405; h=content-transfer-encoding:content-type:in-reply-to:from:references :cc:to: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=vGL+pDMFltXINor2s7gPvNaTc86I6IHQHcTWvavC0vE=; b=FcBlJUKZzJkEO2oUIBpDjwLhwMoWQedhzUp8PvBTJavgtwlViIR/FqU0bk6v0WLsIO Mht5diJg3vZaRhPgTCeSp/TNvxd02JSHe5i63t5VAuhqwprcn0X+Lz647AKdEfpmPRjj AZeVKPuXBGjU85oxmlf7BW3TO7gtUie7ckwZMiJnb6jNmS7hTM179vhNE+sG6IMVv9DN tf7D7V4E/5x904M/+bSLHFLEA3RD3DuMI4DEPOe8upSurOPgu10+Yzq7mbVi41b9qf2Z nqhSoRBBdGX/tN1Xf4RqgVBicd+pEjDAM701b8hjNbexrKEggKWxHCJNpAPABMls3AzQ PX/A== X-Forwarded-Encrypted: i=1; AL+hErEYxWv5quZi542UxdNLPNrJUDCYEu8uVetnhiahjGR57nVKeOtwKNfGB1KpFGWg1wTg8NArrtI=@vger.kernel.org X-Gm-Message-State: APuU4Z+C8iF47xlJi1e/OnYDVSzhZlspohRrjjxfj9Om8Inm3KjBr8q8 sGUf/KwWBgqZWQBSM4wUO2L6wE2CGh0ATiQqW6wUarkAgJA7+f/0PMCa X-Gm-Gg: AZFdTZck5hGvd13CtB1gbPqyc2TBwbLrJMX4/Z4WYUeSvOhLhMgVmavuSU/px2LApqp AwECmSbrKRR/wsS5+FoOhbkc2UsMSZ16/a814oNG3ZfzxQ80CCIzeFNU6fh09NlS4hHRbiGkYVJ 8aKAeUIGR0yqhr+o0zbmtQ2pqlQ/NJxl9Q1VURodzOuPoT4Naa0dwt3njnam8UWIDue0C4zATcS HsgzRZkBlx2eZ3C2uGnFhGS2xofQohGCiyigjPTGyQy3s2yRPR4qBAW2MUAJ8eYbV8Z1IYwlDpS 2Q1GJ3DQ+cKxRIS8UtIzOJmoDbxSH8JXPFWGAtcqKuqhWBmQJjG5fSxzLZp4uL4IvQXmxqVqAM3 QZUEqmHMuAurWJKZZ69u7fbLQQCX0i/0iU0y6rE8x2zg/RqnSlD4eK+BIFC9IC2583UdcvMH5eK 7HxtHOqERyYP5q7D9meUhq4VauBc6PjeoeCHkogSbB2Om/6rD8oRfkAS99pmRldqv3ZzsmfJCL5 HpoZzKedTGuaRJpMPvp7vYzGjF2hJyjLnmSJ+pqCxF0BeQ47ritT78NJLG9q3sw0n6St898z0PQ M82d6GVGB+31hDESDkuQ6kL9LFoOnVkoa1leiEkH2Jb+3WrY1CYw6YCy5de2HeKlFdnk3/YR2O2 8bKE= X-Received: by 2002:a17:90b:56ce:b0:3b0:9409:6969 with SMTP id 98e67ed59e1d1-3b5cb697781mr850450a91.19.1796286604509; Thu, 03 Dec 2026 00:30:04 -0800 (PST) Received: from [192.168.255.10] ([43.132.141.24]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b44b7c6513sm33265599a91.4.2026.12.03.00.29.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Dec 2026 00:30:03 -0800 (PST) Message-ID: <4a1c81c9-fb1f-43f7-9700-b72f383f6e82@gmail.com> Date: Thu, 3 Dec 2026 16:29:47 +0800 X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net v4] bonding: unbind 802.3ad slaves on enslave failure To: Hangbin Liu Cc: jv@jvosburgh.net, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, sfeldma@cumulusnetworks.com, netdev@vger.kernel.org, Lin Jiapeng , TencentOS Corvus AI References: <20261202111120.99494-1-ljp1205831794@gmail.com> From: Lin Jiapeng In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2026-12-03 2:45 p.m., Hangbin Liu wrote: > Hi Jiapeng, > On Wed, Dec 02, 2026 at 07:10:42PM +0800, Lin Jiapeng wrote: >> From: Lin Jiapeng >> >> 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 > > This is an injected enslave failure, and I see you are using a kretprobe > for testing, which means it's very hard to reproduce and not observed in > real-world use. Perhaps we should target this patch to net-next? > >> 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 >> Signed-off-by: Lin Jiapeng >> --- >> 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); > > Here the ACTIVEBACKUP and 8023AD both only have the flag setting. Maybe just > > case BOND_MODE_ACTIVEBACKUP: > case BOND_MODE_8023AD: > 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); >> + } > > Do we need to update slave array here? The slave_cnt hasn't changed yet, no? > > Thanks > Hangbin Thanks for your review. You are right about the trigger. In a realistic unprivileged setup, reaching a suitable enslave failure seems to require memory pressure/OOM or another bug, such as the issue fixed by b6743653d134. I agree that net-next is a better target. I will also merge the ACTIVEBACKUP and 8023AD cases as you suggested. Regarding the slave array, bond_3ad_unbind_slave() can invoke ad_agg_selection_logic() when the removed port affects the active aggregator, potentially selecting a different active aggregator even though slave_cnt remains unchanged. Rebuilding the array afterwards therefore seems to be a safer, conservative way to keep it consistent with the LACP state, so I would prefer to keep the update. Regards, Jiapeng pw-bot: cr