From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753773AbcGUQyN (ORCPT ); Thu, 21 Jul 2016 12:54:13 -0400 Received: from out02.mta.xmission.com ([166.70.13.232]:37831 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753667AbcGUQyD (ORCPT ); Thu, 21 Jul 2016 12:54:03 -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:10 -0500 Message-Id: <20160721164014.17534-6-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=1bQHER-0000M2-G3;;;mid=<20160721164014.17534-6-ebiederm@xmission.com>;;;hst=in02.mta.xmission.com;;;ip=67.3.204.119;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1+YGBp4xtmlmbvgH6+3sne4u3zX6t1877Y= 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.0 TVD_RCVD_IP Message was received from an IP address * 0.7 XMSubLong Long Subject * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa03 1397; Body=1 Fuz1=1] X-Spam-DCC: XMission; sa03 1397; Body=1 Fuz1=1 X-Spam-Combo: ;Linux Containers X-Spam-Relay-Country: X-Spam-Timing: total 598 ms - load_scoreonly_sql: 0.05 (0.0%), signal_user_changed: 3.6 (0.6%), b_tie_ro: 2.5 (0.4%), parse: 1.36 (0.2%), extract_message_metadata: 27 (4.5%), get_uri_detail_list: 2.9 (0.5%), tests_pri_-1000: 10 (1.7%), tests_pri_-950: 2.0 (0.3%), tests_pri_-900: 1.63 (0.3%), tests_pri_-400: 32 (5.3%), check_bayes: 30 (5.0%), b_tokenize: 13 (2.2%), b_tok_get_all: 7 (1.2%), b_comp_prob: 3.3 (0.5%), b_tok_touch_all: 3.3 (0.6%), b_finish: 0.86 (0.1%), tests_pri_0: 509 (85.0%), check_dkim_signature: 0.83 (0.1%), check_dkim_adsp: 4.4 (0.7%), tests_pri_500: 6 (1.1%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH v2 06/10] utsns: Add a limit on the number of uts 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 + kernel/user_namespace.c | 1 + kernel/utsname.c | 31 ++++++++++++++++++++++++++----- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h index 47733637741a..bed2506081fe 100644 --- a/include/linux/user_namespace.h +++ b/include/linux/user_namespace.h @@ -25,6 +25,7 @@ struct uid_gid_map { /* 64 bytes -- 1 cache line */ enum ucounts { UCOUNT_USER_NAMESPACES, UCOUNT_PID_NAMESPACES, + UCOUNT_UTS_NAMESPACES, UCOUNT_COUNTS, }; diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c index 02a03ead7afc..6b205c24e888 100644 --- a/kernel/user_namespace.c +++ b/kernel/user_namespace.c @@ -78,6 +78,7 @@ static int count_max = COUNT_MAX; static struct ctl_table userns_table[] = { UCOUNT_ENTRY("max_user_namespaces"), UCOUNT_ENTRY("max_pid_namespaces"), + UCOUNT_ENTRY("max_uts_namespaces"), { } }; #endif /* CONFIG_SYSCTL */ diff --git a/kernel/utsname.c b/kernel/utsname.c index 831ea7108232..4f13c0419d64 100644 --- a/kernel/utsname.c +++ b/kernel/utsname.c @@ -17,6 +17,16 @@ #include #include +static bool inc_uts_namespaces(struct user_namespace *ns) +{ + return inc_ucount(ns, UCOUNT_UTS_NAMESPACES); +} + +static void dec_uts_namespaces(struct user_namespace *ns) +{ + dec_ucount(ns, UCOUNT_UTS_NAMESPACES); +} + static struct uts_namespace *create_uts_ns(void) { struct uts_namespace *uts_ns; @@ -38,15 +48,18 @@ static struct uts_namespace *clone_uts_ns(struct user_namespace *user_ns, struct uts_namespace *ns; int err; + err = -ENFILE; + if (!inc_uts_namespaces(user_ns)) + goto fail; + + err = -ENOMEM; ns = create_uts_ns(); if (!ns) - 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 = &utsns_operations; @@ -55,6 +68,13 @@ static struct uts_namespace *clone_uts_ns(struct user_namespace *user_ns, ns->user_ns = get_user_ns(user_ns); up_read(&uts_sem); return ns; + +fail_free: + kfree(ns); +fail_dec: + dec_uts_namespaces(user_ns); +fail: + return ERR_PTR(err); } /* @@ -85,6 +105,7 @@ void free_uts_ns(struct kref *kref) struct uts_namespace *ns; ns = container_of(kref, struct uts_namespace, kref); + dec_uts_namespaces(ns->user_ns); put_user_ns(ns->user_ns); ns_free_inum(&ns->ns); kfree(ns); -- 2.8.3