From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753827AbcGUQyU (ORCPT ); Thu, 21 Jul 2016 12:54:20 -0400 Received: from out01.mta.xmission.com ([166.70.13.231]:49838 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753775AbcGUQyO (ORCPT ); Thu, 21 Jul 2016 12:54:14 -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:14 -0500 Message-Id: <20160721164014.17534-10-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=1bQHEc-0000M2-PO;;;mid=<20160721164014.17534-10-ebiederm@xmission.com>;;;hst=in02.mta.xmission.com;;;ip=67.3.204.119;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX192G/slv1u9BGpbd/DksW86Oa4jCBGgXx4= 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 * [sa06 1397; Body=1 Fuz1=1] * 0.0 T_TooManySym_01 4+ unique symbols in subject X-Spam-DCC: XMission; sa06 1397; Body=1 Fuz1=1 X-Spam-Combo: ;Linux Containers X-Spam-Relay-Country: X-Spam-Timing: total 286 ms - load_scoreonly_sql: 0.03 (0.0%), signal_user_changed: 4.0 (1.4%), b_tie_ro: 3.1 (1.1%), parse: 0.67 (0.2%), extract_message_metadata: 12 (4.1%), get_uri_detail_list: 1.29 (0.4%), tests_pri_-1000: 6 (2.2%), tests_pri_-950: 1.23 (0.4%), tests_pri_-900: 1.04 (0.4%), tests_pri_-400: 22 (7.6%), check_bayes: 21 (7.2%), b_tokenize: 6 (2.0%), b_tok_get_all: 8 (2.7%), b_comp_prob: 1.37 (0.5%), b_tok_touch_all: 3.2 (1.1%), b_finish: 0.72 (0.3%), tests_pri_0: 234 (81.7%), check_dkim_signature: 0.70 (0.2%), check_dkim_adsp: 4.1 (1.4%), tests_pri_500: 3.2 (1.1%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH v2 10/10] mntns: Add a limit on the number of mount 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" --- fs/namespace.c | 19 ++++++++++++++++++- include/linux/user_namespace.h | 1 + kernel/user_namespace.c | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/fs/namespace.c b/fs/namespace.c index aabe8e397fc3..3942ae6c34f5 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -2718,9 +2718,20 @@ dput_out: return retval; } +static bool inc_mnt_namespaces(struct user_namespace *ns) +{ + return inc_ucount(ns, UCOUNT_MNT_NAMESPACES); +} + +static void dec_mnt_namespaces(struct user_namespace *ns) +{ + dec_ucount(ns, UCOUNT_MNT_NAMESPACES); +} + static void free_mnt_ns(struct mnt_namespace *ns) { ns_free_inum(&ns->ns); + dec_mnt_namespaces(ns->user_ns); put_user_ns(ns->user_ns); kfree(ns); } @@ -2739,12 +2750,18 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns) struct mnt_namespace *new_ns; int ret; + if (!inc_mnt_namespaces(user_ns)) + return ERR_PTR(-ENFILE); + new_ns = kmalloc(sizeof(struct mnt_namespace), GFP_KERNEL); - if (!new_ns) + if (!new_ns) { + dec_mnt_namespaces(user_ns); return ERR_PTR(-ENOMEM); + } ret = ns_alloc_inum(&new_ns->ns); if (ret) { kfree(new_ns); + dec_mnt_namespaces(user_ns); return ERR_PTR(ret); } new_ns->ns.ops = &mntns_operations; diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h index f86afa536baf..ee0e9d7b2e67 100644 --- a/include/linux/user_namespace.h +++ b/include/linux/user_namespace.h @@ -28,6 +28,7 @@ enum ucounts { UCOUNT_UTS_NAMESPACES, UCOUNT_IPC_NAMESPACES, UCOUNT_NET_NAMESPACES, + UCOUNT_MNT_NAMESPACES, UCOUNT_CGROUP_NAMESPACES, UCOUNT_COUNTS, }; diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c index e326ca722ae0..f6702d84afab 100644 --- a/kernel/user_namespace.c +++ b/kernel/user_namespace.c @@ -81,6 +81,7 @@ static struct ctl_table userns_table[] = { UCOUNT_ENTRY("max_uts_namespaces"), UCOUNT_ENTRY("max_ipc_namespaces"), UCOUNT_ENTRY("max_net_namespaces"), + UCOUNT_ENTRY("max_mnt_namespaces"), UCOUNT_ENTRY("max_cgroup_namespaces"), { } }; -- 2.8.3