Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp4204736imm; Mon, 15 Oct 2018 10:44:01 -0700 (PDT) X-Google-Smtp-Source: ACcGV62bWXZ3EdW/pfAH5GhosV5vh45f4zNrOu0U+IL4XUA7Re8DbU5yqfiifNo7IpQBIcTpVKry X-Received: by 2002:a63:db55:: with SMTP id x21-v6mr16455752pgi.365.1539625441367; Mon, 15 Oct 2018 10:44:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539625441; cv=none; d=google.com; s=arc-20160816; b=0h6wXZXWGQ72LgrtIhJPxIk+mu97kKoFSTd//HqT5MHt63FD1kZMAooaTu13Ou9gt1 Ivgy1oNebyVKD/s8KhranwoOBa5jGuR3yjge26jCAF189y97x3XfyEVDzDmJaxUBnU1a prqAktBL+htDqrJEvWo3WWzC6gP4bA9lMenXDZXPckCxJJQMPuuN7rR1M/WzVZZO3sc/ Lxy318weJqkqATmBliaUhPFXIXEeRIekTLzVBxPHe9pMrgHv/J1KJQzdxAajKL1SwU6F GjBZ7QdhbP0tWHIJ7Q8oFM3YCFhvxatHy8sf6Chlt4w+uqbIDBTM9/86nrrSUGoH13dD Ojlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:mime-version:user-agent :message-id:in-reply-to:date:references:cc:to:from; bh=aJdZNQCVQ0+sPJXMEigxZFj+aIfbYZ+77PSU0KvDf8k=; b=rYh9uc9n5Ahfan2fYqNNjpMHDIvb+kg1qXdcTTWWS73MsFR911fVhPIf2SZAzGKKfc XSCWJzVnW473AypfnvOOZ6DVR2/y1YGbMkvDkac2z4wxYHWqCggrr7tk8lTn271xh388 dktmtvFqGnjwEqMbEhKSnvjY1OwR0ORKqhg6tVJzmt79F5gQMb7f88FLcnQeR4IKo2uD 4g+CY4n9Y4KVLgqdgUKuTKuj5LGk2N7eeg0+nFsK0tXWkptMp1vTB1s1CPkM9hUNtqvd 37HjlT4ZEdddeqL7dBS5437hFX4hP1K2q0ELuajf2BYNvtZz006TwNrWfK0vgq7c6E/+ 6qNw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a90-v6si6022089plc.88.2018.10.15.10.43.45; Mon, 15 Oct 2018 10:44:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726903AbeJPB3P (ORCPT + 99 others); Mon, 15 Oct 2018 21:29:15 -0400 Received: from out02.mta.xmission.com ([166.70.13.232]:37384 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726697AbeJPB3O (ORCPT ); Mon, 15 Oct 2018 21:29:14 -0400 Received: from in02.mta.xmission.com ([166.70.13.52]) by out02.mta.xmission.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.87) (envelope-from ) id 1gC6tP-0002HK-NM; Mon, 15 Oct 2018 11:42:59 -0600 Received: from 67-3-154-154.omah.qwest.net ([67.3.154.154] helo=x220.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.87) (envelope-from ) id 1gC6tO-0006KR-Sa; Mon, 15 Oct 2018 11:42:59 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: nagarathnam.muthusamy@oracle.com Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org, serge.hallyn@ubuntu.com, oleg@redhat.com, prakash.sangappa@oracle.com, khlebnikov@yandex-team.ru, luto@amacapital.net, jannh@google.com References: <1539623427-10789-1-git-send-email-nagarathnam.muthusamy@oracle.com> Date: Mon, 15 Oct 2018 12:42:44 -0500 In-Reply-To: <1539623427-10789-1-git-send-email-nagarathnam.muthusamy@oracle.com> (nagarathnam muthusamy's message of "Mon, 15 Oct 2018 11:10:27 -0600") Message-ID: <874ldnnm23.fsf@xmission.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1gC6tO-0006KR-Sa;;;mid=<874ldnnm23.fsf@xmission.com>;;;hst=in02.mta.xmission.com;;;ip=67.3.154.154;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX19b7oQjZYAa5xEASyK7ymh37aCcz5drflE= X-SA-Exim-Connect-IP: 67.3.154.154 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on sa06.xmission.com X-Spam-Level: X-Spam-Status: No, score=-0.2 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,TVD_RCVD_IP,T_TM2_M_HEADER_IN_MSG autolearn=disabled version=3.4.1 X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.4998] * 0.0 TVD_RCVD_IP Message was received from an IP address * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa06 1397; Body=1 Fuz1=1 Fuz2=1] X-Spam-DCC: XMission; sa06 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ;nagarathnam.muthusamy@oracle.com X-Spam-Relay-Country: X-Spam-Timing: total 432 ms - load_scoreonly_sql: 0.04 (0.0%), signal_user_changed: 4.7 (1.1%), b_tie_ro: 1.79 (0.4%), parse: 0.89 (0.2%), extract_message_metadata: 4.9 (1.1%), get_uri_detail_list: 3.2 (0.7%), tests_pri_-1000: 3.6 (0.8%), tests_pri_-950: 1.21 (0.3%), tests_pri_-900: 1.06 (0.2%), tests_pri_-400: 45 (10.5%), check_bayes: 39 (9.1%), b_tokenize: 16 (3.6%), b_tok_get_all: 11 (2.6%), b_comp_prob: 4.8 (1.1%), b_tok_touch_all: 4.2 (1.0%), b_finish: 0.80 (0.2%), tests_pri_0: 351 (81.3%), check_dkim_signature: 0.96 (0.2%), check_dkim_adsp: 3.9 (0.9%), tests_pri_10: 2.4 (0.5%), tests_pri_500: 9 (2.1%), rewrite_mail: 0.00 (0.0%) Subject: Re: [RFC] Allow user namespace inside chroot 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Have you considered using pivot_root to drop all of the pieces of the filesystem you don't want to be visible? That should be a much better solution overall. It is must a matter of: mount --bind /path/you/would/chroot/to pivot_root /path/you/would/chroot/to /put/old umount -l /put/old You might need to do something like make --rprivate before calling pivot_root to stop mount propagation to the parent. But I can't image it to be a practical problem. Also note that being in a chroot tends to indicate one of two things, being in an old build system, or being in some kind of chroot jail. Because of the jails created with chroot we want to be very careful with enabling user namespaces in that context. There have been some very clever people figuring out how to get out of chroot jails by passing file descriptors between processes and using things like pivot root. Even if your analysis is semantically perfect there is the issue of increasing the attack surface of preexising chroot jails. I believe that would make the kernel more vulnerable overall, and for only a very small simplification of implementation details. So unless I am missing something I don't see the use case for this that would not be better served by just properly setting up your mount namespace, and the attack surface increase of chroot jails makes we very relucatant to see a change like this. Eric nagarathnam.muthusamy@oracle.com writes: > From: Nagarathnam Muthusamy > > Following commit disables the creation of user namespace inside > the chroot environment. > > userns: Don't allow creation if the user is chrooted > > commit 3151527ee007b73a0ebd296010f1c0454a919c7d > > Consider a system in which a non-root user creates a combination > of user, pid and mount namespaces and confines a process to it. > The system will have multiple levels of nested namespaces. > The root namespace in the system will have lots of directories > which should not be exposed to the child confined to the set of > namespaces. > > Without chroot, we will have to hide all unwanted directories > individually using bind mounts and mount namespace. Chroot enables > us to expose a handpicked list of directories which the child > can see but if we use chroot we wont be able to create nested > namespaces. > > Allowing a process to create user namespace within a chroot > environment will enable it to chroot, which in turn can be used > to escape the jail. > > This patch drops the chroot privilege when user namespace is > created within the chroot environment so the process cannot > use it to escape the chroot jail. The process can still modify > the view of the file system using mount namespace but for those > modifications to be useful, it needs to run a setuid program with > that intented uid directly mapped into the user namespace as it is > which is not possible for an unprivileged process. > > If there were any other corner cases which were considered while > deciding to disable the creation of user namespace as a whole > within the chroot environment please let me know. > > Signed-off-by: Nagarathnam Muthusamy > --- > kernel/user_namespace.c | 22 +++++++++++++--------- > 1 file changed, 13 insertions(+), 9 deletions(-) > > diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c > index e5222b5..83d2a70 100644 > --- a/kernel/user_namespace.c > +++ b/kernel/user_namespace.c > @@ -44,7 +44,7 @@ static void dec_user_namespaces(struct ucounts *ucounts) > return dec_ucount(ucounts, UCOUNT_USER_NAMESPACES); > } > > -static void set_cred_user_ns(struct cred *cred, struct user_namespace *user_ns) > +static void set_cred_user_ns(struct cred *cred, struct user_namespace *user_ns, int is_chrooted) > { > /* Start with the same capabilities as init but useless for doing > * anything as the capabilities are bound to the new user namespace. > @@ -55,6 +55,11 @@ static void set_cred_user_ns(struct cred *cred, struct user_namespace *user_ns) > cred->cap_effective = CAP_FULL_SET; > cred->cap_ambient = CAP_EMPTY_SET; > cred->cap_bset = CAP_FULL_SET; > + if (is_chrooted) { > + cap_lower(cred->cap_permitted, CAP_SYS_CHROOT); > + cap_lower(cred->cap_effective, CAP_SYS_CHROOT); > + cap_lower(cred->cap_bset, CAP_SYS_CHROOT); > + } > #ifdef CONFIG_KEYS > key_put(cred->request_key_auth); > cred->request_key_auth = NULL; > @@ -78,6 +83,7 @@ int create_user_ns(struct cred *new) > kgid_t group = new->egid; > struct ucounts *ucounts; > int ret, i; > + int is_chrooted = 0; > > ret = -ENOSPC; > if (parent_ns->level > 32) > @@ -88,14 +94,12 @@ int create_user_ns(struct cred *new) > goto fail; > > /* > - * Verify that we can not violate the policy of which files > - * may be accessed that is specified by the root directory, > - * by verifing that the root directory is at the root of the > - * mount namespace which allows all files to be accessed. > + * Drop the chroot privilege when a user namespace is created inside > + * chrooted environment so that the file system view presented to a > + * non-admin process is preserved. > */ > - ret = -EPERM; > if (current_chrooted()) > - goto fail_dec; > + is_chrooted = 1; > > /* The creator needs a mapping in the parent user namespace > * or else we won't be able to reasonably tell userspace who > @@ -140,7 +144,7 @@ int create_user_ns(struct cred *new) > if (!setup_userns_sysctls(ns)) > goto fail_keyring; > > - set_cred_user_ns(new, ns); > + set_cred_user_ns(new, ns, is_chrooted); > return 0; > fail_keyring: > #ifdef CONFIG_PERSISTENT_KEYRINGS > @@ -1281,7 +1285,7 @@ static int userns_install(struct nsproxy *nsproxy, struct ns_common *ns) > return -ENOMEM; > > put_user_ns(cred->user_ns); > - set_cred_user_ns(cred, get_user_ns(user_ns)); > + set_cred_user_ns(cred, get_user_ns(user_ns), 0); > > return commit_creds(cred); > }