net: fix a race in dst_release()
authorEric Dumazet <edumazet@google.com>
Tue, 10 Nov 2015 01:51:23 +0000 (17:51 -0800)
committerBen Hutchings <ben@decadent.org.uk>
Fri, 27 Nov 2015 12:48:24 +0000 (12:48 +0000)
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 <gthelen@google.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
[bwh: Backported to 3.2: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
net/core/dst.c

index d5e2c4c..946e214 100644 (file)
@@ -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);