Commit c18bdd018e8912ca73ad6c12120b7283b5038875

Authored by Sven Eckelmann
Committed by Antonio Quartulli
1 parent db92ea5d4d

batman-adv: Only put gw_node list reference when removed

The batadv_gw_node reference counter in batadv_gw_node_update can only be
reduced when the list entry was actually removed. Otherwise the reference
counter may reach zero when batadv_gw_node_update is called from two
different contexts for the same gw_node but only one context is actually
removing the entry from the list.

The release function for this gw_node is not called inside the list_lock
spinlock protected region because the function batadv_gw_node_update still
holds a gw_node reference for the object pointer on the stack. Thus the
actual release function (when required) will be called only at the end of
the function.

Fixes: bd3524c14bd0 ("batman-adv: remove obsolete deleted attribute for gateway node")
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Antonio Quartulli <a@unstable.cc>

Showing 1 changed file with 4 additions and 3 deletions Side-by-side Diff

net/batman-adv/gateway_client.c
... ... @@ -527,10 +527,11 @@
527 527 * gets dereferenced.
528 528 */
529 529 spin_lock_bh(&bat_priv->gw.list_lock);
530   - hlist_del_init_rcu(&gw_node->list);
  530 + if (!hlist_unhashed(&gw_node->list)) {
  531 + hlist_del_init_rcu(&gw_node->list);
  532 + batadv_gw_node_free_ref(gw_node);
  533 + }
531 534 spin_unlock_bh(&bat_priv->gw.list_lock);
532   -
533   - batadv_gw_node_free_ref(gw_node);
534 535  
535 536 curr_gw = batadv_gw_get_selected_gw_node(bat_priv);
536 537 if (gw_node == curr_gw)