From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751952AbcGXFUe (ORCPT ); Sun, 24 Jul 2016 01:20:34 -0400 Received: from out01.mta.xmission.com ([166.70.13.231]:57968 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751011AbcGXFUc (ORCPT ); Sun, 24 Jul 2016 01:20:32 -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-4-git-send-email-avagin@openvz.org> Date: Sun, 24 Jul 2016 00:07:24 -0500 In-Reply-To: <1468548742-32136-4-git-send-email-avagin@openvz.org> (Andrey Vagin's message of "Thu, 14 Jul 2016 19:12:21 -0700") Message-ID: <87zip7lj3n.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=1bRBpt-0001x8-Rd;;;mid=<87zip7lj3n.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/OJ0Rkzd3ks0uF2RiFhmEHAee4gZm86cI= 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 * 1.5 XMNoVowels Alpha-numberic number with no vowels * 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.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.4902] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa07 1397; Body=1 Fuz1=1 Fuz2=1] X-Spam-DCC: XMission; sa07 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: *;Andrey Vagin X-Spam-Relay-Country: X-Spam-Timing: total 559 ms - load_scoreonly_sql: 0.05 (0.0%), signal_user_changed: 3.8 (0.7%), b_tie_ro: 2.8 (0.5%), parse: 0.73 (0.1%), extract_message_metadata: 12 (2.1%), get_uri_detail_list: 0.97 (0.2%), tests_pri_-1000: 4.8 (0.9%), tests_pri_-950: 1.17 (0.2%), tests_pri_-900: 1.01 (0.2%), tests_pri_-400: 18 (3.3%), check_bayes: 17 (3.1%), b_tokenize: 5 (0.9%), b_tok_get_all: 6 (1.0%), b_comp_prob: 1.38 (0.2%), b_tok_touch_all: 3.3 (0.6%), b_finish: 0.60 (0.1%), tests_pri_0: 184 (33.0%), check_dkim_signature: 0.52 (0.1%), check_dkim_adsp: 2.8 (0.5%), tests_pri_500: 330 (59.1%), poll_dns_idle: 324 (58.0%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH 4/5] nsfs: add ioctl to get a parent 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: > diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c > index 3529a03..a63adfb 100644 > --- a/kernel/pid_namespace.c > +++ b/kernel/pid_namespace.c > @@ -388,12 +388,38 @@ static int pidns_install(struct nsproxy *nsproxy, struct ns_common *ns) > return 0; > } > > +static struct ns_common *pidns_get_parent(struct ns_common *ns) > +{ > + struct pid_namespace *active = task_active_pid_ns(current); > + struct pid_namespace *pid_ns, *p; > + > + pid_ns = to_pid_ns(ns); > + if (pid_ns == &init_pid_ns) { > + if (capable(CAP_SYS_ADMIN)) > + return ERR_PTR(-ENOENT); > + return ERR_PTR(-EPERM); > + } > + > + pid_ns = p = pid_ns->parent; > + > + for (;;) { > + if (p == active) > + break; > + if (p == &init_pid_ns) > + return ERR_PTR(-EPERM); > + p = p->parent; > + } Similarly to the user namespace issue the permission check here needs to be: if (!ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN) return ERR_PTR(-EPERM); > + > + return &get_pid_ns(pid_ns)->ns; > +} > + > const struct proc_ns_operations pidns_operations = { > .name = "pid", > .type = CLONE_NEWPID, > .get = pidns_get, > .put = pidns_put, > .install = pidns_install, > + .get_parent = pidns_get_parent, > }; > Eric