From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Serge E. Hallyn" Subject: Re: [PATCH v2 05/10] pidns: Add a limit on the number of pid namespaces Date: Mon, 25 Jul 2016 18:09:11 -0500 Message-ID: <20160725230911.GC26841@mail.hallyn.com> References: <87d1m754jc.fsf@x220.int.ebiederm.org> <20160721164014.17534-1-ebiederm@xmission.com> <20160721164014.17534-5-ebiederm@xmission.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <20160721164014.17534-5-ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org> 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: "Eric W. Biederman" Cc: Kees Cook , netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Linux Containers , linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Andy Lutomirski , Seth Forshee , Nikolay Borisov , linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Jann Horn List-Id: containers.vger.kernel.org Quoting Eric W. Biederman (ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org): > Signed-off-by: "Eric W. Biederman" Acked-by: Serge Hallyn > --- > include/linux/user_namespace.h | 1 + > kernel/pid_namespace.c | 22 ++++++++++++++++++---- > kernel/user_namespace.c | 1 + > 3 files changed, 20 insertions(+), 4 deletions(-) > > diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h > index f74a0facc696..47733637741a 100644 > --- a/include/linux/user_namespace.h > +++ b/include/linux/user_namespace.h > @@ -24,6 +24,7 @@ struct uid_gid_map { /* 64 bytes -- 1 cache line */ > > enum ucounts { > UCOUNT_USER_NAMESPACES, > + UCOUNT_PID_NAMESPACES, > UCOUNT_COUNTS, > }; > > diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c > index a65ba137fd15..049cc14ae37a 100644 > --- a/kernel/pid_namespace.c > +++ b/kernel/pid_namespace.c > @@ -79,6 +79,16 @@ static void proc_cleanup_work(struct work_struct *work) > /* MAX_PID_NS_LEVEL is needed for limiting size of 'struct pid' */ > #define MAX_PID_NS_LEVEL 32 > > +static bool inc_pid_namespaces(struct user_namespace *ns) > +{ > + return inc_ucount(ns, UCOUNT_PID_NAMESPACES); > +} > + > +static void dec_pid_namespaces(struct user_namespace *ns) > +{ > + dec_ucount(ns, UCOUNT_PID_NAMESPACES); > +} > + > static struct pid_namespace *create_pid_namespace(struct user_namespace *user_ns, > struct pid_namespace *parent_pid_ns) > { > @@ -87,15 +97,16 @@ static struct pid_namespace *create_pid_namespace(struct user_namespace *user_ns > int i; > int err; > > - if (level > MAX_PID_NS_LEVEL) { > - err = -EINVAL; > + err = -EINVAL; > + if (level > MAX_PID_NS_LEVEL) > + goto out; > + if (!inc_pid_namespaces(user_ns)) > goto out; > - } > > err = -ENOMEM; > ns = kmem_cache_zalloc(pid_ns_cachep, GFP_KERNEL); > if (ns == NULL) > - goto out; > + goto out_dec; > > ns->pidmap[0].page = kzalloc(PAGE_SIZE, GFP_KERNEL); > if (!ns->pidmap[0].page) > @@ -129,6 +140,8 @@ out_free_map: > kfree(ns->pidmap[0].page); > out_free: > kmem_cache_free(pid_ns_cachep, ns); > +out_dec: > + dec_pid_namespaces(user_ns); > out: > return ERR_PTR(err); > } > @@ -146,6 +159,7 @@ static void destroy_pid_namespace(struct pid_namespace *ns) > ns_free_inum(&ns->ns); > for (i = 0; i < PIDMAP_ENTRIES; i++) > kfree(ns->pidmap[i].page); > + dec_pid_namespaces(ns->user_ns); > put_user_ns(ns->user_ns); > call_rcu(&ns->rcu, delayed_free_pidns); > } > diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c > index 728d7e4995ff..02a03ead7afc 100644 > --- a/kernel/user_namespace.c > +++ b/kernel/user_namespace.c > @@ -77,6 +77,7 @@ static int count_max = COUNT_MAX; > } > static struct ctl_table userns_table[] = { > UCOUNT_ENTRY("max_user_namespaces"), > + UCOUNT_ENTRY("max_pid_namespaces"), > { } > }; > #endif /* CONFIG_SYSCTL */ > -- > 2.8.3 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753306AbcGYXJS (ORCPT ); Mon, 25 Jul 2016 19:09:18 -0400 Received: from h2.hallyn.com ([78.46.35.8]:54312 "EHLO h2.hallyn.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752915AbcGYXJN (ORCPT ); Mon, 25 Jul 2016 19:09:13 -0400 Date: Mon, 25 Jul 2016 18:09:11 -0500 From: "Serge E. Hallyn" To: "Eric W. Biederman" Cc: Linux Containers , Andy Lutomirski , Jann Horn , Kees Cook , Nikolay Borisov , "Serge E. Hallyn" , Seth Forshee , linux-fsdevel@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org Subject: Re: [PATCH v2 05/10] pidns: Add a limit on the number of pid namespaces Message-ID: <20160725230911.GC26841@mail.hallyn.com> References: <87d1m754jc.fsf@x220.int.ebiederm.org> <20160721164014.17534-1-ebiederm@xmission.com> <20160721164014.17534-5-ebiederm@xmission.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160721164014.17534-5-ebiederm@xmission.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Eric W. Biederman (ebiederm@xmission.com): > Signed-off-by: "Eric W. Biederman" Acked-by: Serge Hallyn > --- > include/linux/user_namespace.h | 1 + > kernel/pid_namespace.c | 22 ++++++++++++++++++---- > kernel/user_namespace.c | 1 + > 3 files changed, 20 insertions(+), 4 deletions(-) > > diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h > index f74a0facc696..47733637741a 100644 > --- a/include/linux/user_namespace.h > +++ b/include/linux/user_namespace.h > @@ -24,6 +24,7 @@ struct uid_gid_map { /* 64 bytes -- 1 cache line */ > > enum ucounts { > UCOUNT_USER_NAMESPACES, > + UCOUNT_PID_NAMESPACES, > UCOUNT_COUNTS, > }; > > diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c > index a65ba137fd15..049cc14ae37a 100644 > --- a/kernel/pid_namespace.c > +++ b/kernel/pid_namespace.c > @@ -79,6 +79,16 @@ static void proc_cleanup_work(struct work_struct *work) > /* MAX_PID_NS_LEVEL is needed for limiting size of 'struct pid' */ > #define MAX_PID_NS_LEVEL 32 > > +static bool inc_pid_namespaces(struct user_namespace *ns) > +{ > + return inc_ucount(ns, UCOUNT_PID_NAMESPACES); > +} > + > +static void dec_pid_namespaces(struct user_namespace *ns) > +{ > + dec_ucount(ns, UCOUNT_PID_NAMESPACES); > +} > + > static struct pid_namespace *create_pid_namespace(struct user_namespace *user_ns, > struct pid_namespace *parent_pid_ns) > { > @@ -87,15 +97,16 @@ static struct pid_namespace *create_pid_namespace(struct user_namespace *user_ns > int i; > int err; > > - if (level > MAX_PID_NS_LEVEL) { > - err = -EINVAL; > + err = -EINVAL; > + if (level > MAX_PID_NS_LEVEL) > + goto out; > + if (!inc_pid_namespaces(user_ns)) > goto out; > - } > > err = -ENOMEM; > ns = kmem_cache_zalloc(pid_ns_cachep, GFP_KERNEL); > if (ns == NULL) > - goto out; > + goto out_dec; > > ns->pidmap[0].page = kzalloc(PAGE_SIZE, GFP_KERNEL); > if (!ns->pidmap[0].page) > @@ -129,6 +140,8 @@ out_free_map: > kfree(ns->pidmap[0].page); > out_free: > kmem_cache_free(pid_ns_cachep, ns); > +out_dec: > + dec_pid_namespaces(user_ns); > out: > return ERR_PTR(err); > } > @@ -146,6 +159,7 @@ static void destroy_pid_namespace(struct pid_namespace *ns) > ns_free_inum(&ns->ns); > for (i = 0; i < PIDMAP_ENTRIES; i++) > kfree(ns->pidmap[i].page); > + dec_pid_namespaces(ns->user_ns); > put_user_ns(ns->user_ns); > call_rcu(&ns->rcu, delayed_free_pidns); > } > diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c > index 728d7e4995ff..02a03ead7afc 100644 > --- a/kernel/user_namespace.c > +++ b/kernel/user_namespace.c > @@ -77,6 +77,7 @@ static int count_max = COUNT_MAX; > } > static struct ctl_table userns_table[] = { > UCOUNT_ENTRY("max_user_namespaces"), > + UCOUNT_ENTRY("max_pid_namespaces"), > { } > }; > #endif /* CONFIG_SYSCTL */ > -- > 2.8.3