From mboxrd@z Thu Jan 1 00:00:00 1970 From: Vasily Averin Subject: Re: [PATCH] ipv4: in new netns initialize sysctls in net.ipv4.conf.* with defaults Date: Sun, 21 Feb 2016 12:25:17 +0300 Message-ID: <56C9827D.3010103@virtuozzo.com> References: <20160221071102.9686.63148.stgit@buzz> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20160221071102.9686.63148.stgit@buzz> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: containers-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org Errors-To: containers-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org To: Konstantin Khlebnikov , netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, "David S. Miller" Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, "Eric W. Biederman" List-Id: containers.vger.kernel.org Konstantin, I've investigated question with sysctls initialization inside namespaces some time ago. IIRC I've found people expect that sysctl values should be inherited from parent namespace. It allows node admin to adjust unsafe pre-compiled settings, and prepare adequate defaults before creation of namespaces. However, there is corner case: module with sysctl can be loaded after creation of namespaces. In this case namespaces will get pre-compiled sysctl defaults, and are not be able to adjust them even if they want to do it. Thank you, Vasily Averin On 21.02.2016 10:11, Konstantin Khlebnikov wrote: > Currently initial net.ipv4.conf.all.* and net.ipv4.conf.default.* are > copied from init network namespace because static structures are used > for init_net. This makes no sense because new netns might be created > from any netns. This patch makes private copy also for init netns if > network namespaces are enabled. Other sysctls in net.ipv4 and net.ipv6 > already initialized with default values at namespace creation. > > Signed-off-by: Konstantin Khlebnikov > Fixes: 752d14dc6aa9 ("[IPV4]: Move the devinet pointers on the struct net") > --- > net/ipv4/devinet.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c > index cebd9d31e65a..9d73d4bbdba3 100644 > --- a/net/ipv4/devinet.c > +++ b/net/ipv4/devinet.c > @@ -2290,7 +2290,7 @@ static __net_init int devinet_init_net(struct net *net) > all = &ipv4_devconf; > dflt = &ipv4_devconf_dflt; > > - if (!net_eq(net, &init_net)) { > + if (IS_ENABLED(CONFIG_NET_NS)) { > all = kmemdup(all, sizeof(ipv4_devconf), GFP_KERNEL); > if (!all) > goto err_alloc_all; > > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753054AbcBURm7 (ORCPT ); Sun, 21 Feb 2016 12:42:59 -0500 Received: from mailhub.sw.ru ([195.214.232.25]:46883 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752757AbcBURlt (ORCPT ); Sun, 21 Feb 2016 12:41:49 -0500 Subject: Re: [PATCH] ipv4: in new netns initialize sysctls in net.ipv4.conf.* with defaults To: Konstantin Khlebnikov , netdev@vger.kernel.org, "David S. Miller" References: <20160221071102.9686.63148.stgit@buzz> Cc: containers@lists.linux-foundation.org, linux-kernel@vger.kernel.org, "Eric W. Biederman" From: Vasily Averin X-Enigmail-Draft-Status: N1110 Message-ID: <56C9827D.3010103@virtuozzo.com> Date: Sun, 21 Feb 2016 12:25:17 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <20160221071102.9686.63148.stgit@buzz> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Konstantin, I've investigated question with sysctls initialization inside namespaces some time ago. IIRC I've found people expect that sysctl values should be inherited from parent namespace. It allows node admin to adjust unsafe pre-compiled settings, and prepare adequate defaults before creation of namespaces. However, there is corner case: module with sysctl can be loaded after creation of namespaces. In this case namespaces will get pre-compiled sysctl defaults, and are not be able to adjust them even if they want to do it. Thank you, Vasily Averin On 21.02.2016 10:11, Konstantin Khlebnikov wrote: > Currently initial net.ipv4.conf.all.* and net.ipv4.conf.default.* are > copied from init network namespace because static structures are used > for init_net. This makes no sense because new netns might be created > from any netns. This patch makes private copy also for init netns if > network namespaces are enabled. Other sysctls in net.ipv4 and net.ipv6 > already initialized with default values at namespace creation. > > Signed-off-by: Konstantin Khlebnikov > Fixes: 752d14dc6aa9 ("[IPV4]: Move the devinet pointers on the struct net") > --- > net/ipv4/devinet.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c > index cebd9d31e65a..9d73d4bbdba3 100644 > --- a/net/ipv4/devinet.c > +++ b/net/ipv4/devinet.c > @@ -2290,7 +2290,7 @@ static __net_init int devinet_init_net(struct net *net) > all = &ipv4_devconf; > dflt = &ipv4_devconf_dflt; > > - if (!net_eq(net, &init_net)) { > + if (IS_ENABLED(CONFIG_NET_NS)) { > all = kmemdup(all, sizeof(ipv4_devconf), GFP_KERNEL); > if (!all) > goto err_alloc_all; > >