From patchwork Fri Jan 28 17:34:07 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 713 Return-Path: Received: from v3-1039.vlinux.de (narfation.org [79.140.41.39]) by open-mesh.org (Postfix) with ESMTPS id 6FA4D1545B9 for ; Fri, 28 Jan 2011 18:34:13 +0100 (CET) Received: from sven-desktop.home.narfation.org (i59F6BEB3.versanet.de [89.246.190.179]) by v3-1039.vlinux.de (Postfix) with ESMTPSA id 2D2DD94061; Fri, 28 Jan 2011 18:34:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=narfation.org; s=mail; t=1296236085; bh=qG4S5pEvB+lS6+26Usp2T5Vt1mJaKRA+heue3cKj+VA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=Jsb/VEVp/TyzLx9or0VH8E2up7HtkvvmWdyuhBV/2Rwmdi2R15DU1hMf/ATzy2wmD L2vC/0WHZbNicGHgS4JG5JwmhqnIHzfjIQsEK2yW0F/ypHPzNi+oirgrgPpQOjxLmC Cu6dSDd35D7wVHU/wfysudng16o9X0vUbiz773tk= From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Date: Fri, 28 Jan 2011 18:34:07 +0100 Message-Id: <1296236047-15200-3-git-send-email-sven@narfation.org> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1296236047-15200-1-git-send-email-sven@narfation.org> References: <1296236047-15200-1-git-send-email-sven@narfation.org> Subject: [B.A.T.M.A.N.] [PATCH 3/3] batman-adv: Make vis info stack traversal threadsafe X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.11 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Jan 2011 17:34:13 -0000 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 Signed-off-by: Sven Eckelmann --- batman-adv/vis.c | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-) diff --git a/batman-adv/vis.c b/batman-adv/vis.c index 584781e..323f013 100644 --- a/batman-adv/vis.c +++ b/batman-adv/vis.c @@ -825,7 +825,7 @@ static void send_vis_packets(struct work_struct *work) container_of(work, struct delayed_work, work); struct bat_priv *bat_priv = container_of(delayed_work, struct bat_priv, vis_work); - struct vis_info *info, *temp; + struct vis_info *info; spin_lock_bh(&bat_priv->vis_hash_lock); purge_vis_packets(bat_priv); @@ -835,8 +835,9 @@ static void send_vis_packets(struct work_struct *work) send_list_add(bat_priv, bat_priv->my_vis_info); } - list_for_each_entry_safe(info, temp, &bat_priv->vis_send_list, - send_list) { + while (!list_empty(&bat_priv->vis_send_list)) { + info = list_first_entry(&bat_priv->vis_send_list, + typeof(*info), send_list); kref_get(&info->refcount); spin_unlock_bh(&bat_priv->vis_hash_lock);