Skip to content

Commit 8772cc4

Browse files
neocturnesimonwunderlich
authored andcommitted
batman-adv: fix duplicate MAC address check
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 in down state with different MAC addresses to a mesh as hardifs - Change the MAC addresses so they conflict - 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. Fixes: c6c8fea ("net: Add batman-adv meshing protocol") Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net> Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
1 parent 61f96e6 commit 8772cc4

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

net/batman-adv/hard-interface.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -506,28 +506,32 @@ batadv_hardif_is_iface_up(const struct batadv_hard_iface *hard_iface)
506506
return false;
507507
}
508508

509-
static void batadv_check_known_mac_addr(const struct net_device *net_dev)
509+
static void batadv_check_known_mac_addr(const struct batadv_hard_iface *hard_iface)
510510
{
511-
const struct batadv_hard_iface *hard_iface;
511+
const struct net_device *mesh_iface = hard_iface->mesh_iface;
512+
const struct batadv_hard_iface *tmp_hard_iface;
512513

513-
rcu_read_lock();
514-
list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
515-
if (hard_iface->if_status != BATADV_IF_ACTIVE &&
516-
hard_iface->if_status != BATADV_IF_TO_BE_ACTIVATED)
514+
if (!mesh_iface)
515+
return;
516+
517+
list_for_each_entry(tmp_hard_iface, &batadv_hardif_list, list) {
518+
if (tmp_hard_iface == hard_iface)
519+
continue;
520+
521+
if (tmp_hard_iface->mesh_iface != mesh_iface)
517522
continue;
518523

519-
if (hard_iface->net_dev == net_dev)
524+
if (tmp_hard_iface->if_status == BATADV_IF_NOT_IN_USE)
520525
continue;
521526

522-
if (!batadv_compare_eth(hard_iface->net_dev->dev_addr,
523-
net_dev->dev_addr))
527+
if (!batadv_compare_eth(tmp_hard_iface->net_dev->dev_addr,
528+
hard_iface->net_dev->dev_addr))
524529
continue;
525530

526531
pr_warn("The newly added mac address (%pM) already exists on: %s\n",
527-
net_dev->dev_addr, hard_iface->net_dev->name);
532+
hard_iface->net_dev->dev_addr, tmp_hard_iface->net_dev->name);
528533
pr_warn("It is strongly recommended to keep mac addresses unique to avoid problems!\n");
529534
}
530-
rcu_read_unlock();
531535
}
532536

533537
/**
@@ -764,6 +768,8 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
764768
hard_iface->net_dev->name, hardif_mtu,
765769
required_mtu);
766770

771+
batadv_check_known_mac_addr(hard_iface);
772+
767773
if (batadv_hardif_is_iface_up(hard_iface))
768774
batadv_hardif_activate_interface(hard_iface);
769775
else
@@ -902,7 +908,6 @@ batadv_hardif_add_interface(struct net_device *net_dev)
902908

903909
batadv_v_hardif_init(hard_iface);
904910

905-
batadv_check_known_mac_addr(hard_iface->net_dev);
906911
kref_get(&hard_iface->refcount);
907912
list_add_tail_rcu(&hard_iface->list, &batadv_hardif_list);
908913
batadv_hardif_generation++;
@@ -989,7 +994,7 @@ static int batadv_hard_if_event(struct notifier_block *this,
989994
if (hard_iface->if_status == BATADV_IF_NOT_IN_USE)
990995
goto hardif_put;
991996

992-
batadv_check_known_mac_addr(hard_iface->net_dev);
997+
batadv_check_known_mac_addr(hard_iface);
993998

994999
bat_priv = netdev_priv(hard_iface->mesh_iface);
9951000
bat_priv->algo_ops->iface.update_mac(hard_iface);

0 commit comments

Comments
 (0)