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.4.113~122 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=74c1a5ecfcf8cd6a6238578add2ce0aefd5e44ed;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 [lizf: Backported to 3.4: adjust context] Signed-off-by: Zefan Li --- diff --git a/net/core/dst.c b/net/core/dst.c index 43d94cedbf7c0..54ba1ebba30ef 100644 --- a/net/core/dst.c +++ b/net/core/dst.c @@ -272,7 +272,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)) { dst = dst_destroy(dst); if (dst) __dst_free(dst);