{"id":811381,"url":"http://patchwork.ozlabs.org/api/1.2/patches/811381/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/patch/204659713af1979c26b8defb2b52e1668b4e5aad.1504859062.git.sd@queasysnail.net/","project":{"id":7,"url":"http://patchwork.ozlabs.org/api/1.2/projects/7/?format=json","name":"Linux network development","link_name":"netdev","list_id":"netdev.vger.kernel.org","list_email":"netdev@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<204659713af1979c26b8defb2b52e1668b4e5aad.1504859062.git.sd@queasysnail.net>","list_archive_url":null,"date":"2017-09-08T08:26:19","name":"[net] ipv6: fix memory leak with multiple tables during netns destruction","commit_ref":null,"pull_url":null,"state":"accepted","archived":true,"hash":"2953ad88a2a8bae99359065a6f41641aec3fe154","submitter":{"id":47767,"url":"http://patchwork.ozlabs.org/api/1.2/people/47767/?format=json","name":"Sabrina Dubroca","email":"sd@queasysnail.net"},"delegate":{"id":34,"url":"http://patchwork.ozlabs.org/api/1.2/users/34/?format=json","username":"davem","first_name":"David","last_name":"Miller","email":"davem@davemloft.net"},"mbox":"http://patchwork.ozlabs.org/project/netdev/patch/204659713af1979c26b8defb2b52e1668b4e5aad.1504859062.git.sd@queasysnail.net/mbox/","series":[{"id":2130,"url":"http://patchwork.ozlabs.org/api/1.2/series/2130/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/list/?series=2130","date":"2017-09-08T08:26:19","name":"[net] ipv6: fix memory leak with multiple tables during netns destruction","version":1,"mbox":"http://patchwork.ozlabs.org/series/2130/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/811381/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/811381/checks/","tags":{},"related":[],"headers":{"Return-Path":"<netdev-owner@vger.kernel.org>","X-Original-To":"patchwork-incoming@ozlabs.org","Delivered-To":"patchwork-incoming@ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=netdev-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","ext-mx06.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none)\n\theader.from=queasysnail.net","ext-mx06.extmail.prod.ext.phx2.redhat.com;\n\tspf=none smtp.mailfrom=sd@queasysnail.net"],"Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xpVls5QKkz9s0Z\n\tfor <patchwork-incoming@ozlabs.org>;\n\tFri,  8 Sep 2017 18:26:33 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1756004AbdIHI03 (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tFri, 8 Sep 2017 04:26:29 -0400","from mx1.redhat.com ([209.132.183.28]:51284 \"EHLO mx1.redhat.com\"\n\trhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP\n\tid S1754657AbdIHI01 (ORCPT <rfc822;netdev@vger.kernel.org>);\n\tFri, 8 Sep 2017 04:26:27 -0400","from smtp.corp.redhat.com\n\t(int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id E8C4D285D0;\n\tFri,  8 Sep 2017 08:26:26 +0000 (UTC)","from localhost.localdomain (ovpn-116-179.ams2.redhat.com\n\t[10.36.116.179])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id 16EA56058F;\n\tFri,  8 Sep 2017 08:26:25 +0000 (UTC)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com E8C4D285D0","DKIM-Filter":"OpenDKIM Filter v2.11.0 mx1.redhat.com E8C4D285D0","From":"Sabrina Dubroca <sd@queasysnail.net>","To":"netdev@vger.kernel.org","Cc":"Sabrina Dubroca <sd@queasysnail.net>","Subject":"[PATCH net] ipv6: fix memory leak with multiple tables during netns\n\tdestruction","Date":"Fri,  8 Sep 2017 10:26:19 +0200","Message-Id":"<204659713af1979c26b8defb2b52e1668b4e5aad.1504859062.git.sd@queasysnail.net>","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.11","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.30]);\n\tFri, 08 Sep 2017 08:26:27 +0000 (UTC)","Sender":"netdev-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<netdev.vger.kernel.org>","X-Mailing-List":"netdev@vger.kernel.org"},"content":"fib6_net_exit only frees the main and local tables. If another table was\ncreated with fib6_alloc_table, we leak it when the netns is destroyed.\n\nFix this in the same way ip_fib_net_exit cleans up tables, by walking\nthrough the whole hashtable of fib6_table's. We can get rid of the\nspecial cases for local and main, since they're also part of the\nhashtable.\n\nReproducer:\n    ip netns add x\n    ip -net x -6 rule add from 6003:1::/64 table 100\n    ip netns del x\n\nReported-by: Jianlin Shi <jishi@redhat.com>\nFixes: 58f09b78b730 (\"[NETNS][IPV6] ip6_fib - make it per network namespace\")\nSigned-off-by: Sabrina Dubroca <sd@queasysnail.net>\n---\n net/ipv6/ip6_fib.c | 25 +++++++++++++++++++------\n 1 file changed, 19 insertions(+), 6 deletions(-)","diff":"diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c\nindex a3b5c163325f..8280172c806c 100644\n--- a/net/ipv6/ip6_fib.c\n+++ b/net/ipv6/ip6_fib.c\n@@ -191,6 +191,12 @@ void rt6_free_pcpu(struct rt6_info *non_pcpu_rt)\n }\n EXPORT_SYMBOL_GPL(rt6_free_pcpu);\n \n+static void fib6_free_table(struct fib6_table *table)\n+{\n+\tinetpeer_invalidate_tree(&table->tb6_peers);\n+\tkfree(table);\n+}\n+\n static void fib6_link_table(struct net *net, struct fib6_table *tb)\n {\n \tunsigned int h;\n@@ -2022,15 +2028,22 @@ static int __net_init fib6_net_init(struct net *net)\n \n static void fib6_net_exit(struct net *net)\n {\n+\tunsigned int i;\n+\n \trt6_ifdown(net, NULL);\n \tdel_timer_sync(&net->ipv6.ip6_fib_timer);\n \n-#ifdef CONFIG_IPV6_MULTIPLE_TABLES\n-\tinetpeer_invalidate_tree(&net->ipv6.fib6_local_tbl->tb6_peers);\n-\tkfree(net->ipv6.fib6_local_tbl);\n-#endif\n-\tinetpeer_invalidate_tree(&net->ipv6.fib6_main_tbl->tb6_peers);\n-\tkfree(net->ipv6.fib6_main_tbl);\n+\tfor (i = 0; i < FIB_TABLE_HASHSZ; i++) {\n+\t\tstruct hlist_head *head = &net->ipv6.fib_table_hash[i];\n+\t\tstruct hlist_node *tmp;\n+\t\tstruct fib6_table *tb;\n+\n+\t\thlist_for_each_entry_safe(tb, tmp, head, tb6_hlist) {\n+\t\t\thlist_del(&tb->tb6_hlist);\n+\t\t\tfib6_free_table(tb);\n+\t\t}\n+\t}\n+\n \tkfree(net->ipv6.fib_table_hash);\n \tkfree(net->ipv6.rt6_stats);\n \tfib6_notifier_exit(net);\n","prefixes":["net"]}