From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753534AbcGUQ4e (ORCPT ); Thu, 21 Jul 2016 12:56:34 -0400 Received: from out02.mta.xmission.com ([166.70.13.232]:37843 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753652AbcGUQyA (ORCPT ); Thu, 21 Jul 2016 12:54:00 -0400 From: "Eric W. Biederman" To: Linux Containers Cc: 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, "Eric W. Biederman" Date: Thu, 21 Jul 2016 11:40:11 -0500 Message-Id: <20160721164014.17534-7-ebiederm@xmission.com> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20160721164014.17534-1-ebiederm@xmission.com> References: <87d1m754jc.fsf@x220.int.ebiederm.org> <20160721164014.17534-1-ebiederm@xmission.com> X-XM-SPF: eid=1bQHEU-0000M2-Np;;;mid=<20160721164014.17534-7-ebiederm@xmission.com>;;;hst=in02.mta.xmission.com;;;ip=67.3.204.119;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1/yut5kAOPuhaxrq/i3ezruWnqRNQsHIOU= X-SA-Exim-Connect-IP: 67.3.204.119 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.7 XMSubLong Long Subject * 0.0 TVD_RCVD_IP Message was received from an IP address * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa04 1397; Body=1 Fuz1=1] X-Spam-DCC: XMission; sa04 1397; Body=1 Fuz1=1 X-Spam-Combo: ;Linux Containers X-Spam-Relay-Country: X-Spam-Timing: total 247 ms - load_scoreonly_sql: 0.06 (0.0%), signal_user_changed: 9 (3.8%), b_tie_ro: 7 (2.8%), parse: 1.37 (0.6%), extract_message_metadata: 14 (5.8%), get_uri_detail_list: 2.9 (1.2%), tests_pri_-1000: 4.8 (2.0%), tests_pri_-950: 0.96 (0.4%), tests_pri_-900: 0.77 (0.3%), tests_pri_-400: 18 (7.1%), check_bayes: 17 (6.8%), b_tokenize: 5 (2.2%), b_tok_get_all: 6 (2.4%), b_comp_prob: 1.22 (0.5%), b_tok_touch_all: 2.1 (0.9%), b_finish: 0.67 (0.3%), tests_pri_0: 192 (77.5%), check_dkim_signature: 0.41 (0.2%), check_dkim_adsp: 3.6 (1.5%), tests_pri_500: 3.1 (1.2%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH v2 07/10] ipcns: Add a limit on the number of ipc namespaces X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: "Eric W. Biederman" --- include/linux/user_namespace.h | 1 + ipc/namespace.c | 42 +++++++++++++++++++++++++++++++----------- kernel/user_namespace.c | 1 + 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h index bed2506081fe..367cf08ff63d 100644 --- a/include/linux/user_namespace.h +++ b/include/linux/user_namespace.h @@ -26,6 +26,7 @@ enum ucounts { UCOUNT_USER_NAMESPACES, UCOUNT_PID_NAMESPACES, UCOUNT_UTS_NAMESPACES, + UCOUNT_IPC_NAMESPACES, UCOUNT_COUNTS, }; diff --git a/ipc/namespace.c b/ipc/namespace.c index 04cb07eb81f1..3996a1e41a1d 100644 --- a/ipc/namespace.c +++ b/ipc/namespace.c @@ -16,33 +16,42 @@ #include "util.h" +static bool inc_ipc_namespaces(struct user_namespace *ns) +{ + return inc_ucount(ns, UCOUNT_IPC_NAMESPACES); +} + +static void dec_ipc_namespaces(struct user_namespace *ns) +{ + dec_ucount(ns, UCOUNT_IPC_NAMESPACES); +} + static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns, struct ipc_namespace *old_ns) { struct ipc_namespace *ns; int err; + err = -ENFILE; + if (!inc_ipc_namespaces(user_ns)) + goto fail; + + err = -ENOMEM; ns = kmalloc(sizeof(struct ipc_namespace), GFP_KERNEL); if (ns == NULL) - return ERR_PTR(-ENOMEM); + goto fail_dec; err = ns_alloc_inum(&ns->ns); - if (err) { - kfree(ns); - return ERR_PTR(err); - } + if (err) + goto fail_free; ns->ns.ops = &ipcns_operations; atomic_set(&ns->count, 1); ns->user_ns = get_user_ns(user_ns); err = mq_init_ns(ns); - if (err) { - put_user_ns(ns->user_ns); - ns_free_inum(&ns->ns); - kfree(ns); - return ERR_PTR(err); - } + if (err) + goto fail_put; atomic_inc(&nr_ipc_ns); sem_init_ns(ns); @@ -50,6 +59,16 @@ static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns, shm_init_ns(ns); return ns; + +fail_put: + put_user_ns(ns->user_ns); + ns_free_inum(&ns->ns); +fail_free: + kfree(ns); +fail_dec: + dec_ipc_namespaces(user_ns); +fail: + return ERR_PTR(err); } struct ipc_namespace *copy_ipcs(unsigned long flags, @@ -98,6 +117,7 @@ static void free_ipc_ns(struct ipc_namespace *ns) shm_exit_ns(ns); atomic_dec(&nr_ipc_ns); + dec_ipc_namespaces(ns->user_ns); put_user_ns(ns->user_ns); ns_free_inum(&ns->ns); kfree(ns); diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c index 6b205c24e888..060d3e099f87 100644 --- a/kernel/user_namespace.c +++ b/kernel/user_namespace.c @@ -79,6 +79,7 @@ static struct ctl_table userns_table[] = { UCOUNT_ENTRY("max_user_namespaces"), UCOUNT_ENTRY("max_pid_namespaces"), UCOUNT_ENTRY("max_uts_namespaces"), + UCOUNT_ENTRY("max_ipc_namespaces"), { } }; #endif /* CONFIG_SYSCTL */ -- 2.8.3