ipv6: set dst.obsolete when a cached route has expired
authorXin Long <lucien.xin@gmail.com>
Sat, 26 Aug 2017 12:10:10 +0000 (20:10 +0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 28 Aug 2017 22:45:04 +0000 (15:45 -0700)
Now it doesn't check for the cached route expiration in ipv6's
dst_ops->check(), because it trusts dst_gc that would clean the
cached route up when it's expired.

The problem is in dst_gc, it would clean the cached route only
when it's refcount is 1. If some other module (like xfrm) keeps
holding it and the module only release it when dst_ops->check()
fails.

But without checking for the cached route expiration, .check()
may always return true. Meanwhile, without releasing the cached
route, dst_gc couldn't del it. It will cause this cached route
never to expire.

This patch is to set dst.obsolete with DST_OBSOLETE_KILL in .gc
when it's expired, and check obsolete != DST_OBSOLETE_FORCE_CHK
in .check.

Note that this is even needed when ipv6 dst_gc timer is removed
one day. It would set dst.obsolete in .redirect and .update_pmtu
instead, and check for cached route expiration when getting it,
just like what ipv4 route does.

Reported-by: Jianlin Shi <jishi@redhat.com>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
Acked-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv6/ip6_fib.c
net/ipv6/route.c

index 10b4b1f8b838854fc2f2d3b9ac0b04c06a700b2f..e1c85bb4eac0fd50905fc441e726eca843fc36a8 100644 (file)
@@ -1795,8 +1795,10 @@ static int fib6_age(struct rt6_info *rt, void *arg)
                }
                gc_args->more++;
        } else if (rt->rt6i_flags & RTF_CACHE) {
+               if (time_after_eq(now, rt->dst.lastuse + gc_args->timeout))
+                       rt->dst.obsolete = DST_OBSOLETE_KILL;
                if (atomic_read(&rt->dst.__refcnt) == 1 &&
-                   time_after_eq(now, rt->dst.lastuse + gc_args->timeout)) {
+                   rt->dst.obsolete == DST_OBSOLETE_KILL) {
                        RT6_TRACE("aging clone %p\n", rt);
                        return -1;
                } else if (rt->rt6i_flags & RTF_GATEWAY) {
index 86fb2411e2bda7d148a6467411b4d025bd4c397c..2d0e7798c793a4058dc0ef3a5b50734e774500a9 100644 (file)
@@ -440,7 +440,8 @@ static bool rt6_check_expired(const struct rt6_info *rt)
                if (time_after(jiffies, rt->dst.expires))
                        return true;
        } else if (rt->dst.from) {
-               return rt6_check_expired((struct rt6_info *) rt->dst.from);
+               return rt->dst.obsolete != DST_OBSOLETE_FORCE_CHK ||
+                      rt6_check_expired((struct rt6_info *)rt->dst.from);
        }
        return false;
 }