Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1546204
| Path | csiph.com!news.redatomik.org!aioe.org!bofh.it!news.nic.it!robomod |
|---|---|
| From | "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> |
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH 2/2] nsfs: Add an ioctl() to return creator UID of a userns |
| Date | Thu, 22 Dec 2016 08:20:02 +0100 |
| Message-ID | <sR5Ps-6eS-7@gated-at.bofh.it> (permalink) |
| References | <sQ7gC-Ek-11@gated-at.bofh.it> <sQ7gC-Ek-27@gated-at.bofh.it> <sR5Ps-6eS-9@gated-at.bofh.it> |
| X-Original-To | Andrei Vagin <avagin@virtuozzo.com> |
| Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=wXD15UuUM3yBWa5WJTBIqYchXt+qZfGXypdUJ9e1II0=; b=G8BrtasZjqjOf3rr5T4SwtEpiLtvJotEkf73PFrYiDR0YJKTqyStY3/vZeLgajP2QU SKTQLt8nUClFWxMjxTOMGJDRCltPh8Vjbnb/FRceYbqzvPx1ZG2egQmk9dNQaNI1n6K+ wY2Gatrx8Ub81IlpyoksGxYglG+31fL8tiWxC7qVUa/xdmCu4w2ml8++ycJ2z1y3z0E8 84P4gKX9QPEBMQ6k31Yc6kJUCcsne4TTtyACjOm/MtWy60ez4ELVTh6vE8TQOIa6q0tA UeCo5Q2wrkibO6XNf1W3rGBl+MR+Kn5OVxSAgt6l56jHFRYeOAa1wI7QpTo0V5uCml9n zg3w== |
| X-Google-Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=wXD15UuUM3yBWa5WJTBIqYchXt+qZfGXypdUJ9e1II0=; b=HVvJQok4JXbRdv/w1Wj/CHo1u4hTUSnrtmAZDoFIWjt4RLfW6ASTf7jQDMM0TtIl3a aAJ653aYpixtTRjIx+TnE/5x+SfgITuX6ON21nOc0g+Il6czEXPdcCR+30/cI0I818U7 zeaX3ChQHaIYJ3tU26VAijQIWvK9iZ9opLzkZErlS8HHwcm/j0xB1oU19NcKTwdIdTnE cF41U0EzAq/VMGErLiQPfhs1Hu6SN6qigOmqWhPNv9O0uhSKYVbflSpzVzv+E4FH33Ew x3upgR0vjdjOCCSmCRnNwcbXB321nUA0l9xtAIodkEq/CgAv6gpdcWhJJueSdzYKWSKK ALzw== |
| X-Gm-Message-State | AIkVDXID1gHm2UOJuy222moHLBymUfg1sJAG/KgS5sINqMSqcIJlOmVsZWcjNoluBNGNRA== |
| X-Received | by 10.28.5.193 with SMTP id 184mr10628202wmf.89.1482391029267; Wed, 21 Dec 2016 23:17:09 -0800 (PST) |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=koi8-r |
| Content-Transfer-Encoding | 7bit |
| Sender | robomod@news.nic.it |
| List-ID | <linux-kernel.vger.kernel.org> |
| X-Mailing-List | linux-kernel@vger.kernel.org |
| Approved | robomod@news.nic.it |
| Lines | 106 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | mtk.manpages@gmail.com, "Eric W. Biederman" <ebiederm@xmission.com>, "Serge E. Hallyn" <serge@hallyn.com>, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Andrey Vagin <avagin@openvz.org>, James Bottomley <James.Bottomley@hansenpartnership.com>, "W. Trevor King" <wking@tremily.us>, Alexander Viro <viro@zeniv.linux.org.uk>, Jonathan Corbet <corbet@lwn.net> |
| X-Original-Date | Thu, 22 Dec 2016 08:17:05 +0100 |
| X-Original-Message-ID | <f98ee21e-00f0-c4c8-1a4c-b1086a003633@gmail.com> |
| X-Original-References | <fdce894d-8385-b4b4-da3c-6282a7e4ecba@gmail.com> <46b85444-dc97-17a3-4445-439923936450@gmail.com> <20161221031315.GB20983@outlook.office365.com> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | csiph.com linux.kernel:1546204 |
Show key headers only | View raw
Hi Andrei,
On 12/21/2016 04:13 AM, Andrei Vagin wrote:
> On Mon, Dec 19, 2016 at 03:38:35PM +0100, Michael Kerrisk (man-pages) wrote:
>> # Some open questions about this patch below.
>> #
>> One of the rules regarding capabilities is:
>>
>> A process that resides in the parent of the user namespace and
>> whose effective user ID matches the owner of the namespace has
>> all capabilities in the namespace.
>>
>> Therefore, in order to write code that discovers whether process X has
>> capabilities in namespace Y, we need a way to find out who the creator
>> of a user namespace is. This patch adds an NS_GET_CREATOR_UID ioctl()
>> that returns 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.
>>
>> Signed-off-by: Michael Kerrisk <mtk-manpages@gmail.com>
>> ---
>> fs/nsfs.c | 6 ++++++
>> include/uapi/linux/nsfs.h | 8 +++++---
>> 2 files changed, 11 insertions(+), 3 deletions(-)
>>
>> Open questions:
>>
>> * Would it be preferabe to separate the logic for NS_GET_CREATOR_UID
>> into a small helper function?
>> * Is this a correct use of container_of()? I did not immediately
>> see another way to get to the user_namespace struct, but I
>> may well have missed something.
>>
>> diff --git a/fs/nsfs.c b/fs/nsfs.c
>> index 5d53476..26f6d94 100644
>> --- a/fs/nsfs.c
>> +++ b/fs/nsfs.c
>> @@ -163,6 +163,7 @@ 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));
>>
>> switch (ioctl) {
>> @@ -174,6 +175,11 @@ 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_CREATOR_UID:
>> + if (ns->ops->type != CLONE_NEWUSER)
>> + return -EINVAL;
>> + user_ns = container_of(ns, struct user_namespace, ns);
>> + return from_kuid_munged(current_user_ns(), user_ns->owner);
>
> uid_t is "unsigned int", ioctl() returns long, so it may be hard to
> distinguish user id-s from errors on x32.
Good point. So, we could instead return the UID via a buffer pointed to
by the ioctl() arg. That would seem better, right?
> off-topic: What is about user_ns->group? I can't find where it is used...
I've no idea. Like you, I can't see any place where it's being used.
Cheers,
Michael
>> default:
>> return -ENOTTY;
>> }
>> diff --git a/include/uapi/linux/nsfs.h b/include/uapi/linux/nsfs.h
>> index 2b48df1..b3c6c78 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 creator UID for a user namespace */
>> +#define NS_GET_CREATOR_UID _IO(NSIO, 0x4)
>>
>> #endif /* __LINUX_NSFS_H */
>> --
>> 2.5.5
>>
>
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 2/2] nsfs: Add an ioctl() to return creator UID of a userns "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> - 2016-12-19 15:40 +0100 Re: [PATCH 2/2] nsfs: Add an ioctl() to return creator UID of a userns "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> - 2016-12-22 08:20 +0100 Re: [PATCH 2/2] nsfs: Add an ioctl() to return creator UID of a userns ebiederm@xmission.com (Eric W. Biederman) - 2016-12-22 08:30 +0100
csiph-web