From patchwork Sat Mar 5 18:05:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 15899 X-Patchwork-Delegate: mareklindner@neomailbox.ch Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from open-mesh.org (localhost [127.0.0.1]) by open-mesh.org (Postfix) with ESMTP id 631A782395; Sat, 5 Mar 2016 19:05:38 +0100 (CET) Authentication-Results: open-mesh.org; dkim=fail reason="verification failed; unprotected key" header.d=narfation.org header.i=@narfation.org header.b=Hk41MT+k; dkim-adsp=fail (unprotected policy); dkim-atps=neutral Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=79.140.41.39; helo=v3-1039.vlinux.de; envelope-from=sven@narfation.org; receiver=b.a.t.m.a.n@lists.open-mesh.org Authentication-Results: open-mesh.org; dmarc=pass header.from=narfation.org Received: from v3-1039.vlinux.de (narfation.org [79.140.41.39]) by open-mesh.org (Postfix) with ESMTPS id 33B0A82393 for ; Sat, 5 Mar 2016 19:05:36 +0100 (CET) Received: from sven-desktop.home.narfation.org (p200300C593C286FD0000000000002E16.dip0.t-ipconnect.de [IPv6:2003:c5:93c2:86fd::2e16]) by v3-1039.vlinux.de (Postfix) with ESMTPSA id AF65F110103; Sat, 5 Mar 2016 19:05:35 +0100 (CET) Authentication-Results: v3-1039.vlinux.de; dmarc=none header.from=narfation.org DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=narfation.org; s=20121; t=1457201135; bh=ZIOkE/kFHMm5ARF3/nFy++HMRfKD8M7bV45yOsGxf8M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hk41MT+k/Zchh9CE7d0bYayxedXWz4400yT/7UZtL99Or8QRsJDUQEwI3Rj86ZICE 8Wk6wEQWHBNrlzReoDFbUMprll1dE7x+aiV7sEgAx5uVK+ZVRbjazlJF6R56UCOcr7 fyZ9WBqzgki20k7qDK9UAxWF1Wc58VRf0YRv8Da0= From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Date: Sat, 5 Mar 2016 19:05:24 +0100 Message-Id: <1457201124-8495-1-git-send-email-sven@narfation.org> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1457190564-11419-9-git-send-email-sven@narfation.org> References: <1457190564-11419-9-git-send-email-sven@narfation.org> Subject: [B.A.T.M.A.N.] [PATCH v2 9/9] batman-adv: Use kref_get for _batadv_update_route X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking Errors-To: b.a.t.m.a.n-bounces@lists.open-mesh.org Sender: "B.A.T.M.A.N" _batadv_update_route requires that the caller already has a valid reference for neigh_node. It is therefore not possible that it has an reference counter of 0 and was still given to this function The kref_get function instead WARNs (with debug information) when the reference counter would still be 0. This makes a bug in batman-adv better visible because kref_get_unless_zero would have ignored this problem. Signed-off-by: Sven Eckelmann --- This patch requires https://patchwork.open-mesh.org/patch/15888/ v2: - Remove one of the empty lines around the removed block net/batman-adv/routing.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c index ffc4c09..06581af 100644 --- a/net/batman-adv/routing.c +++ b/net/batman-adv/routing.c @@ -100,13 +100,11 @@ static void _batadv_update_route(struct batadv_priv *bat_priv, if (curr_router) batadv_neigh_node_put(curr_router); - /* increase refcount of new best neighbor */ - if (neigh_node && !kref_get_unless_zero(&neigh_node->refcount)) - neigh_node = NULL; - spin_lock_bh(&orig_node->neigh_list_lock); curr_router = rcu_dereference_protected(orig_ifinfo->router, true); + if (neigh_node) + kref_get(&neigh_node->refcount); rcu_assign_pointer(orig_ifinfo->router, neigh_node); spin_unlock_bh(&orig_node->neigh_list_lock); batadv_orig_ifinfo_put(orig_ifinfo);