From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795957320; b=dZuneDYLfUdzu3yzXBJVcxDo0SopFR75UHc8cjmytYTv5Z5MctbW3JII1PD60Y9N1K/n i6c12NR2W5ydxltMzgZOCUrKogPfQHSaU2Lj1i0uxVOdxj2A84GZ8cpqCvBsqNzmfv8X3 ARt7bmnXjKhIY9+4qbviprmX2ZwJ0y9GtO8SCU/cUL8nepbD9WdKeWpqDMaoASOuzEbRG oyOSTyP3eEeD1TPSW98yAoOyqxvPAgYznqFdPkD9Vrk7mbhC4hlW+9yCtSSZmffrIuEab WVpqM9rdamnHhZT1N8P2mOHmkCntSE87JxvoIU0EsmoOqUztT2/I8d2bfcAEWbjFQzw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795957320; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=I7N1H8nRIUPfsq5YllUOQogPmWxLZ9/ie/GNDxTEQv0=; b=mQO1JDrdawuxNqS190WMGQ5dIaHr/UGfCxFW7LXR/mbZFZt9NdRCesd1MXZrr1uJ8EiE iDs9AOO9Kgrx6ml8qJBujRDoqWb3FkN7L8XvUJ23FCDG6Jt0ccej98b0tZgyxK4tjeHkS UzxWiQVA69S37PMMlr4J+OJ5xOEMrTnWnEb/OqwogWb2LgEELB1ZxRZm+0Wm6JdG3rnVs 8P5mO6L7aFggKIUFd/MirfKTLZFk4DfR/1JMnfI4PEIUPH17GGxKKGAySRFr9qb0gKbHj OSnECr3fgv1uwYHJn26E6Ril6cEDqWM6LqL5duYQuzzXDV2EdEn/oA/5ZuuaL55St/Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Zea0cnYi; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 12362606A323; Sun, 29 Nov 2026 13:01:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Zea0cnYi Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD08B1F00896; Sun, 29 Nov 2026 13:01:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795957319; bh=I7N1H8nRIUPfsq5YllUOQogPmWxLZ9/ie/GNDxTEQv0=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=Zea0cnYi+0Ov3v4++4YhY5SL13loU5lKbYNL9VRK7gt2EoBlx6yMLuVXdaKYqP7oN qJHKyjSqwg4CGq7H8FeW1pf59JP/SFfFWaiRMprHWpaQwk+/HQ8jZrl+kIAtz+dRJg NbjxJ3YiL7QYUXYjDCRPkcODhONlFwYdw30tMv+atG/8Y+/XK8eBSEFKDHayQSJyWN jDWgPVULyF4Bwqvv2oRkDqH1PIHhvwE9h3W23VkrnUw+vwJrSu33mv04Bwvqppo7bf wQdsXGYVTAp5Ufe5XFDZ/Omwe83/WTbXCLyS/VnTWRIn6PKjHCC1iSTcPqAq+tmJTm K8J3+2NpAariA== Subject: Re: [PATCH net-next] bonding: undo enslave state when XDP setup fails From: netdev-bot+sashiko@kernel.org To: hangbin.liu@linux.dev Cc: jv@jvosburgh.net, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com, sdf@fomichev.me, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Date: Sun, 29 Nov 2026 13:01:58 +0000 Message-ID: <179595731839.3146.9352124638865415714@kernel.org> In-Reply-To: <20261125-bond_xdp_rollback-v1-1-35dddaa337ba@kylinos.cn> References: <20261125-bond_xdp_rollback-v1-1-35dddaa337ba@kylinos.cn> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider. Critical: 0 · High: 1 (1) · Medium: 0 · Low: 2 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [High] The second bond_slave_ns_maddrs_del() that the patch adds at err_close in bond_enslave() (drivers/net/bonding/bond_main.c:2402)… - [Low] The patch fixes leaks visible to users after a failed bond_enslave(): stale promiscuity/allmulti counts and synced uc/mc… - [Low] The commit author is 'Hangbin Liu ', but the only Signed-off-by is 'Hangbin Liu '. Pre-existing issues: - [High] This problem wasn't introduced by this patch, but the bond_enslave() error labels the patch extends still do not undo… -- bonding: undo enslave state when XDP setup fails This patch adds undo steps at err_dec_slave_cnt in bond_enslave() for the ns maddrs, promiscuity, allmulti and synced addresses when one of the XDP checks fails. It also adds a second bond_slave_ns_maddrs_del() at err_close, meant for the case where the new slave was selected active and is then demoted on the error path. > Signed-off-by: Hangbin Liu [Severity: Low] This isn't a bug, but the author address is hangbin.liu@linux.dev and the only Signed-off-by uses liuhangbin@kylinos.cn. checkpatch reports a From:/Signed-off-by: email address mismatch. Could the two addresses be made to match? [Severity: Low] Should this have Fixes: tags? The promisc/allmulti/address leak on the XDP failure paths appears to come from 9e2ee5c7e7c3 ("net, bonding: Add XDP support to the bonding driver"). The ns maddr leak appears to come from 8eb36164d1a6 ("bonding: add ns target multicast address to slave device"). The earlier related fix a978095699641d ("bonding: fix slave_cnt leak on XDP enslave failure") carries Fixes: 9e2ee5c7e7c3. > diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c > index 776afdb9df43e..a3daf005b444d 100644 > --- a/drivers/net/bonding/bond_main.c > +++ b/drivers/net/bonding/bond_main.c > @@ -2364,7 +2364,16 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev, > > /* Undo stages on error */ > err_dec_slave_cnt: > + bond_slave_ns_maddrs_del(bond, new_slave); > WRITE_ONCE(bond->slave_cnt, bond->slave_cnt - 1); > + if (!bond_uses_primary(bond)) { > + if (bond_dev->flags & IFF_PROMISC) > + dev_set_promiscuity(slave_dev, -1); > + if (bond_dev->flags & IFF_ALLMULTI) > + dev_set_allmulti(slave_dev, -1); > + if (bond_dev->flags & IFF_UP) > + bond_hw_addr_flush(bond_dev, slave_dev); > + } [Severity: High] This is a pre-existing issue and this patch did not introduce it. The error labels being extended here still skip several steps that __bond_release_one() performs. In 802.3ad mode, bond_enslave() calls bond_3ad_bind_slave(new_slave). No error label calls bond_3ad_unbind_slave(). Only __bond_release_one() does: drivers/net/bonding/bond_main.c:__bond_release_one() { ... if (BOND_MODE(bond) == BOND_MODE_8023AD) bond_3ad_unbind_slave(slave); ... } bond_3ad_state_machine_handler() runs from ad_work under mode_lock and rcu_read_lock, not RTNL. That means it can run after the slave is linked and before the XDP or sysfs failure. The newly bound port is not AD_PORT_SELECTED, so ad_port_selection_logic() picks it up. With no matching LAG it takes the first free aggregator, which can belong to another existing slave: drivers/net/bonding/bond_3ad.c:ad_port_selection_logic() { ... free_aggregator->lag_ports = port; free_aggregator->num_of_ports++; rcu_assign_pointer(port->aggregator, free_aggregator); ... } The error path then unlinks the slave, and bond_free_slave() calls kfree(SLAVE_AD_INFO(slave)). Can the other slave's aggregator->lag_ports then point to freed memory? Later ticks would read it through __agg_active_ports() and ad_agg_selection_logic(), and write through __set_agg_ports_ready(). __bond_xdp_check() allows 802.3ad with XDP, so the XDP failure labels can reach this. The bond_sysfs_slave_add() failure path can reach it too. Separately, netdev_compute_master_upper_features() and bond_set_carrier() ran with the failing slave counted: WRITE_ONCE(bond->slave_cnt, bond->slave_cnt + 1); netdev_compute_master_upper_features(bond->dev, true); bond_set_carrier(bond); They do not run again after slave_cnt is decremented and the slave is unlinked. Could the bond keep carrier on, or keep stale features, with zero slaves? One example is the first slave of a bond that already has an XDP program and that fails the XDP checks. Also, in TLB/ALB modes, the sysfs failure path never undoes bond_alb_init_slave() with bond_alb_deinit_slave(). > > err_sysfs_del: > bond_sysfs_slave_del(new_slave); > @@ -2390,6 +2399,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev, > slave_disable_netpoll(new_slave); > > err_close: > + bond_slave_ns_maddrs_del(bond, new_slave); [Severity: High] Is there a matching add for this second bond_slave_ns_maddrs_del() on any path? The commit message says: If the new slave was selected active before the failure, err_detach demotes it via bond_change_active_slave(NULL) and bond_hw_addr_swap() re-adds them after the first removal In bond_change_active_slave(), the swap runs before the old active slave is flagged inactive: drivers/net/bonding/bond_main.c:bond_change_active_slave() { ... if (bond_uses_primary(bond)) bond_hw_addr_swap(bond, new_active, old_active); ... if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP) { if (old_active) bond_set_slave_inactive_flags(old_active, BOND_SLAVE_NOTIFY_NOW); ... } So when bond_hw_addr_swap() calls bond_slave_ns_maddrs_add(bond, old_active), the slave is still active and the gate rejects it: drivers/net/bonding/bond_options.c:slave_can_set_ns_maddr() { return BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP && !bond_is_active_slave(slave) && slave->dev->flags & IFF_MULTICAST; } The re-add therefore does nothing. By the time err_close runs, though, the slave is flagged backup. This del then passes the gate and calls dev_mc_del() for every NS target MAC. In active-backup mode with arp_validate and ns_ip6_target set, each of these cases seems to end at net -1: - The new slave was selected active. The add in bond_enslave() is +1. The del of new_active in bond_hw_addr_swap() is -1. The err_dec_slave_cnt del is skipped (slave active). The err_detach re-add is skipped (still active). The err_close del is -1. This case was balanced before the patch. - The new slave stayed backup. The add is +1, the err_dec_slave_cnt del is -1 and the err_close del is -1. - Older failure paths reach err_close after bond_set_slave_inactive_flags() in the BOND_MODE_ACTIVEBACKUP case. These are the netpoll enable, netdev_rx_handler_register(), bond_master_upper_dev_link() and bond_sysfs_slave_add() failures. They now run a del even though bond_slave_ns_maddrs_add() never ran. The commit message also says: on every other path it is a harmless no-op, since deleting an address that is not on the mc list does nothing. dev_mc_del() ends up in __hw_addr_del_entry(), which decrements ha->refcount without checking who owns the reference, and frees the entry when it reaches zero. Another owner may hold the solicited-node MAC 33:33:ff:xx:xx:xx on the slave, for example a packet socket with PACKET_MR_MULTICAST, or a VLAN or macvlan upper. Can this del drop that owner's reference and remove the hardware filter? That owner's later delete would then fail with -ENOENT. The err_dec_slave_cnt del already undoes the add on the XDP failure paths. Could the err_close call be dropped? Related, and not introduced by this patch: because of the same ordering in bond_change_active_slave(), a slave demoted on an ordinary failover also becomes a backup without NS maddrs. > if (!netif_is_bond_master(slave_dev)) > slave_dev->priv_flags &= ~IFF_BONDING; > dev_close(slave_dev); -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125-bond_xdp_rollback-v1-1-35dddaa337ba%40kylinos.cn