From: Eric Dumazet Date: Tue, 10 Nov 2015 01:51:23 +0000 (-0800) Subject: net: fix a race in dst_release() X-Git-Tag: v3.16.35~1060 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=86c908b4d5346bf270e84d8dee1a1bc41a91eb57;p=thirdparty%2Fkernel%2Fstable.git net: fix a race in dst_release() commit d69bbf88c8d0b367cf3e3a052f6daadf630ee566 upstream. Only cpu seeing dst refcount going to 0 can safely dereference dst->flags. Otherwise an other cpu might already have freed the dst. Fixes: 27b75c95f10d ("net: avoid RCU for NOCACHE dst") Reported-by: Greg Thelen Signed-off-by: Eric Dumazet Signed-off-by: David S. Miller [ luis: backported to 3.16: adjusted context ] Signed-off-by: Luis Henriques --- diff --git a/net/core/dst.c b/net/core/dst.c index a028409ee438c..a80e92346b9bf 100644 --- a/net/core/dst.c +++ b/net/core/dst.c @@ -285,7 +285,7 @@ void dst_release(struct dst_entry *dst) newrefcnt = atomic_dec_return(&dst->__refcnt); WARN_ON(newrefcnt < 0); - if (unlikely(dst->flags & DST_NOCACHE) && !newrefcnt) + if (!newrefcnt && unlikely(dst->flags & DST_NOCACHE)) call_rcu(&dst->rcu_head, dst_destroy_rcu); } }