aboutsummaryrefslogtreecommitdiffstats
path: root/include/net/sock.h
diff options
context:
space:
mode:
authorEric Dumazet <edumazet@google.com>2014-06-24 13:05:11 -0400
committerDavid S. Miller <davem@davemloft.net>2014-06-25 20:41:44 -0400
commitf88649721268999bdff09777847080a52004f691 (patch)
tree909bff5bf235780ccec651d41bfc8a370ba7ff27 /include/net/sock.h
parent99e72a0fed07d118d329f3046ad2ec2ae9357d63 (diff)
ipv4: fix dst race in sk_dst_get()
When IP route cache had been removed in linux-3.6, we broke assumption that dst entries were all freed after rcu grace period. DST_NOCACHE dst were supposed to be freed from dst_release(). But it appears we want to keep such dst around, either in UDP sockets or tunnels. In sk_dst_get() we need to make sure dst refcount is not 0 before incrementing it, or else we might end up freeing a dst twice. DST_NOCACHE set on a dst does not mean this dst can not be attached to a socket or a tunnel. Then, before actual freeing, we need to observe a rcu grace period to make sure all other cpus can catch the fact the dst is no longer usable. Signed-off-by: Eric Dumazet <edumazet@google.com> Reported-by: Dormando <dormando@rydia.net> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net/sock.h')
-rw-r--r--include/net/sock.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/include/net/sock.h b/include/net/sock.h
index 07b7fcd60d80..173cae485de1 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1730,8 +1730,8 @@ sk_dst_get(struct sock *sk)
1730 1730
1731 rcu_read_lock(); 1731 rcu_read_lock();
1732 dst = rcu_dereference(sk->sk_dst_cache); 1732 dst = rcu_dereference(sk->sk_dst_cache);
1733 if (dst) 1733 if (dst && !atomic_inc_not_zero(&dst->__refcnt))
1734 dst_hold(dst); 1734 dst = NULL;
1735 rcu_read_unlock(); 1735 rcu_read_unlock();
1736 return dst; 1736 return dst;
1737} 1737}