Skip to content

Commit 61fb0d0

Browse files
edumazetdavem330
authored andcommitted
ipv6: prevent possible fib6 leaks
At ipv6 route dismantle, fib6_drop_pcpu_from() is responsible for finding all percpu routes and set their ->from pointer to NULL, so that fib6_ref can reach its expected value (1). The problem right now is that other cpus can still catch the route being deleted, since there is no rcu grace period between the route deletion and call to fib6_drop_pcpu_from() This can leak the fib6 and associated resources, since no notifier will take care of removing the last reference(s). I decided to add another boolean (fib6_destroying) instead of reusing/renaming exception_bucket_flushed to ease stable backports, and properly document the memory barriers used to implement this fix. This patch has been co-developped with Wei Wang. Fixes: 93531c6 ("net/ipv6: separate handling of FIB entries from dst based routes") Signed-off-by: Eric Dumazet <edumazet@google.com> Reported-by: syzbot <syzkaller@googlegroups.com> Cc: Wei Wang <weiwan@google.com> Cc: David Ahern <dsahern@gmail.com> Cc: Martin Lau <kafai@fb.com> Acked-by: Wei Wang <weiwan@google.com> Acked-by: Martin KaFai Lau <kafai@fb.com> Reviewed-by: David Ahern <dsahern@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 185ce5c commit 61fb0d0

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

‎include/net/ip6_fib.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ struct fib6_info {
167167
dst_nocount:1,
168168
dst_nopolicy:1,
169169
dst_host:1,
170-
unused:3;
170+
fib6_destroying:1,
171+
unused:2;
171172

172173
struct fib6_nh fib6_nh;
173174
struct rcu_head rcu;

‎net/ipv6/ip6_fib.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,12 @@ static void fib6_drop_pcpu_from(struct fib6_info *f6i,
904904
{
905905
int cpu;
906906

907+
/* Make sure rt6_make_pcpu_route() wont add other percpu routes
908+
* while we are cleaning them here.
909+
*/
910+
f6i->fib6_destroying = 1;
911+
mb(); /* paired with the cmpxchg() in rt6_make_pcpu_route() */
912+
907913
/* release the reference to this fib entry from
908914
* all of its cached pcpu routes
909915
*/
@@ -927,6 +933,9 @@ static void fib6_purge_rt(struct fib6_info *rt, struct fib6_node *fn,
927933
{
928934
struct fib6_table *table = rt->fib6_table;
929935

936+
if (rt->rt6i_pcpu)
937+
fib6_drop_pcpu_from(rt, table);
938+
930939
if (refcount_read(&rt->fib6_ref) != 1) {
931940
/* This route is used as dummy address holder in some split
932941
* nodes. It is not leaked, but it still holds other resources,
@@ -948,9 +957,6 @@ static void fib6_purge_rt(struct fib6_info *rt, struct fib6_node *fn,
948957
fn = rcu_dereference_protected(fn->parent,
949958
lockdep_is_held(&table->tb6_lock));
950959
}
951-
952-
if (rt->rt6i_pcpu)
953-
fib6_drop_pcpu_from(rt, table);
954960
}
955961
}
956962

‎net/ipv6/route.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,13 @@ static struct rt6_info *rt6_make_pcpu_route(struct net *net,
12951295
prev = cmpxchg(p, NULL, pcpu_rt);
12961296
BUG_ON(prev);
12971297

1298+
if (res->f6i->fib6_destroying) {
1299+
struct fib6_info *from;
1300+
1301+
from = xchg((__force struct fib6_info **)&pcpu_rt->from, NULL);
1302+
fib6_info_release(from);
1303+
}
1304+
12981305
return pcpu_rt;
12991306
}
13001307

0 commit comments

Comments
 (0)