diff options
author | Sabrina Dubroca <sd@queasysnail.net> | 2017-09-08 11:26:19 +0300 |
---|---|---|
committer | Ben Hutchings <ben@decadent.org.uk> | 2017-11-26 16:51:08 +0300 |
commit | 4faaefb9e038c5aa09ff5b33a91c2bf9b8b37e93 (patch) | |
tree | 7a1ed6419ad2d779afaa68efd7217f63b2a9f88b /net/ipv6 | |
parent | 5cb8ec47887b051ff0d967126651644a0ea6eb9e (diff) | |
download | linux-4faaefb9e038c5aa09ff5b33a91c2bf9b8b37e93.tar.xz |
ipv6: fix memory leak with multiple tables during netns destruction
commit ba1cc08d9488c94cb8d94f545305688b72a2a300 upstream.
fib6_net_exit only frees the main and local tables. If another table was
created with fib6_alloc_table, we leak it when the netns is destroyed.
Fix this in the same way ip_fib_net_exit cleans up tables, by walking
through the whole hashtable of fib6_table's. We can get rid of the
special cases for local and main, since they're also part of the
hashtable.
Reproducer:
ip netns add x
ip -net x -6 rule add from 6003:1::/64 table 100
ip netns del x
Reported-by: Jianlin Shi <jishi@redhat.com>
Fixes: 58f09b78b730 ("[NETNS][IPV6] ip6_fib - make it per network namespace")
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
[bwh: Backported to 3.2:
- No need to call inetpeer_invalidate_tree()
- Add the extra iterator variable needed by hlist_for_each_entry_safe()]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Diffstat (limited to 'net/ipv6')
-rw-r--r-- | net/ipv6/ip6_fib.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c index 8b1f0f9c1252..10135b1b01d7 100644 --- a/net/ipv6/ip6_fib.c +++ b/net/ipv6/ip6_fib.c @@ -1577,13 +1577,22 @@ out_timer: static void fib6_net_exit(struct net *net) { + unsigned int i; + rt6_ifdown(net, NULL); del_timer_sync(&net->ipv6.ip6_fib_timer); -#ifdef CONFIG_IPV6_MULTIPLE_TABLES - kfree(net->ipv6.fib6_local_tbl); -#endif - kfree(net->ipv6.fib6_main_tbl); + for (i = 0; i < FIB_TABLE_HASHSZ; i++) { + struct hlist_head *head = &net->ipv6.fib_table_hash[i]; + struct hlist_node *node, *tmp; + struct fib6_table *tb; + + hlist_for_each_entry_safe(tb, node, tmp, head, tb6_hlist) { + hlist_del(&tb->tb6_hlist); + kfree(tb); + } + } + kfree(net->ipv6.fib_table_hash); kfree(net->ipv6.rt6_stats); } |