From patchwork Mon Dec 13 00:18:52 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Lindner X-Patchwork-Id: 613 Return-Path: Received: from nm17.bullet.mail.ukl.yahoo.com (nm17.bullet.mail.ukl.yahoo.com [217.146.183.191]) by open-mesh.org (Postfix) with SMTP id D98961545C3 for ; Mon, 13 Dec 2010 01:21:49 +0100 (CET) Received: from [217.146.183.181] by nm17.bullet.mail.ukl.yahoo.com with NNFMP; 13 Dec 2010 00:21:47 -0000 Received: from [77.238.184.63] by tm12.bullet.mail.ukl.yahoo.com with NNFMP; 13 Dec 2010 00:21:47 -0000 Received: from [127.0.0.1] by smtp132.mail.ukl.yahoo.com with NNFMP; 13 Dec 2010 00:21:47 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.de; s=s1024; t=1292199707; bh=eYw9cpujQ/0ejWwGEBk0hcQeeldy4+52O6ISjbMXaVI=; h=X-Yahoo-Newman-Id:Received:X-Yahoo-SMTP:X-YMail-OSG:X-Yahoo-Newman-Property:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References; b=udLhab/SDFIeBQ+kH0SHuPEAALcCxy9kOCfuZjdWYuDGLTsBdBJs6GwEew63s5NbhPp1e3ovDRD+7DR9hOclZqvaiOvA4D4uFPxNMgJtYFSrqpy6Aj2Qo5X8liRrceYxLQMzG8u7yYieSBdRw7bHNADh4iLW0aDVGBVQ1uaqeWw= X-Yahoo-Newman-Id: 656753.25009.bm@smtp132.mail.ukl.yahoo.com Received: from localhost (lindner_marek@81.57.254.118 with plain) by smtp132.mail.ukl.yahoo.com with SMTP; 12 Dec 2010 16:21:44 -0800 PST X-Yahoo-SMTP: tW.h3tiswBBMXO2coYcbPigGD5Lt6zY_.Zc- X-YMail-OSG: npr228IVM1kE_3XfOZByUW5CgcaGe.pkPPOpo4trjWW2pSD QbIHKlwxe282PDd79KFCRn4Wa3seID4oZnF5pmk1H2O55Px60_enarS2e1by 8voVA9R_O6H_1VsOKjz_0FZ2hISWLTiYV6eX9Lo89deigXzKPby2ojt1vjE9 9ck0z_zzBeyMq_aHhsqBcLWC7.7cfpULuofhkccZrDJvazJRmCWBz5BIjzrJ 5yUGSql6a.DeCtwoAAj2T.eiqXKO9gF_Z.y4.O4sGxBvy7RYktbF19XjLChj ._lsfvCoCdqoTc4SBRbe2OwiuIQ-- X-Yahoo-Newman-Property: ymail-3 From: Marek Lindner To: b.a.t.m.a.n@lists.open-mesh.org Date: Mon, 13 Dec 2010 01:18:52 +0100 Message-Id: <1292199536-4644-1-git-send-email-lindner_marek@yahoo.de> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <201012130118.14949.lindner_marek@yahoo.de> References: <201012130118.14949.lindner_marek@yahoo.de> Cc: Marek Lindner Subject: [B.A.T.M.A.N.] [PATCH 1/5] batman-adv: protect neigh_nodes used outside of rcu_locks with refcounting 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: Mon, 13 Dec 2010 00:21:50 -0000 Signed-off-by: Marek Lindner --- batman-adv/routing.c | 40 +++++++++++++++++++++++++++++++--------- 1 files changed, 31 insertions(+), 9 deletions(-) diff --git a/batman-adv/routing.c b/batman-adv/routing.c index abce1ae..7e9499f 100644 --- a/batman-adv/routing.c +++ b/batman-adv/routing.c @@ -152,6 +152,7 @@ static int is_bidirectional_neigh(struct orig_node *orig_node, struct neigh_node *neigh_node = NULL, *tmp_neigh_node = NULL; struct hlist_node *node; unsigned char total_count; + int ret = 0; if (orig_node == orig_neigh_node) { rcu_read_lock(); @@ -163,7 +164,6 @@ static int is_bidirectional_neigh(struct orig_node *orig_node, (tmp_neigh_node->if_incoming == if_incoming)) neigh_node = tmp_neigh_node; } - rcu_read_unlock(); if (!neigh_node) neigh_node = create_neighbor(orig_node, @@ -172,7 +172,10 @@ static int is_bidirectional_neigh(struct orig_node *orig_node, if_incoming); /* create_neighbor failed, return 0 */ if (!neigh_node) - return 0; + goto unlock; + + kref_get(&neigh_node->refcount); + rcu_read_unlock(); neigh_node->last_valid = jiffies; } else { @@ -186,7 +189,6 @@ static int is_bidirectional_neigh(struct orig_node *orig_node, (tmp_neigh_node->if_incoming == if_incoming)) neigh_node = tmp_neigh_node; } - rcu_read_unlock(); if (!neigh_node) neigh_node = create_neighbor(orig_neigh_node, @@ -195,7 +197,10 @@ static int is_bidirectional_neigh(struct orig_node *orig_node, if_incoming); /* create_neighbor failed, return 0 */ if (!neigh_node) - return 0; + goto unlock; + + kref_get(&neigh_node->refcount); + rcu_read_unlock(); } orig_node->last_valid = jiffies; @@ -251,9 +256,16 @@ static int is_bidirectional_neigh(struct orig_node *orig_node, /* if link has the minimum required transmission quality * consider it bidirectional */ if (batman_packet->tq >= TQ_TOTAL_BIDRECT_LIMIT) - return 1; + ret = 1; - return 0; + goto out; + +unlock: + rcu_read_unlock(); +out: + if (neigh_node) + kref_put(&neigh_node->refcount, neigh_node_free_ref); + return ret; } static void update_orig(struct bat_priv *bat_priv, @@ -288,23 +300,25 @@ static void update_orig(struct bat_priv *bat_priv, tmp_neigh_node->tq_avg = ring_buffer_avg(tmp_neigh_node->tq_recv); } - rcu_read_unlock(); if (!neigh_node) { struct orig_node *orig_tmp; orig_tmp = get_orig_node(bat_priv, ethhdr->h_source); if (!orig_tmp) - return; + goto unlock; neigh_node = create_neighbor(orig_node, orig_tmp, ethhdr->h_source, if_incoming); if (!neigh_node) - return; + goto unlock; } else bat_dbg(DBG_BATMAN, bat_priv, "Updating existing last-hop neighbor of originator\n"); + kref_get(&neigh_node->refcount); + rcu_read_unlock(); + orig_node->flags = batman_packet->flags; neigh_node->last_valid = jiffies; @@ -358,6 +372,14 @@ update_gw: (atomic_read(&bat_priv->gw_mode) == GW_MODE_CLIENT) && (atomic_read(&bat_priv->gw_sel_class) > 2)) gw_check_election(bat_priv, orig_node); + + goto out; + +unlock: + rcu_read_unlock(); +out: + if (neigh_node) + kref_put(&neigh_node->refcount, neigh_node_free_ref); } /* checks whether the host restarted and is in the protection time.