Skip to content

Commit 1181e1d

Browse files
committed
batman-adv: Make vis info stack traversal threadsafe
The batman-adv vis server has to a stack which stores all information about packets which should be send later. This stack is protected with a spinlock that is used to prevent concurrent write access to it. The send_vis_packets function has to take all elements from the stack and send them to other hosts over the primary interface. The send will be initiated without the lock which protects the stack. The implementation using list_for_each_entry_safe has the problem that it stores the next element as "safe ptr" to allow the deletion of the current element in the list. The list may be modified during the unlock/lock pair in the loop body which may make the safe pointer not pointing to correct next element. It is safer to remove and use the first element from the stack until no elements are available. This does not need reduntant information which would have to be validated each time the lock was removed. Reported-by: Russell Senior <russell@personaltelco.net> Signed-off-by: Sven Eckelmann <sven@narfation.org>
1 parent dda9fc6 commit 1181e1d

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

‎net/batman-adv/vis.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ static void send_vis_packets(struct work_struct *work)
816816
container_of(work, struct delayed_work, work);
817817
struct bat_priv *bat_priv =
818818
container_of(delayed_work, struct bat_priv, vis_work);
819-
struct vis_info *info, *temp;
819+
struct vis_info *info;
820820

821821
spin_lock_bh(&bat_priv->vis_hash_lock);
822822
purge_vis_packets(bat_priv);
@@ -826,8 +826,9 @@ static void send_vis_packets(struct work_struct *work)
826826
send_list_add(bat_priv, bat_priv->my_vis_info);
827827
}
828828

829-
list_for_each_entry_safe(info, temp, &bat_priv->vis_send_list,
830-
send_list) {
829+
while (!list_empty(&bat_priv->vis_send_list)) {
830+
info = list_first_entry(&bat_priv->vis_send_list,
831+
typeof(*info), send_list);
831832

832833
kref_get(&info->refcount);
833834
spin_unlock_bh(&bat_priv->vis_hash_lock);

0 commit comments

Comments
 (0)