ipv6: prevent possible fib6 leaks
Subsystems (3)
PATCH 1/1 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.
--- include/net/ip6_fib.h | 3 ++- net/ipv6/ip6_fib.c | 12 +++++++++--- net/ipv6/route.c | 7 +++++++ 3 files changed, 18 insertions(+), 4 deletions(-)
include/net/ip6_fib.h +2 -1
@@ -167,7 +167,8 @@ struct fib6_info { dst_nocount:1, dst_nopolicy:1, dst_host:1, - unused:3; + fib6_destroying:1, + unused:2;struct fib6_nh fib6_nh;struct rcu_head rcu;
net/ipv6/ip6_fib.c +9 -3
@@ -904,6 +904,12 @@ static void fib6_drop_pcpu_from(struct fib6_info *f6i, {int cpu; +/* Make sure rt6_make_pcpu_route() wont add other percpu routes +* while we are cleaning them here. +*/ + f6i->fib6_destroying =1 ; +mb ();/* paired with the cmpxchg() in rt6_make_pcpu_route() */ +/* release the reference to this fib entry from * all of its cached pcpu routes */
@@ -927,6 +933,9 @@ static void fib6_purge_rt(struct fib6_info *rt, struct fib6_node *fn, {struct fib6_table *table = rt->fib6_table; +if (rt->rt6i_pcpu) +fib6_drop_pcpu_from (rt, table); +if (refcount_read (&rt->fib6_ref) !=1 ) {/* This route is used as dummy address holder in some split * 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, fn =rcu_dereference_protected (fn->parent,lockdep_is_held (&table->tb6_lock)); } - -if (rt->rt6i_pcpu) -fib6_drop_pcpu_from (rt, table); } }
net/ipv6/route.c +7 -0
@@ -1295,6 +1295,13 @@ static struct rt6_info *rt6_make_pcpu_route(struct net *net, prev =cmpxchg (p,NULL , pcpu_rt);BUG_ON (prev); +if (res->f6i->fib6_destroying) { +struct fib6_info *from; + + from =xchg ((__force struct fib6_info **)&pcpu_rt->from,NULL ); +fib6_info_release (from); + } +return pcpu_rt; }
Signature · 1 line
2.21.0.1020.gf2820cf01a-goog
Quoted 18 lines · Eric Dumazet
At ipv6 route dismantle,
fib6_drop_pcpu_from()is responsible for finding all percpu routes and set their ->from pointer to NULL, so thatfib6_refcan 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/renamingexception_bucket_flushedto ease stable backports, and properly document the memory barriers used to implement this fix.This patch has been co-developped with Wei Wang.
Quoted 7 lines
Fixes 93531c674315 ("net/ipv6: separate handling of FIB entries from dst based routes")Signed-off-by Eric Dumazet <[email protected]>Reported-by syzbot <[email protected]>Cc Wei Wang <[email protected]>Cc David Ahern <[email protected]>Cc Martin Lau <[email protected]>---
Thanks for the fix Eric.
Quoted 77 lines
include/net/ip6_fib.h | 3 ++- net/ipv6/ip6_fib.c | 12 +++++++++--- net/ipv6/route.c | 7 +++++++ 3 files changed, 18 insertions(+), 4 deletions(-)include/net/ip6_fib.h +2
-1@@ -167,7 +167,8 @@ struct fib6_info { dst_nocount:1, dst_nopolicy:1, dst_host:1, - unused:3; + fib6_destroying:1, + unused:2;struct fib6_nh fib6_nh;struct rcu_head rcu;net/ipv6/ip6_fib.c +9
-3@@ -904,6 +904,12 @@ static void fib6_drop_pcpu_from(struct fib6_info *f6i, {int cpu; +/* Make sure rt6_make_pcpu_route() wont add other percpu routes +* while we are cleaning them here. +*/ + f6i->fib6_destroying =1 ; +mb ();/* paired with the cmpxchg() in rt6_make_pcpu_route() */ +/* release the reference to this fib entry from * all of its cached pcpu routes */ @@ -927,6 +933,9 @@ static void fib6_purge_rt(struct fib6_info *rt, struct fib6_node *fn, {struct fib6_table *table = rt->fib6_table; +if (rt->rt6i_pcpu) +fib6_drop_pcpu_from (rt, table); +if (refcount_read (&rt->fib6_ref) !=1 ) {/* This route is used as dummy address holder in some split * 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, fn =rcu_dereference_protected (fn->parent,lockdep_is_held (&table->tb6_lock)); } - -if (rt->rt6i_pcpu) -fib6_drop_pcpu_from (rt, table); } }net/ipv6/route.c +7
-1@@ -1295,6 +1295,13 @@ static struct rt6_info *rt6_make_pcpu_route(struct net *net, prev =cmpxchg (p,NULL , pcpu_rt);BUG_ON (prev); +if (res->f6i->fib6_destroying) { +struct fib6_info *from; + + from =xchg ((__force struct fib6_info **)&pcpu_rt->from,NULL ); +fib6_info_release (from); + } +return pcpu_rt; } --2.21.0.1020.gf2820cf01a-goog
Quoted 8 lines · Eric Dumazet
At ipv6 route dismantle,
fib6_drop_pcpu_from()is responsible for finding all percpu routes and set their ->from pointer to NULL, so thatfib6_refcan 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()
Quoted 8 lines
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/renamingexception_bucket_flushedto ease stable backports, and properly document the memory barriers used to implement this fix.This patch has been co-developped with Wei Wang.
Nice fix!
Quoted 23 lines · Eric Dumazet
At ipv6 route dismantle,
fib6_drop_pcpu_from()is responsible for finding all percpu routes and set their ->from pointer to NULL, so thatfib6_refcan 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/renamingexception_bucket_flushedto ease stable backports, and properly document the memory barriers used to implement this fix.This patch has been co-developped with Wei Wang.
Fixes 93531c674315 ("net/ipv6: separate handling of FIB entries from dst based routes")Signed-off-by Eric Dumazet <[email protected]>Reported-by syzbot <[email protected]>Cc Wei Wang <[email protected]>Cc David Ahern <[email protected]>Cc Martin Lau <[email protected]>
Quoted 6 lines
--- include/net/ip6_fib.h | 3 ++- net/ipv6/ip6_fib.c | 12 +++++++++--- net/ipv6/route.c | 7 +++++++ 3 files changed, 18 insertions(+), 4 deletions(-)
Thanks, Eric. Attaching 'from' to rt6_info makes v6 much more complicated than ipv4.
David Miller
maintainerFrom: Eric Dumazet <[email protected]>
Date: Wed, 15 May 2019 19:39:52 -0700
Quoted 15 lines
At ipv6 route dismantle,
fib6_drop_pcpu_from()is responsible for finding all percpu routes and set their ->from pointer to NULL, so thatfib6_refcan 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/renamingexception_bucket_flushedto ease stable backports, and properly document the memory barriers used to implement this fix.
Quoted 5 lines
This patch has been co-developped with Wei Wang.
Fixes 93531c674315 ("net/ipv6: separate handling of FIB entries from dst based routes")Signed-off-by Eric Dumazet <[email protected]>Reported-by syzbot <[email protected]>
Applied and queued up for -stable.