Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754009AbcLKWdp convert rfc822-to-8bit (ORCPT ); Sun, 11 Dec 2016 17:33:45 -0500 Received: from out02.mta.xmission.com ([166.70.13.232]:54336 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753887AbcLKWdn (ORCPT ); Sun, 11 Dec 2016 17:33:43 -0500 From: ebiederm@xmission.com (Eric W. Biederman) To: "Michael Kerrisk \(man-pages\)" Cc: Andrei Vagin , Containers , Linux API , lkml , "linux-fsdevel\@vger.kernel.org" , James Bottomley , "W. Trevor King" , Alexander Viro , Serge Hallyn References: Date: Mon, 12 Dec 2016 11:30:38 +1300 In-Reply-To: (Michael Kerrisk's message of "Sun, 11 Dec 2016 12:54:56 +0100") Message-ID: <87poky5ca9.fsf@xmission.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT X-XM-SPF: eid=1cGCge-00021A-2q;;;mid=<87poky5ca9.fsf@xmission.com>;;;hst=in02.mta.xmission.com;;;ip=101.100.131.98;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX18w02FMEQKR9wzbGrMlLMtzt/yha4/E3I0= X-SA-Exim-Connect-IP: 101.100.131.98 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 T_TM2_M_HEADER_IN_MSG BODY: No description available. * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * -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: ;"Michael Kerrisk \(man-pages\)" X-Spam-Relay-Country: X-Spam-Timing: total 287 ms - load_scoreonly_sql: 0.04 (0.0%), signal_user_changed: 7 (2.3%), b_tie_ro: 5 (1.8%), parse: 1.13 (0.4%), extract_message_metadata: 4.0 (1.4%), get_uri_detail_list: 1.66 (0.6%), tests_pri_-1000: 4.1 (1.4%), tests_pri_-950: 1.14 (0.4%), tests_pri_-900: 0.98 (0.3%), tests_pri_-400: 24 (8.3%), check_bayes: 23 (7.9%), b_tokenize: 7 (2.4%), b_tok_get_all: 8 (2.9%), b_comp_prob: 2.1 (0.7%), b_tok_touch_all: 3.0 (1.1%), b_finish: 0.71 (0.2%), tests_pri_0: 231 (80.5%), check_dkim_signature: 0.49 (0.2%), check_dkim_adsp: 3.0 (1.0%), tests_pri_500: 4.4 (1.5%), rewrite_mail: 0.00 (0.0%) Subject: Re: Documenting the ioctl interfaces to discover relationships between 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 Content-Length: 2572 Lines: 62 "Michael Kerrisk (man-pages)" writes: > [was: [PATCH 0/4 v3] Add an interface to discover relationships > between namespaces] One small comment below. > > Introspecting namespace relationships > Since Linux 4.9, two ioctl(2) operations are provided to allow > introspection of namespace relationships (see user_namespaces(7) > and pid_namespaces(7)). The form of the calls is: > > ioctl(fd, request); > > In each case, fd refers to a /proc/[pid]/ns/* file. > > NS_GET_USERNS > Returns a file descriptor that refers to the owning user > namespace for the namespace referred to by fd. > > NS_GET_PARENT > Returns a file descriptor that refers to the parent names‐ > pace of the namespace referred to by fd. This operation is > valid only for hierarchical namespaces (i.e., PID and user > namespaces). For user namespaces, NS_GET_PARENT is synony‐ > mous with NS_GET_USERNS. > > In each case, the returned file descriptor is opened with O_RDONLY > and O_CLOEXEC (close-on-exec). > > By applying fstat(2) to the returned file descriptor, one obtains > a stat structure whose st_ino (inode number) field identifies the > owning/parent namespace. This inode number can be matched with > the inode number of another /proc/[pid]/ns/{pid,user} file to > determine whether that is the owning/parent namespace. Like all fstat inode comparisons to be fully accurate you need to compare both the st_ino and st_dev. I reserve the right for st_dev to be significant when comparing namespaces. Otherwise I might have to create a namespace of namespaces someday and that is ugly. > Either of these ioctl(2) operations can fail with the following > error: > > EPERM The requested namespace is outside of the caller's names‐ > pace scope. This error can occur if, for example, the own‐ > ing user namespace is an ancestor of the caller's current > user namespace. It can also occur on attempts to obtain > the parent of the initial user or PID namespace. > > Additionally, the NS_GET_PARENT operation can fail with the fol‐ > lowing error: > > EINVAL fd refers to a nonhierarchical namespace. > > See the EXAMPLE section for an example of the use of these opera‐ > tions. > > [...] Eric