[linux-next] LinuxNextTracking branch, master, updated. next-20140519

batman at open-mesh.org batman at open-mesh.org
Tue May 20 00:19:40 CEST 2014

The following commit has been merged in the master branch:
commit 377fe0f968b30a1a714fab53a908061914f30e26
Author: Antonio Quartulli <antonio at open-mesh.com>
Date:   Fri May 2 01:35:13 2014 +0200

    batman-adv: increase orig refcount when storing ref in gw_node
    A pointer to the orig_node representing a bat-gateway is
    stored in the gw_node->orig_node member, but the refcount
    for such orig_node is never increased.
    This leads to memory faults when gw_node->orig_node is accessed
    and the originator has already been freed.
    Fix this by increasing the refcount on gw_node creation
    and decreasing it on gw_node free.
    Signed-off-by: Antonio Quartulli <antonio at open-mesh.com>
    Signed-off-by: Marek Lindner <mareklindner at neomailbox.ch>

diff --git a/net/batman-adv/gateway_client.c b/net/batman-adv/gateway_client.c
index c835e13..90cff58 100644
--- a/net/batman-adv/gateway_client.c
+++ b/net/batman-adv/gateway_client.c
@@ -42,8 +42,10 @@
 static void batadv_gw_node_free_ref(struct batadv_gw_node *gw_node)
-	if (atomic_dec_and_test(&gw_node->refcount))
+	if (atomic_dec_and_test(&gw_node->refcount)) {
+		batadv_orig_node_free_ref(gw_node->orig_node);
 		kfree_rcu(gw_node, rcu);
+	}
 static struct batadv_gw_node *
@@ -406,9 +408,14 @@ static void batadv_gw_node_add(struct batadv_priv *bat_priv,
 	if (gateway->bandwidth_down == 0)
+	if (!atomic_inc_not_zero(&orig_node->refcount))
+		return;
 	gw_node = kzalloc(sizeof(*gw_node), GFP_ATOMIC);
-	if (!gw_node)
+	if (!gw_node) {
+		batadv_orig_node_free_ref(orig_node);
+	}
 	gw_node->orig_node = orig_node;


More information about the linux-merge mailing list