aboutsummaryrefslogtreecommitdiffstats
path: root/include/net
diff options
context:
space:
mode:
authorEric Dumazet <eric.dumazet@gmail.com>2011-07-29 15:00:53 -0400
committerDavid S. Miller <davem@davemloft.net>2011-08-03 06:34:12 -0400
commitf2c31e32b378a6653f8de606149d963baf11d7d3 (patch)
tree4eeb8075a93520935381a75514f309228e6824c0 /include/net
parent28f4881cbf9ce285edfc245a8990af36d21c062f (diff)
net: fix NULL dereferences in check_peer_redir()
Gergely Kalman reported crashes in check_peer_redir(). It appears commit f39925dbde778 (ipv4: Cache learned redirect information in inetpeer.) added a race, leading to possible NULL ptr dereference. Since we can now change dst neighbour, we should make sure a reader can safely use a neighbour. Add RCU protection to dst neighbour, and make sure check_peer_redir() can be called safely by different cpus in parallel. As neighbours are already freed after one RCU grace period, this patch should not add typical RCU penalty (cache cold effects) Many thanks to Gergely for providing a pretty report pointing to the bug. Reported-by: Gergely Kalman <synapse@hippy.csoma.elte.hu> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net')
-rw-r--r--include/net/dst.h17
1 files changed, 13 insertions, 4 deletions
diff --git a/include/net/dst.h b/include/net/dst.h
index 29e255796ce1..13d507d69ddb 100644
--- a/include/net/dst.h
+++ b/include/net/dst.h
@@ -37,7 +37,7 @@ struct dst_entry {
37 unsigned long _metrics; 37 unsigned long _metrics;
38 unsigned long expires; 38 unsigned long expires;
39 struct dst_entry *path; 39 struct dst_entry *path;
40 struct neighbour *_neighbour; 40 struct neighbour __rcu *_neighbour;
41#ifdef CONFIG_XFRM 41#ifdef CONFIG_XFRM
42 struct xfrm_state *xfrm; 42 struct xfrm_state *xfrm;
43#else 43#else
@@ -88,12 +88,17 @@ struct dst_entry {
88 88
89static inline struct neighbour *dst_get_neighbour(struct dst_entry *dst) 89static inline struct neighbour *dst_get_neighbour(struct dst_entry *dst)
90{ 90{
91 return dst->_neighbour; 91 return rcu_dereference(dst->_neighbour);
92}
93
94static inline struct neighbour *dst_get_neighbour_raw(struct dst_entry *dst)
95{
96 return rcu_dereference_raw(dst->_neighbour);
92} 97}
93 98
94static inline void dst_set_neighbour(struct dst_entry *dst, struct neighbour *neigh) 99static inline void dst_set_neighbour(struct dst_entry *dst, struct neighbour *neigh)
95{ 100{
96 dst->_neighbour = neigh; 101 rcu_assign_pointer(dst->_neighbour, neigh);
97} 102}
98 103
99extern u32 *dst_cow_metrics_generic(struct dst_entry *dst, unsigned long old); 104extern u32 *dst_cow_metrics_generic(struct dst_entry *dst, unsigned long old);
@@ -382,8 +387,12 @@ static inline void dst_rcu_free(struct rcu_head *head)
382static inline void dst_confirm(struct dst_entry *dst) 387static inline void dst_confirm(struct dst_entry *dst)
383{ 388{
384 if (dst) { 389 if (dst) {
385 struct neighbour *n = dst_get_neighbour(dst); 390 struct neighbour *n;
391
392 rcu_read_lock();
393 n = dst_get_neighbour(dst);
386 neigh_confirm(n); 394 neigh_confirm(n);
395 rcu_read_unlock();
387 } 396 }
388} 397}
389 398