Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754753AbcLXMss (ORCPT ); Sat, 24 Dec 2016 07:48:48 -0500 Received: from mail-db5eur01on0109.outbound.protection.outlook.com ([104.47.2.109]:56029 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753619AbcLXMso (ORCPT ); Sat, 24 Dec 2016 07:48:44 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=avagin@virtuozzo.com; Date: Fri, 23 Dec 2016 17:16:14 -0800 From: Andrei Vagin To: "Michael Kerrisk (man-pages)" CC: "Eric W. Biederman" , "Serge E. Hallyn" , , , , Andrey Vagin , James Bottomley , "W. Trevor King" , Alexander Viro Subject: Re: [PATCH v2 2/2] nsfs: Add an ioctl() to return owner UID of a userns Message-ID: <20161224011614.GA31161@outlook.office365.com> References: <11b302a2-aac3-5994-a12d-e93ce64f7819@gmail.com> <44599777-c346-3b24-0181-6d86b20ab201@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="koi8-r" Content-Disposition: inline In-Reply-To: <44599777-c346-3b24-0181-6d86b20ab201@gmail.com> User-Agent: Mutt/1.7.1 (2016-10-04) X-Originating-IP: [67.183.159.197] X-ClientProxiedBy: CY1PR17CA0011.namprd17.prod.outlook.com (10.163.68.21) To VI1PR0801MB1982.eurprd08.prod.outlook.com (10.173.74.15) X-MS-Office365-Filtering-Correlation-Id: 937c19a3-85d2-44cf-582c-08d42b9a822c X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:VI1PR0801MB1982; X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB1982;3:4ykRDeKDbRRYtISh1xaBnIpXryHHjWzdzowPa/Kq1Ae6x38U0Rk68R8s5+/VYY/S+t2crW4x5TBln/Iq9Y5eO0PXpeknL8BJ7INi3PDnwFnphNJmuJ9YRJuoK+t7hf6eU9IpIoMyMG1Lp/1l1Qlme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nPM/1iHTUa28E5ACSyUNvtAzRdv0vVFyRd/uO87OmntWt5z/fiHg6XViVc7JlZ5o5WJmYfk4JKqzBu6aO2LDF5ufEe/F2k7BnJmmjXYN79DAgSyCnhP+JyorWqt7CiQwsG X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6041248)(20161123562025)(20161123560025)(20161123564025)(20161123555025)(6072148)(6042181);SRVR:VI1PR0801MB1982;BCL:0;PCL:0;RULEID:;SRVR:VI1PR0801MB1982; X-Microsoft-Exchange-Diagnostics: 1;VI1PR0801MB1982;4:neqoHqnEMeD8KuMrOA1NXEES6kwEfFtbrIiUVaf4EAN+KGcCas8Also8YZjNEHdHg+i51/pf/sOIVTCCbCWLCJdWW5eDCM6IHk0DeKW9cse0ikFvdysE9DLRuzL7QMxs+TgcoKMoqY83Mv7CgTGE1IHe/52HeFJkdtZ2mDLjkHJgEauL8AZmwFDVNkf0eye8pgP/mk48s7l/RzTk9NyhsE+UzqipX1E5GTXalTdxsrY+zaHrt8Zf+kPvJH112gruLUB3AoRwS3uTAES8tmH7NEoqKDLb7gk9Fs2q24NqP4f77HggNZ3JB2CxnqihEcqXjJPvTXXDPhc11rrRUbb4nKQUC/1ti7zXVTw1Qx8/vz7D7wiBG5zWPC/oMVaAEXLejjFE6qCFkpge6WyR1WCTVOQ00dTsPirXfF5/hk3xDyIt0PEoMfXaJiW28fYTSiogJCpEV35LoxB2jkBrcTsuahk5yZ5XU1BTfPma9Fgq1xAuzUH1L/ctEEe8nWjPJ3eQfRGv3ej6B5YGiqlNNYU3dJ/Qo+BiwMOeiyWEd1pLtXy1nrUWjz27TOIV+h2iEFBFLzm7ehpkONrNGEq43BHOpA== X-Forefront-PRVS: 0166B75B74 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(7916002)(199003)(189002)(24454002)(33656002)(7736002)(4001350100001)(69596002)(66066001)(25786008)(23686003)(305945005)(68736007)(9686002)(6916009)(76176999)(2950100002)(50986999)(5660300001)(42186005)(8676002)(6666003)(101416001)(81156014)(81166006)(4326007)(110136003)(6116002)(3846002)(53416004)(229853002)(1076002)(47776003)(50466002)(106356001)(105586002)(92566002)(189998001)(97736004)(6506006)(2906002)(83506001)(86362001)(38730400001)(39060400001)(54356999)(18370500001)(26326002);DIR:OUT;SFP:1102;SCL:1;SRVR:VI1PR0801MB1982;H:outlook.office365.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?koi8-r?Q?1;VI1PR0801MB1982;23:lR584doPvwWKmZD3lMCB5QdLaQaUoXTJIKLuakEcD?= =?koi8-r?Q?bLAdCcPIqSzED8rAAQOt1LBsrlZSXE0BN92/in/L8ReOTfGH4nPOWEDjTEkftR?= =?koi8-r?Q?59tum3poKi3A+ULShi46zV+152x9Z4j5/b09DcQ1ZcC6Bb8olCrYz8Jz/oK9xM?= =?koi8-r?Q?stLTsgYoHklhqdZ9kLBhq161nigY1/WhIbkcly0wCwgEwiP08jUq4wZjLEvg+i?= =?koi8-r?Q?mZ6hDD8U3cLhmtE4dJX5Po7RIuWF5KjS6jOiB9Xr6uuSnfMa19j7CcmIqnKbSD?= =?koi8-r?Q?JsmmpsHfxOxhk7L9dKkhAfev/wuNS1mJLXZHx1eh437TvvCFmY9AyzqmnaivQJ?= =?koi8-r?Q?NTV8yO2bVDk0tsNoWAgIL13GuV8sZh9U76WQUsIe9OZaS0JtSEmqbUuWBAehbi?= =?koi8-r?Q?EGv5EUCeObk5WPonz/3LoJlCgzCDmfbHHBnkRPbACXBD3evZP4AgIXgso0hsBk?= =?koi8-r?Q?ElubNBHfIYBkdsYmnT5p18AAEtQnYWUq6IoCpEcyrpG2V2Gqxg0byXmnoR4Ic2?= =?koi8-r?Q?zy5od0oBWaqP4ekQidrBi5X0kkOXGsK3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VvhdcENfT6KVgtQpuvljnuSfR3ZNiZkOhGsLX9MqmUnYGjJm4wkdDL5xNMWjnZydHACyI6KVabLHEOCJ68kl+XZXnxPLtnU3Q= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Dec 2016 01:16:34.4829 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB1982 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3297 Lines: 95 On Fri, Dec 23, 2016 at 10:54:53AM +0100, Michael Kerrisk (man-pages) wrote: > I'd like to write code that discovers the user namespace hierarchy on > a running system, and also shows who owns the various user namespaces. > Currently, there is no way of getting the owner UID of a user > namespace. Therefore, this patch adds an NS_GET_CREATOR_UID ioctl() > that fetches the (munged) UID of the creator of the user namespace > referred to by the specified file descriptor. > > If the supplied file descriptor does not refer to a user namespace, > the operation fails with the error EINVAL. > Acked-by: Andrey Vagin Here is one minor comment bellow > Signed-off-by: Michael Kerrisk > > --- > V2 changes: > * Renamed ioctl() from NS_CREATOR_UID to NS_OWNER_UID, at the > suggestion of Eric Biederman. > * Make ioctl() return UID via buffer pointed to by argp. (Returning > the UID via the result value could lead to problems since a large > unsigned int UID might be misinterpreted as an error.) Thanks to > Andrei Vagin for pointing this out. > --- > fs/nsfs.c | 11 +++++++++++ > include/uapi/linux/nsfs.h | 8 +++++--- > 2 files changed, 16 insertions(+), 3 deletions(-) > > diff --git a/fs/nsfs.c b/fs/nsfs.c > index 9f24b47..9c9277c 100644 > --- a/fs/nsfs.c > +++ b/fs/nsfs.c > @@ -7,6 +7,7 @@ > #include > #include > #include > +#include > > static struct vfsmount *nsfs_mnt; > > @@ -163,7 +164,10 @@ static int open_related_ns(struct ns_common *ns, > static long ns_ioctl(struct file *filp, unsigned int ioctl, > unsigned long arg) > { > + struct user_namespace *user_ns; > struct ns_common *ns = get_proc_ns(file_inode(filp)); > + unsigned int __user *argp; > + unsigned int uid; I think it is better to use uid_t here > > switch (ioctl) { > case NS_GET_USERNS: > @@ -174,6 +178,13 @@ static long ns_ioctl(struct file *filp, unsigned int ioctl, > return open_related_ns(ns, ns->ops->get_parent); > case NS_GET_NSTYPE: > return ns->ops->type; > + case NS_GET_OWNER_UID: > + if (ns->ops->type != CLONE_NEWUSER) > + return -EINVAL; > + user_ns = container_of(ns, struct user_namespace, ns); > + argp = (unsigned int __user *) arg; > + uid = from_kuid_munged(current_user_ns(), user_ns->owner); > + return put_user(uid, argp); > default: > return -ENOTTY; > } > diff --git a/include/uapi/linux/nsfs.h b/include/uapi/linux/nsfs.h > index 2b48df1..c4a925e 100644 > --- a/include/uapi/linux/nsfs.h > +++ b/include/uapi/linux/nsfs.h > @@ -6,11 +6,13 @@ > #define NSIO 0xb7 > > /* Returns a file descriptor that refers to an owning user namespace */ > -#define NS_GET_USERNS _IO(NSIO, 0x1) > +#define NS_GET_USERNS _IO(NSIO, 0x1) > /* Returns a file descriptor that refers to a parent namespace */ > -#define NS_GET_PARENT _IO(NSIO, 0x2) > +#define NS_GET_PARENT _IO(NSIO, 0x2) > /* Returns the type of namespace (CLONE_NEW* value) referred to by > file descriptor */ > -#define NS_GET_NSTYPE _IO(NSIO, 0x3) > +#define NS_GET_NSTYPE _IO(NSIO, 0x3) > +/* Get owner UID for a user namespace */ > +#define NS_GET_OWNER_UID _IO(NSIO, 0x4) > > #endif /* __LINUX_NSFS_H */ > -- > 2.5.5 >