]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
batman-adv: clear current gateway during teardown
authorRuijie Li <ruijieli51@gmail.com>
Thu, 14 May 2026 08:13:25 +0000 (16:13 +0800)
committerSven Eckelmann <sven@narfation.org>
Thu, 14 May 2026 16:48:40 +0000 (18:48 +0200)
batadv_gw_node_free() removes the gateway list entries during mesh teardown,
but it does not clear the currently selected gateway. This leaves stale
gateway state behind across cleanup and can break a later mesh recreation.

Clear bat_priv->gw.curr_gw before walking the gateway list so the selected
gateway reference is dropped as part of teardown.

Fixes: 2265c1410864 ("batman-adv: gateway election code refactoring")
Cc: stable@kernel.org
Reported-by: Yuan Tan <yuantan098@gmail.com>
Reported-by: Yifan Wu <yifanwucs@gmail.com>
Reported-by: Juefei Pu <tomapufckgml@gmail.com>
Reported-by: Xin Liu <bird@lzu.edu.cn>
Signed-off-by: Ruijie Li <ruijieli51@gmail.com>
Signed-off-by: Zhanpeng Li <lzhanpeng2025@lzu.edu.cn>
Signed-off-by: Ren Wei <n05ec@lzu.edu.cn>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
net/batman-adv/gateway_client.c

index 51e9c081a2a4ef2443a7a2a224d94e2239bac907..a9d0346e8332e52bccb95f234374bdca5f8ed763 100644 (file)
@@ -478,10 +478,14 @@ void batadv_gw_node_delete(struct batadv_priv *bat_priv,
  */
 void batadv_gw_node_free(struct batadv_priv *bat_priv)
 {
+       struct batadv_gw_node *curr_gw;
        struct batadv_gw_node *gw_node;
        struct hlist_node *node_tmp;
 
        spin_lock_bh(&bat_priv->gw.list_lock);
+       curr_gw = rcu_replace_pointer(bat_priv->gw.curr_gw, NULL, true);
+       batadv_gw_node_put(curr_gw);
+
        hlist_for_each_entry_safe(gw_node, node_tmp,
                                  &bat_priv->gw.gateway_list, list) {
                hlist_del_init_rcu(&gw_node->list);