* [PATCH] devpts: Make ptmx be owned by the userns owner instead of userns-local 0
@ 2016-03-14 5:06 Andy Lutomirski
[not found] ` <fd99f5e7144be5de87c88e069cd5edb36136eefd.1457931898.git.luto-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
[not found] ` <20160314083501.GB23225@ubuntumail>
0 siblings, 2 replies; 4+ messages in thread
From: Andy Lutomirski @ 2016-03-14 5:06 UTC (permalink / raw)
To: Linux FS Devel, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
Eric W. Biederman
Cc: gnome-os-list-rDKQcyrBJuzYtjvyW6yDsg, Linux Containers,
mclasen-H+wXaHxf7aLQT0dZR+AlfA, Andy Lutomirski
We used to have ptmx be owned by the inner uid and gid 0. Change
this: if the owner and group are both mapped but are not both 0,
then use the owner instead.
For container-style namespaces (LXC, etc), this should have no
effect -- UID 0 is will either be the owner or will be unmapped.
The important behavior change is for sandboxes: many sandboxes
intentionally do not create an inner uid 0. Without this patch,
mounting devpts in such a sandbox is awkward. With this patch, it
will just work and ptmx will be owned by the namespace owner.
Cc: Alexander Larsson <alexl-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Cc: mclasen-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
Cc: "Eric W. Biederman" <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
Cc: Linux Containers <containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>
Signed-off-by: Andy Lutomirski <luto-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
---
fs/devpts/inode.c | 34 ++++++++++++++++++++++++++++++----
1 file changed, 30 insertions(+), 4 deletions(-)
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
index 655f21f99160..d6fa2d1beee3 100644
--- a/fs/devpts/inode.c
+++ b/fs/devpts/inode.c
@@ -27,6 +27,7 @@
#include <linux/parser.h>
#include <linux/fsnotify.h>
#include <linux/seq_file.h>
+#include <linux/user_namespace.h>
#define DEVPTS_DEFAULT_MODE 0600
/*
@@ -250,10 +251,35 @@ static int mknod_ptmx(struct super_block *sb)
kuid_t root_uid;
kgid_t root_gid;
- root_uid = make_kuid(current_user_ns(), 0);
- root_gid = make_kgid(current_user_ns(), 0);
- if (!uid_valid(root_uid) || !gid_valid(root_gid))
- return -EINVAL;
+ /*
+ * For a new devpts instance, ptmx is owned by the creating user
+ * namespace's owner. Usually, that will be 0 as seen by the
+ * user namespace, but for unprivileged sandbox namespaces,
+ * there may not be a uid 0 or gid 0 at all.
+ */
+ root_uid = current_user_ns()->owner;
+ root_gid = current_user_ns()->group;
+
+ if (!uid_valid(root_uid) || !gid_valid(root_gid)) {
+ /*
+ * It's very unlikely for us to get here if the userns
+ * owner is not mapped, but it's possible -- we'd have
+ * to be running in the userns with capabilities granted
+ * by unshare or setns, since there is no inner
+ * privileged user. Nonetheless, this could happen, and
+ * we don't want ptmx to be owned by an unmapped user or
+ * group.
+ *
+ * If this happens fall back to historical behavior:
+ * try to have ptmx be owned by 0:0.
+ */
+ root_uid = make_kuid(current_user_ns(), 0);
+ root_gid = make_kgid(current_user_ns(), 0);
+
+ /* If this still doesn't work, give up. */
+ if (!uid_valid(root_uid) || !gid_valid(root_gid))
+ return -EINVAL;
+ }
inode_lock(d_inode(root));
--
2.5.0
^ permalink raw reply related [flat|nested] 4+ messages in thread[parent not found: <fd99f5e7144be5de87c88e069cd5edb36136eefd.1457931898.git.luto-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>]
* Re: [PATCH] devpts: Make ptmx be owned by the userns owner instead of userns-local 0 [not found] ` <fd99f5e7144be5de87c88e069cd5edb36136eefd.1457931898.git.luto-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> @ 2016-03-14 8:35 ` Serge Hallyn 2016-03-14 15:42 ` Alexander Larsson 1 sibling, 0 replies; 4+ messages in thread From: Serge Hallyn @ 2016-03-14 8:35 UTC (permalink / raw) To: Andy Lutomirski Cc: gnome-os-list-rDKQcyrBJuzYtjvyW6yDsg, Linux Containers, linux-kernel-u79uwXL29TY76Z2rM5mHXA, mclasen-H+wXaHxf7aLQT0dZR+AlfA, Eric W. Biederman, Linux FS Devel Quoting Andy Lutomirski (luto-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org): > We used to have ptmx be owned by the inner uid and gid 0. Change > this: if the owner and group are both mapped but are not both 0, > then use the owner instead. > > For container-style namespaces (LXC, etc), this should have no > effect -- UID 0 is will either be the owner or will be unmapped. This doesn't seem right - it's often the case that the owner is mapped in as non-0 uid, safe or not. The actual namespace root uid should be the owner (so long as it exists). Why not reverse the cases? If 0 is not mapped, then check whether the current_user_ns()->owner is mapped? > The important behavior change is for sandboxes: many sandboxes > intentionally do not create an inner uid 0. Without this patch, > mounting devpts in such a sandbox is awkward. With this patch, it > will just work and ptmx will be owned by the namespace owner. > > Cc: Alexander Larsson <alexl-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> > Cc: mclasen-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org > Cc: "Eric W. Biederman" <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org> > Cc: Linux Containers <containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org> > Signed-off-by: Andy Lutomirski <luto-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> > --- > fs/devpts/inode.c | 34 ++++++++++++++++++++++++++++++---- > 1 file changed, 30 insertions(+), 4 deletions(-) > > diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c > index 655f21f99160..d6fa2d1beee3 100644 > --- a/fs/devpts/inode.c > +++ b/fs/devpts/inode.c > @@ -27,6 +27,7 @@ > #include <linux/parser.h> > #include <linux/fsnotify.h> > #include <linux/seq_file.h> > +#include <linux/user_namespace.h> > > #define DEVPTS_DEFAULT_MODE 0600 > /* > @@ -250,10 +251,35 @@ static int mknod_ptmx(struct super_block *sb) > kuid_t root_uid; > kgid_t root_gid; > > - root_uid = make_kuid(current_user_ns(), 0); > - root_gid = make_kgid(current_user_ns(), 0); > - if (!uid_valid(root_uid) || !gid_valid(root_gid)) > - return -EINVAL; > + /* > + * For a new devpts instance, ptmx is owned by the creating user > + * namespace's owner. Usually, that will be 0 as seen by the > + * user namespace, but for unprivileged sandbox namespaces, > + * there may not be a uid 0 or gid 0 at all. > + */ > + root_uid = current_user_ns()->owner; > + root_gid = current_user_ns()->group; > + > + if (!uid_valid(root_uid) || !gid_valid(root_gid)) { > + /* > + * It's very unlikely for us to get here if the userns > + * owner is not mapped, but it's possible -- we'd have > + * to be running in the userns with capabilities granted > + * by unshare or setns, since there is no inner > + * privileged user. Nonetheless, this could happen, and > + * we don't want ptmx to be owned by an unmapped user or > + * group. > + * > + * If this happens fall back to historical behavior: > + * try to have ptmx be owned by 0:0. > + */ > + root_uid = make_kuid(current_user_ns(), 0); > + root_gid = make_kgid(current_user_ns(), 0); > + > + /* If this still doesn't work, give up. */ > + if (!uid_valid(root_uid) || !gid_valid(root_gid)) > + return -EINVAL; > + } > > inode_lock(d_inode(root)); > > -- > 2.5.0 > > _______________________________________________ > Containers mailing list > Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org > https://lists.linuxfoundation.org/mailman/listinfo/containers ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] devpts: Make ptmx be owned by the userns owner instead of userns-local 0 [not found] ` <fd99f5e7144be5de87c88e069cd5edb36136eefd.1457931898.git.luto-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> 2016-03-14 8:35 ` Serge Hallyn @ 2016-03-14 15:42 ` Alexander Larsson 1 sibling, 0 replies; 4+ messages in thread From: Alexander Larsson @ 2016-03-14 15:42 UTC (permalink / raw) To: Andy Lutomirski, Linux FS Devel, linux-kernel-u79uwXL29TY76Z2rM5mHXA, Eric W. Biederman Cc: Linux Containers, gnome-os-list-rDKQcyrBJuzYtjvyW6yDsg, mclasen-H+wXaHxf7aLQT0dZR+AlfA On sön, 2016-03-13 at 22:06 -0700, Andy Lutomirski wrote: > We used to have ptmx be owned by the inner uid and gid 0. Change > this: if the owner and group are both mapped but are not both 0, > then use the owner instead. > > For container-style namespaces (LXC, etc), this should have no > effect -- UID 0 is will either be the owner or will be unmapped. > > The important behavior change is for sandboxes: many sandboxes > intentionally do not create an inner uid 0. Without this patch, > mounting devpts in such a sandbox is awkward. With this patch, it > will just work and ptmx will be owned by the namespace owner. > > Cc: Alexander Larsson <alexl@redhat.com> > Cc: mclasen@redhat.com > Cc: "Eric W. Biederman" <ebiederm@xmission.com> > Cc: Linux Containers <containers@lists.linux-foundation.org> > Signed-off-by: Andy Lutomirski <luto@kernel.org> Tested-by: Alexander Larsson <alexl@redhat.com> Seems to work fine for me! Thanks! -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Alexander Larsson Red Hat, Inc alexl@redhat.com alexander.larsson@gmail.com He's an uncontrollable voodoo librarian with a robot buddy named Sparky. She's a cynical winged journalist from the wrong side of the tracks. They fight crime! _______________________________________________ Containers mailing list Containers@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/containers ^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <20160314083501.GB23225@ubuntumail>]
* Re: [PATCH] devpts: Make ptmx be owned by the userns owner instead of userns-local 0 [not found] ` <20160314083501.GB23225@ubuntumail> @ 2016-03-15 18:21 ` Andy Lutomirski 0 siblings, 0 replies; 4+ messages in thread From: Andy Lutomirski @ 2016-03-15 18:21 UTC (permalink / raw) To: Serge Hallyn Cc: gnome-os-list-rDKQcyrBJuzYtjvyW6yDsg, Linux Containers, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, mclasen-H+wXaHxf7aLQT0dZR+AlfA, Eric W. Biederman, Linux FS Devel On Mar 14, 2016 1:35 AM, "Serge Hallyn" <serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org> wrote: > > Quoting Andy Lutomirski (luto-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org): > > We used to have ptmx be owned by the inner uid and gid 0. Change > > this: if the owner and group are both mapped but are not both 0, > > then use the owner instead. > > > > For container-style namespaces (LXC, etc), this should have no > > effect -- UID 0 is will either be the owner or will be unmapped. > > This doesn't seem right - it's often the case that the owner is mapped > in as non-0 uid, safe or not. The actual namespace root uid should be > the owner (so long as it exists). > > Why not reverse the cases? If 0 is not mapped, then check whether the > current_user_ns()->owner is mapped? Good point, and less chance of breakage that way as well. --Andy ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-03-15 18:21 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-14 5:06 [PATCH] devpts: Make ptmx be owned by the userns owner instead of userns-local 0 Andy Lutomirski
[not found] ` <fd99f5e7144be5de87c88e069cd5edb36136eefd.1457931898.git.luto-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2016-03-14 8:35 ` Serge Hallyn
2016-03-14 15:42 ` Alexander Larsson
[not found] ` <20160314083501.GB23225@ubuntumail>
2016-03-15 18:21 ` Andy Lutomirski
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox