net: fix a race in dst_release()
authorEric Dumazet <edumazet@google.com>
Tue, 10 Nov 2015 01:51:23 +0000 (17:51 -0800)
committerDavid S. Miller <davem@davemloft.net>
Tue, 10 Nov 2015 02:55:48 +0000 (21:55 -0500)
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>
net/core/dst.c

index 2a1818065e126d4645076f391e4dd689051e9d43..e6dc77252fe9fa3e401529426079f094c9f6f999 100644 (file)
@@ -306,7 +306,7 @@ void dst_release(struct dst_entry *dst)
                if (unlikely(newrefcnt < 0))
                        net_warn_ratelimited("%s: dst:%p refcnt:%d\n",
                                             __func__, dst, newrefcnt);
-               if (unlikely(dst->flags & DST_NOCACHE) && !newrefcnt)
+               if (!newrefcnt && unlikely(dst->flags & DST_NOCACHE))
                        call_rcu(&dst->rcu_head, dst_destroy_rcu);
        }
 }