From nobody Thu Dec 18 14:41:50 2025 Received: from mail.universe-factory.net (osgiliath.universe-factory.net [141.95.161.142]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB57E1A3AB8; Tue, 8 Apr 2025 16:30:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=141.95.161.142 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744129848; cv=none; b=gVsHrV0145MuyN/DH9OIqtFZdjAUAWLB63O1UvlAztgtk8Y7b44oEYgXn2F4ac+Za7+iGXIRg4WMbQA4QdACgXL9DLxu/o7TBSIhrHDHbNF6t+U5tW+8qnsu7P7yQi0IJ/KQomcjTQ6Oo9KJBBMRlSYjMrQAe5nMJoizLaXeq8k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744129848; c=relaxed/simple; bh=SWjrxx7mBYsKxQ85DT+EJ28yhni0UNOr9J1yNClrQQM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=FgCKjtb8J0m3+8ZaiR1H15dDZYkqnKNaUt2+QvOe1XhNJPDU0/jpc7vajJDahmtibmfctVlA2Pc2FsZtGh5QObP14ea+eWOhdHUM6UqGZCy+gv9QmJLSFO9/xDK7brGFQued8HV+QVBXuUB6lFwz2scuX2J3pw+Ts6KHnMPlick= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=universe-factory.net; spf=pass smtp.mailfrom=universe-factory.net; dkim=pass (2048-bit key) header.d=universe-factory.net header.i=@universe-factory.net header.b=lcIfPGas; arc=none smtp.client-ip=141.95.161.142 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=universe-factory.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=universe-factory.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=universe-factory.net header.i=@universe-factory.net header.b="lcIfPGas" From: Matthias Schiffer DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=universe-factory.net; s=dkim; t=1744129843; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=HZjY/++SdcazIcDBDIw/OPGFSAKBqU5udvYkVuC5+dg=; b=lcIfPGasBWgQC8ybApf13bCYOP2yEebhBPyToL5Ae7hFnS26CZz1gAornIr8UGdB0shYyO 3TgzJ6PQxBn1IkYFavFo3vMpEIiu24od2c4Cy3oOMJoaq/H5Zh8xihdzioJkBv8qqJvRkQ HxLuJwqMxbAqJl6D6L3KaNTVj+Fmum2R9MTmzbgB6qCbg6nTqNsTEgyFn+lbxRirHCU87n v3L3WvOmygfYdsCBLmdl3RW8CcnL2WCC61Aefq5lME8OrrzHKyAESRyHUH5/2AE0zTlNRj DnlKjKID/59GwvZmoKKXx7J96kgHjYX7QKxgpayVnXWsb4f4rU/cFC+G70XshQ== Authentication-Results: mail.universe-factory.net; auth=pass smtp.mailfrom=mschiffer@universe-factory.net To: Marek Lindner , Simon Wunderlich , Antonio Quartulli , Sven Eckelmann Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , b.a.t.m.a.n@lists.open-mesh.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Matthias Schiffer Subject: [PATCH net] batman-adv: fix duplicate MAC address check Date: Tue, 8 Apr 2025 18:30:16 +0200 Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: - Content-Type: text/plain; charset="utf-8" batadv_check_known_mac_addr() is both too lenient and too strict: - It is called from batadv_hardif_add_interface(), which means that it checked interfaces that are not used for batman-adv at all. Move it to batadv_hardif_enable_interface(). Also, restrict it to hardifs of the same mesh interface; different mesh interfaces should not interact at all. The batadv_check_known_mac_addr() argument is changed from `struct net_device` to `struct batadv_hard_iface` to achieve this. - The check only cares about hardifs in BATADV_IF_ACTIVE and BATADV_IF_TO_BE_ACTIVATED states, but interfaces in BATADV_IF_INACTIVE state should be checked as well, or the following steps will not result in a warning then they should: - Add two interfaces on down state with different MAC addresses to a mesh as hardifs - Change the MAC addresses so they confliect - Set interfaces to up state Now there will be two active hardifs with the same MAC address, but no warning. Fix by only ignoring hardifs in BATADV_IF_NOT_IN_USE state. The RCU lock can be dropped, as we're holding RTNL anyways when the function is called. While we're at it, also switch from pr_warn() to netdev_warn(). Fixes: c6c8fea29769 ("net: Add batman-adv meshing protocol") Signed-off-by: Matthias Schiffer --- Aside: batadv_hardif_add_interface() being called for all existing interfaces and having a global batadv_hardif_list at all is also not very nice, but this will be addressed separately, as changing it will require more refactoring. net/batman-adv/hard-interface.c | 37 ++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interfac= e.c index f145f9662653..07b436626afb 100644 --- a/net/batman-adv/hard-interface.c +++ b/net/batman-adv/hard-interface.c @@ -506,28 +506,34 @@ batadv_hardif_is_iface_up(const struct batadv_hard_if= ace *hard_iface) return false; } =20 -static void batadv_check_known_mac_addr(const struct net_device *net_dev) +static void batadv_check_known_mac_addr(const struct batadv_hard_iface *ha= rd_iface) { - const struct batadv_hard_iface *hard_iface; + const struct net_device *mesh_iface =3D hard_iface->mesh_iface; + const struct batadv_hard_iface *tmp_hard_iface; =20 - rcu_read_lock(); - list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) { - if (hard_iface->if_status !=3D BATADV_IF_ACTIVE && - hard_iface->if_status !=3D BATADV_IF_TO_BE_ACTIVATED) + if (!mesh_iface) + return; + + list_for_each_entry(tmp_hard_iface, &batadv_hardif_list, list) { + if (tmp_hard_iface =3D=3D hard_iface) + continue; + + if (tmp_hard_iface->mesh_iface !=3D mesh_iface) continue; =20 - if (hard_iface->net_dev =3D=3D net_dev) + if (tmp_hard_iface->if_status =3D=3D BATADV_IF_NOT_IN_USE) continue; =20 - if (!batadv_compare_eth(hard_iface->net_dev->dev_addr, - net_dev->dev_addr)) + if (!batadv_compare_eth(tmp_hard_iface->net_dev->dev_addr, + hard_iface->net_dev->dev_addr)) continue; =20 - pr_warn("The newly added mac address (%pM) already exists on: %s\n", - net_dev->dev_addr, hard_iface->net_dev->name); - pr_warn("It is strongly recommended to keep mac addresses unique to avoi= d problems!\n"); + netdev_warn(hard_iface->net_dev, + "The newly added mac address (%pM) already exists on: %s\n", + hard_iface->net_dev->dev_addr, tmp_hard_iface->net_dev->name); + netdev_warn(hard_iface->net_dev, + "It is strongly recommended to keep mac addresses unique to avoid p= roblems!\n"); } - rcu_read_unlock(); } =20 /** @@ -764,6 +770,8 @@ int batadv_hardif_enable_interface(struct batadv_hard_i= face *hard_iface, hard_iface->net_dev->name, hardif_mtu, required_mtu); =20 + batadv_check_known_mac_addr(hard_iface); + if (batadv_hardif_is_iface_up(hard_iface)) batadv_hardif_activate_interface(hard_iface); else @@ -902,7 +910,6 @@ batadv_hardif_add_interface(struct net_device *net_dev) =20 batadv_v_hardif_init(hard_iface); =20 - batadv_check_known_mac_addr(hard_iface->net_dev); kref_get(&hard_iface->refcount); list_add_tail_rcu(&hard_iface->list, &batadv_hardif_list); batadv_hardif_generation++; @@ -989,7 +996,7 @@ static int batadv_hard_if_event(struct notifier_block *= this, if (hard_iface->if_status =3D=3D BATADV_IF_NOT_IN_USE) goto hardif_put; =20 - batadv_check_known_mac_addr(hard_iface->net_dev); + batadv_check_known_mac_addr(hard_iface); =20 bat_priv =3D netdev_priv(hard_iface->mesh_iface); bat_priv->algo_ops->iface.update_mac(hard_iface); --=20 2.49.0