From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753489AbcGUQwk (ORCPT ); Thu, 21 Jul 2016 12:52:40 -0400 Received: from out01.mta.xmission.com ([166.70.13.231]:49474 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753300AbcGUQwh (ORCPT ); Thu, 21 Jul 2016 12:52:37 -0400 From: ebiederm@xmission.com (Eric W. Biederman) To: Linux Containers Cc: Andy Lutomirski , Jann Horn , Kees Cook , Nikolay Borisov , "Serge E. Hallyn" , Seth Forshee , , , , References: <8737n5dscy.fsf@x220.int.ebiederm.org> Date: Thu, 21 Jul 2016 11:39:35 -0500 In-Reply-To: <8737n5dscy.fsf@x220.int.ebiederm.org> (Eric W. Biederman's message of "Tue, 19 Jul 2016 20:13:17 -0500") Message-ID: <87d1m754jc.fsf@x220.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1bQHD5-0000Hq-DQ;;;mid=<87d1m754jc.fsf@x220.int.ebiederm.org>;;;hst=in02.mta.xmission.com;;;ip=67.3.204.119;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX18jCrwrmR4kKtGSJOmqafRM590Ga3F6xTA= 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.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa01 1397; Body=1 Fuz1=1 Fuz2=1] X-Spam-DCC: XMission; sa01 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ;Linux Containers X-Spam-Relay-Country: X-Spam-Timing: total 581 ms - load_scoreonly_sql: 0.06 (0.0%), signal_user_changed: 3.9 (0.7%), b_tie_ro: 2.7 (0.5%), parse: 1.31 (0.2%), extract_message_metadata: 6 (1.0%), get_uri_detail_list: 3.1 (0.5%), tests_pri_-1000: 7 (1.1%), tests_pri_-950: 2.0 (0.3%), tests_pri_-900: 1.69 (0.3%), tests_pri_-400: 37 (6.3%), check_bayes: 35 (6.0%), b_tokenize: 13 (2.3%), b_tok_get_all: 9 (1.6%), b_comp_prob: 4.7 (0.8%), b_tok_touch_all: 3.2 (0.5%), b_finish: 0.89 (0.2%), tests_pri_0: 495 (85.1%), check_dkim_signature: 1.59 (0.3%), check_dkim_adsp: 5 (0.9%), tests_pri_500: 6 (1.0%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH v2 00/10] userns: sysctl limits for 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 This patchset addresses two use cases: - Implement a sane upper bound on the number of namespaces. - Provide a way for sandboxes to limit the attack surface from namespaces. The maximum sane case I can imagine is if every process is a fat process, so I set the maximum number of namespaces to the maximum number of threads. I make these limits recursive and per user namespace so that a usernamespace root can reduce the limits further. If a user namespace root raises the limit the limit in the parent namespace will be honored. I have cut this implementation to the bare minimum needed to achieve these objectives. Does anyone know if there is a proper error code to return for resource limit exceeded? I am currently using -EUSERS or -ENFILE but both of those feel a little wrong. Assuming nothing problematic shows up in the review I will add these to my user namespace tree. These patches are also available at: git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace.git for-testing Changes since v1: - Compilation issues with !CONFIG_SYSCTL and !CONFIG_USER_NS have been addressed - Comment improvements. - A few names have been changed to be clearer. Eric W. Biederman (10): sysctl: Stop implicitly passing current into sysctl_table_root.lookup userns: Add per user namespace sysctls. userns: Add a limit on the number of user namespaces userns: Generalize the user namespace count into ucount pidns: Add a limit on the number of pid namespaces utsns: Add a limit on the number of uts namespaces ipcns: Add a limit on the number of ipc namespaces cgroupns: Add a limit on the number of cgroup namespaces netns: Add a limit on the number of net namespaces mntns: Add a limit on the number of mount namespaces. fs/namespace.c | 19 ++++- fs/proc/proc_sysctl.c | 14 +-- include/linux/sysctl.h | 3 +- include/linux/user_namespace.h | 40 +++++++++ ipc/namespace.c | 42 ++++++--- kernel/cgroup.c | 15 ++++ kernel/fork.c | 5 ++ kernel/pid_namespace.c | 22 ++++- kernel/user_namespace.c | 188 ++++++++++++++++++++++++++++++++++++++--- kernel/utsname.c | 31 +++++-- net/core/net_namespace.c | 15 ++++ net/sysctl_net.c | 4 +- 12 files changed, 355 insertions(+), 43 deletions(-) Eric