From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751895AbcGXFQ7 (ORCPT ); Sun, 24 Jul 2016 01:16:59 -0400 Received: from out03.mta.xmission.com ([166.70.13.233]:45215 "EHLO out03.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751011AbcGXFQ5 (ORCPT ); Sun, 24 Jul 2016 01:16:57 -0400 From: ebiederm@xmission.com (Eric W. Biederman) To: Andrey Vagin Cc: linux-kernel@vger.kernel.org, James Bottomley , Serge Hallyn , linux-api@vger.kernel.org, containers@lists.linux-foundation.org, Alexander Viro , criu@openvz.org, linux-fsdevel@vger.kernel.org, "Michael Kerrisk \(man-pages\)" References: <1468548742-32136-1-git-send-email-avagin@openvz.org> <1468548742-32136-2-git-send-email-avagin@openvz.org> Date: Sun, 24 Jul 2016 00:03:49 -0500 In-Reply-To: <1468548742-32136-2-git-send-email-avagin@openvz.org> (Andrey Vagin's message of "Thu, 14 Jul 2016 19:12:19 -0700") Message-ID: <878twrmxu2.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=1bRBmR-0001a3-FI;;;mid=<878twrmxu2.fsf@x220.int.ebiederm.org>;;;hst=in02.mta.xmission.com;;;ip=67.3.204.119;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1/TRCz9hlL3JEV9yKxzCkY2TwbUgkLCtkE= 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 * 1.5 XMNoVowels Alpha-numberic number with no vowels * 0.7 XMSubLong Long Subject * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.4884] * -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: **;Andrey Vagin X-Spam-Relay-Country: X-Spam-Timing: total 1251 ms - load_scoreonly_sql: 0.17 (0.0%), signal_user_changed: 5 (0.4%), b_tie_ro: 3.4 (0.3%), parse: 1.15 (0.1%), extract_message_metadata: 15 (1.2%), get_uri_detail_list: 1.85 (0.1%), tests_pri_-1000: 5 (0.4%), tests_pri_-950: 1.23 (0.1%), tests_pri_-900: 1.05 (0.1%), tests_pri_-400: 20 (1.6%), check_bayes: 19 (1.5%), b_tokenize: 5 (0.4%), b_tok_get_all: 6 (0.5%), b_comp_prob: 1.64 (0.1%), b_tok_touch_all: 3.1 (0.2%), b_finish: 0.77 (0.1%), tests_pri_0: 1191 (95.2%), check_dkim_signature: 0.55 (0.0%), check_dkim_adsp: 3.7 (0.3%), tests_pri_500: 7 (0.6%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH 2/5] kernel: add a helper to get an owning user namespace for a namespace 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 Andrey Vagin writes: > Return -EPERM if an owning user namespace is outside of a process > current user namespace. > > diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c > index a5bc78c..6382e5e 100644 > --- a/kernel/user_namespace.c > +++ b/kernel/user_namespace.c > @@ -994,6 +994,30 @@ static int userns_install(struct nsproxy *nsproxy, struct ns_common *ns) > return commit_creds(cred); > } > > +struct ns_common *ns_get_owner(struct ns_common *ns) > +{ > + const struct cred *cred = current_cred(); > + struct user_namespace *user_ns, *p; > + > + user_ns = p = ns->user_ns; > + if (user_ns == NULL) { /* ns is init_user_ns */ > + /* Unprivileged user should not know that it's init_user_ns. */ > + if (capable(CAP_SYS_ADMIN)) > + return ERR_PTR(-ENOENT); > + return ERR_PTR(-EPERM); > + } This permission check is not what I meant to request. This does not handle nested user namespaces. > + for (;;) { > + if (p == cred->user_ns) > + break; > + if (p == &init_user_ns) > + return ERR_PTR(-EPERM); > + p = p->parent; > + } > + The permission check really needs to be down here. And be: if (!ns_capable(user_ns, CAP_SYS_ADMIN)) return ERR_PTR(-EPERM). That cleanly and easily handles more than a depth of a single user namespace. > + return &get_user_ns(user_ns)->ns; > +} > + > const struct proc_ns_operations userns_operations = { > .name = "user", > .type = CLONE_NEWUSER, Eric