Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935875AbcLOM0u (ORCPT ); Thu, 15 Dec 2016 07:26:50 -0500 Received: from mail-db5eur01on0133.outbound.protection.outlook.com ([104.47.2.133]:47427 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751520AbcLOM0s (ORCPT ); Thu, 15 Dec 2016 07:26:48 -0500 X-Greylist: delayed 29053 seconds by postgrey-1.27 at vger.kernel.org; Thu, 15 Dec 2016 07:26:46 EST Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=avagin@virtuozzo.com; Date: Wed, 14 Dec 2016 16:46:37 -0800 From: Andrei Vagin To: "Michael Kerrisk (man-pages)" CC: Andrei Vagin , "Eric W. Biederman" , Containers , Linux API , lkml , "linux-fsdevel@vger.kernel.org" , "James Bottomley" , "W. Trevor King" , Alexander Viro , Serge Hallyn Subject: Re: Documenting the ioctl interfaces to discover relationships between namespaces Message-ID: <20161215004636.GB31670@outlook.office365.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.7.1 (2016-10-04) X-Originating-IP: [162.246.95.100] X-ClientProxiedBy: BN6PR03CA0014.namprd03.prod.outlook.com (10.168.230.152) To HE1PR0801MB1978.eurprd08.prod.outlook.com (10.168.94.148) X-MS-Office365-Filtering-Correlation-Id: 1804a072-1b04-4395-ecb8-08d42483dae5 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:HE1PR0801MB1978; X-Microsoft-Exchange-Diagnostics: 1;HE1PR0801MB1978;3:ncFiHs1YijZ8Jiq1cl1xHleJoFy2TiO9V4WYQ97kXTlAYUMzm71r/gMnLUF7IEqCd9cghWGtTcsBRgWY9rWmR+MpKLOTbf/nKH0mZzUcLliGzA++DUvMTJRYo9bBzoSbm/z1cBb9CyNuHqGaIRS3l4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VoUWxgK5asFyplVi8f0= X-Microsoft-Exchange-Diagnostics: 1;HE1PR0801MB1978;31:zi0AccQkRdK63QrCHhH7D3BZ8mmLu9bTBoi9+roBhFQFQiXMRs5BH9J/LRjGRxEn7QnuTBYOuCueq6z3Qsf7hWOhnYYV7CRctrfesT6ytk2P0cDlmSkxttewu7XUS4+dOqvK8CBQUj/MIBbmWMsFXQtJT9FEpG3Zc73f87UVfy9NdVL8r4kU6ymEog0u6kbO7hXHqfraiuEfwHbJB1qpQ8G2RnMGtqIFse4Y3hJbWM6sgT1mBfsMj8+nqZgBTV/S;20:oFZRigk/Xbi97r2t8rEwBLnbGOIbhWSQZgjeg/wq5fzsP80yQdIwO+NVXZTPlI3q0NY/UotAPCO6LFOKTN9WbATNS2SXQ73Ggex/j+hBhf1MryHQwEXUybitjP2f5uIPz7mc3PEIvwROBLDSTut6W0OKBxxzvMVXiutGrk18KnBFY0CaVo8iyOtEo0CmHj9o9QEsJvpkTxv9pO6+hGcamQ3Z1hE8YjNQCbBLPURaB8cNcVwOe9/eQMvxJxA7e4Qx X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6041248)(20161123562025)(20161123558021)(20161123560025)(20161123555025)(20161123564025)(6072148);SRVR:HE1PR0801MB1978;BCL:0;PCL:0;RULEID:;SRVR:HE1PR0801MB1978; X-Microsoft-Exchange-Diagnostics: 1;HE1PR0801MB1978;4:jwekOSLmkMd7tDB8gdGVneEWvo8mnIWiSOC5dac869+H6DwcHjcRVUCWzB3QDdvNhdIPa28WUJRev34aBgz4d9B3ZwUSkRG9APTmw8M1Y7O4p+yFMWACoj6TdFnNBUE6AeYMdZbVzpTy9SchafoWG6u2joGMcR4hO8OEAlKQ9fu1DD4adksyu21jR5wIaxb7l1K2JtZE8WWM6w//ojob5x3tKs9YmnFL3iH4Aeqa2p8zyyyYWeYE5Gm6KnM4ZmyLTS61fUXN4UdX0zIK7WlEMlqyi8me88pjRRhrSFkupAZ0EaSEjmvdM4cbQIG2nZfYWv7JXwB0D5TB47KS+lRpP15yVl6egju017lNdzKHbHnMgJro6KIaP0rnX0uZu4jbZ4drAwMSh5oJURFOiXJTsJ0V4mWiUPeKSiSDU6h5nul3RNKbamQiBfBBFOcFcOroIEpZyW6cGqDVF14roLDrlYK5MfzzmRW6RG/TS779q9q8oEMD7+DQ5AUCsaxZpxSPtds6Chn/tc9envrbWeDYhghhFZ2JasZv1a+jqCBAJHyh8DxQ+ErXALnPmJynuqa7pLGyV3yD6Id54WBJGwUuy41THoInVTz4ELWXxZa1mS0= X-Forefront-PRVS: 0157DEB61B X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(7916002)(39450400003)(199003)(24454002)(189002)(23676002)(305945005)(8676002)(83506001)(9686002)(15395725005)(5660300001)(105586002)(229853002)(106356001)(42186005)(7736002)(33656002)(189998001)(53416004)(97736004)(4001350100001)(7416002)(50466002)(68736007)(47776003)(92566002)(50986999)(69596002)(25786008)(86362001)(3846002)(6506006)(6116002)(66066001)(101416001)(1076002)(2950100002)(38730400001)(2870700001)(81166006)(39060400001)(54356999)(81156014)(6916009)(76176999)(6666003)(4326007)(110136003)(2906002)(7099028)(18370500001);DIR:OUT;SFP:1102;SCL:1;SRVR:HE1PR0801MB1978;H:outlook.office365.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtIRTFQUjA4MDFNQjE5Nzg7MjM6Q1BwUjZVcXJFY1BsM1ErVHpUaUp2SE5z?= =?utf-8?B?allVemVQR2I3U0xud3Y2M1NZQmxYQUNUMjQ4YWpRS2Z1ZjY2aE1OSXF1TXlS?= =?utf-8?B?dHlqODhQSVQwVWpIS1JCTWhpSVR2WHJKNm1iQUY5eDFtbHZIQThWL1ZWcXhS?= =?utf-8?B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Ml2Dj4qHwGyR2fAmiqTzxt6wW29/YsaEQ+11l2lpTNqOk/bw/Jp/KwXw+fQ+4gYvrpfIKke08EMZgknp7pnFOf4KesaD7A65hxHnhqdml62yHebXamFjTJxO2a8Fg5qgFtbOX9qucP4A8eIvfgV1CeYjCh3IW8e04gEU= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Dec 2016 00:46:47.2368 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0801MB1978 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 10693 Lines: 286 On Sun, Dec 11, 2016 at 12:54:56PM +0100, Michael Kerrisk (man-pages) wrote: > [was: [PATCH 0/4 v3] Add an interface to discover relationships > between namespaces] > > Hello Andrei > > See below for my attempt to document the following. Hi Michael, Eric already did my work:). I have read this documentation and it looks good for me. I have nothing to add to Eric's comments. Thanks, Andrei > > On 6 September 2016 at 09:47, Andrei Vagin wrote: > > From: Andrey Vagin > > > > Each namespace has an owning user namespace and now there is not way > > to discover these relationships. > > > > Pid and user namepaces are hierarchical. There is no way to discover > > parent-child relationships too. > > > > Why we may want to know relationships between namespaces? > > > > One use would be visualization, in order to understand the running > > system. Another would be to answer the question: what capability does > > process X have to perform operations on a resource governed by namespace > > Y? > > > > One more use-case (which usually called abnormal) is checkpoint/restart. > > In CRIU we are going to dump and restore nested namespaces. > > > > There [1] was a discussion about which interface to choose to determing > > relationships between namespaces. > > > > Eric suggested to add two ioctl-s [2]: > >> Grumble, Grumble. I think this may actually a case for creating ioctls > >> for these two cases. Now that random nsfs file descriptors are bind > >> mountable the original reason for using proc files is not as pressing. > >> > >> One ioctl for the user namespace that owns a file descriptor. > >> One ioctl for the parent namespace of a namespace file descriptor. > > > > Here is an implementaions of these ioctl-s. > > > > $ man man7/namespaces.7 > > ... > > Since Linux 4.X, the following ioctl(2) calls are supported for > > namespace file descriptors. The correct syntax is: > > > > fd = ioctl(ns_fd, ioctl_type); > > > > where ioctl_type is one of the following: > > > > NS_GET_USERNS > > Returns a file descriptor that refers to an owning user names‐ > > pace. > > > > NS_GET_PARENT > > Returns a file descriptor that refers to a parent namespace. > > This ioctl(2) can be used for pid and user namespaces. For > > user namespaces, NS_GET_PARENT and NS_GET_USERNS have the same > > meaning. > > > > In addition to generic ioctl(2) errors, the following specific ones > > can occur: > > > > EINVAL NS_GET_PARENT was called for a nonhierarchical namespace. > > > > EPERM The requested namespace is outside of the current namespace > > scope. > > > > [1] https://lkml.org/lkml/2016/7/6/158 > > [2] https://lkml.org/lkml/2016/7/9/101 > > The following is the text I propose to add to the namespaces(7) page. > Could you please review and let me know of corrections and > improvements. > > Thanks, > > Michael > > > 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. > > 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. > > [...] > > EXAMPLE > The example shown below uses the ioctl(2) operations described > above to perform simple introspection of namespace relationships. > The following shell sessions show various examples of the use of > this program. > > Trying to get the parent of the initial user namespace fails, for > the reasons explained earlier: > > $ ./ns_introspect /proc/self/ns/user p > The parent namespace is outside your namespace scope > > Create a process running sleep(1) that resides in new user and UTS > namespaces, and show that new UTS namespace is associated with the > new user namespace: > > $ unshare -Uu sleep 1000 & > [1] 23235 > $ ./ns_introspect /proc/23235/ns/uts > Inode number of owning user namespace is: 4026532448 > $ readlink /proc/23235/ns/user > user:[4026532448] > > Then show that the parent of the new user namespace in the preced‐ > ing example is the initial user namespace: > > $ readlink /proc/self/ns/user > user:[4026531837] > $ ./ns_introspect /proc/23235/ns/user > Inode number of owning user namespace is: 4026531837 > > Start a shell in a new user namespace, and show that from within > this shell, the parent user namespace can't be discovered. Simi‐ > larly, the UTS namespace (which is associated with the initial > user namespace) can't be discovered. > > $ PS1="sh2$ " unshare -U bash > sh2$ ./ns_introspect /proc/self/ns/user p > The parent namespace is outside your namespace scope > sh2$ ./ns_introspect /proc/self/ns/uts u > The owning user namespace is outside your namespace scope > > Program source > > /* ns_introspect.c > > Licensed under GNU General Public License v2 or later > */ > #include > #include > #include > #include > #include > #include > #include > #include > > #ifndef NS_GET_USERNS > #define NSIO 0xb7 > #define NS_GET_USERNS _IO(NSIO, 0x1) > #define NS_GET_PARENT _IO(NSIO, 0x2) > #endif > > int > main(int argc, char *argv[]) > { > int fd, userns_fd, parent_fd; > struct stat sb; > > if (argc < 2) { > fprintf(stderr, "Usage: %s /proc/[pid]/ns/[file] [p|u]\n", > argv[0]); > fprintf(stderr, "\nDisplay the result of one or both " > "of NS_GET_USERNS (u) or NS_GET_PARENT (p)\n" > "for the specified /proc/[pid]/ns/[file]. If neither " > "'p' nor 'u' is specified,\n" > "NS_GET_USERNS is the default.\n"); > exit(EXIT_FAILURE); > } > > /* Obtain a file descriptor for the 'ns' file specified > in argv[1] */ > > fd = open(argv[1], O_RDONLY); > if (fd == -1) { > perror("open"); > exit(EXIT_FAILURE); > } > > /* Obtain a file descriptor for the owning user namespace and > then obtain and display the inode number of that namespace */ > > if (argc < 3 || strchr(argv[2], 'u')) { > userns_fd = ioctl(fd, NS_GET_USERNS); > > if (userns_fd == -1) { > if (errno == EPERM) > printf("The owning user namespace is outside " > "your namespace scope\n"); > else > perror("ioctl-NS_GET_USERNS"); > exit(EXIT_FAILURE); > } > > if (fstat(userns_fd, &sb) == -1) { > perror("fstat-userns"); > exit(EXIT_FAILURE); > } > printf("Inode number of owning user namespace is: %ld\n", > (long) sb.st_ino); > > close(userns_fd); > } > > /* Obtain a file descriptor for the parent namespace and > then obtain and display the inode number of that namespace */ > > if (argc > 2 && strchr(argv[2], 'p')) { > parent_fd = ioctl(fd, NS_GET_PARENT); > > if (parent_fd == -1) { > if (errno == EINVAL) > printf("Can' get parent namespace of a " > "nonhierarchical namespace\n"); > else if (errno == EPERM) > printf("The parent namespace is outside " > "your namespace scope\n"); > else > perror("ioctl-NS_GET_PARENT"); > exit(EXIT_FAILURE); > } > > if (fstat(parent_fd, &sb) == -1) { > perror("fstat-parentns"); > exit(EXIT_FAILURE); > } > printf("Inode number of parent namespace is: %ld\n", > (long) sb.st_ino); > > close(parent_fd); > } > > exit(EXIT_SUCCESS); > } > > > -- > Michael Kerrisk > Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ > Linux/UNIX System Programming Training: http://man7.org/training/