aboutsummaryrefslogtreecommitdiffstats
path: root/net/batman-adv/originator.h
diff options
context:
space:
mode:
authorMarek Lindner <lindner_marek@yahoo.de>2011-02-18 07:28:10 -0500
committerMarek Lindner <lindner_marek@yahoo.de>2011-03-05 06:52:01 -0500
commit7b36e8eef989fc59535b4f1d3fc0f83afaf419d4 (patch)
treef0900101542966e0655ca5f115b5b0bc409b1e74 /net/batman-adv/originator.h
parent7aadf889e897155c45cda230d2a6701ad1fbff61 (diff)
batman-adv: Correct rcu refcounting for orig_node
It might be possible that 2 threads access the same data in the same rcu grace period. The first thread calls call_rcu() to decrement the refcount and free the data while the second thread increases the refcount to use the data. To avoid this race condition all refcount operations have to be atomic. Reported-by: Sven Eckelmann <sven@narfation.org> Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
Diffstat (limited to 'net/batman-adv/originator.h')
-rw-r--r--net/batman-adv/originator.h6
1 files changed, 4 insertions, 2 deletions
diff --git a/net/batman-adv/originator.h b/net/batman-adv/originator.h
index b4b9a09259fd..3d7a39d4df0f 100644
--- a/net/batman-adv/originator.h
+++ b/net/batman-adv/originator.h
@@ -27,7 +27,7 @@
27int originator_init(struct bat_priv *bat_priv); 27int originator_init(struct bat_priv *bat_priv);
28void originator_free(struct bat_priv *bat_priv); 28void originator_free(struct bat_priv *bat_priv);
29void purge_orig_ref(struct bat_priv *bat_priv); 29void purge_orig_ref(struct bat_priv *bat_priv);
30void orig_node_free_ref(struct kref *refcount); 30void orig_node_free_ref(struct orig_node *orig_node);
31struct orig_node *get_orig_node(struct bat_priv *bat_priv, uint8_t *addr); 31struct orig_node *get_orig_node(struct bat_priv *bat_priv, uint8_t *addr);
32struct neigh_node *create_neighbor(struct orig_node *orig_node, 32struct neigh_node *create_neighbor(struct orig_node *orig_node,
33 struct orig_node *orig_neigh_node, 33 struct orig_node *orig_neigh_node,
@@ -88,8 +88,10 @@ static inline struct orig_node *orig_hash_find(struct bat_priv *bat_priv,
88 if (!compare_eth(orig_node, data)) 88 if (!compare_eth(orig_node, data))
89 continue; 89 continue;
90 90
91 if (!atomic_inc_not_zero(&orig_node->refcount))
92 continue;
93
91 orig_node_tmp = orig_node; 94 orig_node_tmp = orig_node;
92 kref_get(&orig_node_tmp->refcount);
93 break; 95 break;
94 } 96 }
95 rcu_read_unlock(); 97 rcu_read_unlock();