All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] devpts: Add ptmx_uid and ptmx_gid options
@ 2015-02-21  1:04 ` Andy Lutomirski
  0 siblings, 0 replies; 68+ messages in thread
From: Andy Lutomirski @ 2015-02-21  1:04 UTC (permalink / raw)
  To: Eric W. Biederman, linux-fsdevel-u79uwXL29TY76Z2rM5mHXA
  Cc: gnome-os-list-rDKQcyrBJuzYtjvyW6yDsg, Linux Containers,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, Andy Lutomirski,
	mclasen-H+wXaHxf7aLQT0dZR+AlfA

It's currently impossible to mount devpts in a user namespace that
has no root user, since ptmx can't be created.  This adds options
ptmx_uid and ptmx_gid that override the default uid and gid of 0.

These options are not shown in mountinfo because they have no effect
other than changing the initial mode of ptmx, and, in particular, it
wouldn't make any sense to change them on remount.  Instead, we
disallow them on remount.

This could be changed, but we'd probably want to fix the userns
behavior of uid and gid at the same time if we did so.

Signed-off-by: Andy Lutomirski <luto-kltTT9wpgjJwATOyAt5JVQ@public.gmane.org>
---
 Documentation/filesystems/devpts.txt |  4 +++
 fs/devpts/inode.c                    | 58 ++++++++++++++++++++++++++----------
 2 files changed, 46 insertions(+), 16 deletions(-)

diff --git a/Documentation/filesystems/devpts.txt b/Documentation/filesystems/devpts.txt
index 68dffd87f9b7..7808e77d0d72 100644
--- a/Documentation/filesystems/devpts.txt
+++ b/Documentation/filesystems/devpts.txt
@@ -121,6 +121,10 @@ once), following user-space issues should be noted.
 
 	chmod 666 /dev/pts/ptmx
 
+   The ownership for /dev/pts/ptmx can be specified using the ptmxuid
+   and ptmxgid options.  Both default to zero, which, in user namespaces
+   that have no root user, will cause mounting to fail.
+
 7. A mount of devpts without the 'newinstance' option results in binding to
    initial kernel mount.  This behavior while preserving legacy semantics,
    does not provide strict isolation in a container environment. i.e by
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
index cfe8466f7fef..b60d1438c660 100644
--- a/fs/devpts/inode.c
+++ b/fs/devpts/inode.c
@@ -102,6 +102,8 @@ struct pts_mount_opts {
 	int setgid;
 	kuid_t   uid;
 	kgid_t   gid;
+	uid_t ptmx_uid;
+	gid_t ptmx_gid;
 	umode_t mode;
 	umode_t ptmxmode;
 	int newinstance;
@@ -109,8 +111,8 @@ struct pts_mount_opts {
 };
 
 enum {
-	Opt_uid, Opt_gid, Opt_mode, Opt_ptmxmode, Opt_newinstance,  Opt_max,
-	Opt_err
+	Opt_uid, Opt_gid, Opt_ptmx_uid, Opt_ptmx_gid, Opt_mode, Opt_ptmxmode,
+	Opt_newinstance,  Opt_max, Opt_err,
 };
 
 static const match_table_t tokens = {
@@ -118,6 +120,8 @@ static const match_table_t tokens = {
 	{Opt_gid, "gid=%u"},
 	{Opt_mode, "mode=%o"},
 #ifdef CONFIG_DEVPTS_MULTIPLE_INSTANCES
+	{Opt_ptmx_uid, "ptmxuid=%u"},
+	{Opt_ptmx_gid, "ptmxgid=%u"},
 	{Opt_ptmxmode, "ptmxmode=%o"},
 	{Opt_newinstance, "newinstance"},
 	{Opt_max, "max=%d"},
@@ -162,14 +166,17 @@ static int parse_mount_options(char *data, int op, struct pts_mount_opts *opts)
 	char *p;
 	kuid_t uid;
 	kgid_t gid;
-
-	opts->setuid  = 0;
-	opts->setgid  = 0;
-	opts->uid     = GLOBAL_ROOT_UID;
-	opts->gid     = GLOBAL_ROOT_GID;
-	opts->mode    = DEVPTS_DEFAULT_MODE;
+	bool setptmxid = false;
+
+	opts->setuid   = 0;
+	opts->setgid   = 0;
+	opts->uid      = GLOBAL_ROOT_UID;
+	opts->gid      = GLOBAL_ROOT_GID;
+	opts->ptmx_uid = 0;
+	opts->ptmx_gid = 0;
+	opts->mode     = DEVPTS_DEFAULT_MODE;
 	opts->ptmxmode = DEVPTS_DEFAULT_PTMX_MODE;
-	opts->max     = NR_UNIX98_PTY_MAX;
+	opts->max      = NR_UNIX98_PTY_MAX;
 
 	/* newinstance makes sense only on initial mount */
 	if (op == PARSE_MOUNT)
@@ -209,6 +216,22 @@ static int parse_mount_options(char *data, int op, struct pts_mount_opts *opts)
 			opts->mode = option & S_IALLUGO;
 			break;
 #ifdef CONFIG_DEVPTS_MULTIPLE_INSTANCES
+		case Opt_ptmx_uid:
+			if (match_int(&args[0], &option))
+				return -EINVAL;
+			if (op != PARSE_MOUNT)
+				return -EINVAL;
+			opts->ptmx_uid = option;
+			setptmxid = true;
+			break;
+		case Opt_ptmx_gid:
+			if (match_int(&args[0], &option))
+				return -EINVAL;
+			if (op != PARSE_MOUNT)
+				return -EINVAL;
+			opts->ptmx_gid = option;
+			setptmxid = true;
+			break;
 		case Opt_ptmxmode:
 			if (match_octal(&args[0], &option))
 				return -EINVAL;
@@ -232,6 +255,9 @@ static int parse_mount_options(char *data, int op, struct pts_mount_opts *opts)
 		}
 	}
 
+	if (setptmxid && !opts->newinstance)
+		return -EINVAL;
+
 	return 0;
 }
 
@@ -245,12 +271,12 @@ static int mknod_ptmx(struct super_block *sb)
 	struct dentry *root = sb->s_root;
 	struct pts_fs_info *fsi = DEVPTS_SB(sb);
 	struct pts_mount_opts *opts = &fsi->mount_opts;
-	kuid_t root_uid;
-	kgid_t root_gid;
+	kuid_t ptmx_uid;
+	kgid_t ptmx_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))
+	ptmx_uid = make_kuid(current_user_ns(), opts->ptmx_uid);
+	ptmx_gid = make_kgid(current_user_ns(), opts->ptmx_gid);
+	if (!uid_valid(ptmx_uid) || !gid_valid(ptmx_gid))
 		return -EINVAL;
 
 	mutex_lock(&root->d_inode->i_mutex);
@@ -282,8 +308,8 @@ static int mknod_ptmx(struct super_block *sb)
 
 	mode = S_IFCHR|opts->ptmxmode;
 	init_special_inode(inode, mode, MKDEV(TTYAUX_MAJOR, 2));
-	inode->i_uid = root_uid;
-	inode->i_gid = root_gid;
+	inode->i_uid = ptmx_uid;
+	inode->i_gid = ptmx_gid;
 
 	d_add(dentry, inode);
 
-- 
2.3.0

^ permalink raw reply related	[flat|nested] 68+ messages in thread

end of thread, other threads:[~2016-03-08 18:18 UTC | newest]

Thread overview: 68+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-21  1:04 [PATCH] devpts: Add ptmx_uid and ptmx_gid options Andy Lutomirski
2015-02-21  1:04 ` Andy Lutomirski
     [not found] ` <b321c0c2729d1c2a72aea319b077dce7afd79698.1424480579.git.luto-kltTT9wpgjJwATOyAt5JVQ@public.gmane.org>
2015-03-26 19:29   ` Andy Lutomirski
2015-03-26 19:29 ` Andy Lutomirski
     [not found]   ` <CALCETrVtGE8LdBCFTe1_cqpLf=SxPNX5iCe5wa-hZ0pe8ps_jA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-03-27  9:03     ` James Bottomley
2015-03-27  9:03       ` James Bottomley
2015-03-31  7:57       ` Alexander Larsson
     [not found]         ` <1427788642.4411.12.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-03-31 13:06           ` Andy Lutomirski
2015-03-31 13:06             ` Andy Lutomirski
2015-03-31 13:07           ` James Bottomley
2015-03-31 13:07             ` James Bottomley
     [not found]             ` <1427807248.2117.117.camel-d9PhHud1JfjCXq6kfMZ53/egYHeGw8Jk@public.gmane.org>
2015-03-31 13:11               ` Alexander Larsson
2015-03-31 13:12               ` Andy Lutomirski
2015-03-31 13:11             ` Alexander Larsson
2015-03-31 13:12             ` Andy Lutomirski
     [not found]               ` <CALCETrWKA4ZdHfdLuW0_W5xxJOSCJdt_fiRWs6vDk+8ZQ9n9iA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-03-31 13:23                 ` James Bottomley
2015-03-31 13:23                   ` James Bottomley
2015-03-31 13:44                   ` Andy Lutomirski
2015-03-31 13:55                     ` James Bottomley
2015-03-31 13:59                       ` Andy Lutomirski
     [not found]                         ` <CALCETrU1vKf3fXPt8nS-ABDgfp8NxrFjHwTc68rA0rtvg2Lufg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-03-31 14:08                           ` James Bottomley
2015-03-31 14:08                             ` James Bottomley
     [not found]                             ` <1427810886.2117.129.camel-d9PhHud1JfjCXq6kfMZ53/egYHeGw8Jk@public.gmane.org>
2015-03-31 14:17                               ` Alexander Larsson
2015-03-31 14:17                             ` Alexander Larsson
     [not found]                               ` <1427811444.4411.20.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-04-02 10:12                                 ` James Bottomley
2015-04-02 10:12                                   ` James Bottomley
     [not found]                                   ` <1427969525.3559.120.camel-d9PhHud1JfjCXq6kfMZ53/egYHeGw8Jk@public.gmane.org>
2015-04-02 14:06                                     ` Andy Lutomirski
2015-04-02 14:06                                       ` Andy Lutomirski
2015-04-02 14:29                                       ` Alexander Larsson
     [not found]                                         ` <1427984969.13651.11.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-04-02 14:33                                           ` Andy Lutomirski
2015-04-02 14:33                                             ` Andy Lutomirski
     [not found]                                             ` <CALCETrWYit+WiAM6DFm0enGeJN==uWNC63zXp_zRSsSJg2YGPg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-04-02 15:49                                               ` Serge Hallyn
2015-04-02 15:49                                                 ` Serge Hallyn
2015-04-02 18:27                                               ` Eric W. Biederman
2015-04-02 18:27                                                 ` Eric W. Biederman
     [not found]                                                 ` <87zj6qs7v8.fsf-JOvCrm2gF+uungPnsOpG7nhyD016LWXt@public.gmane.org>
2015-05-27 21:32                                                   ` Andy Lutomirski
2015-05-27 21:32                                                 ` Andy Lutomirski
     [not found]                                                   ` <CALCETrVGcCA2SMiDT8JN=AWiSFCXWSaMeKBQmkbKynKfiPJCwA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-05-28 16:44                                                     ` Eric W. Biederman
2015-05-28 16:44                                                       ` Eric W. Biederman
2015-05-28 17:01                                                       ` Alexander Larsson
     [not found]                                                         ` <1432832511.21304.6.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-05-28 17:14                                                           ` Eric W. Biederman
2015-05-28 17:14                                                             ` Eric W. Biederman
2015-05-28 17:35                                                             ` Alexander Larsson
     [not found]                                                             ` <87mw0omxp0.fsf-JOvCrm2gF+uungPnsOpG7nhyD016LWXt@public.gmane.org>
2015-05-28 17:35                                                               ` Alexander Larsson
2015-05-28 20:06                                                               ` Alexander Larsson
2015-05-28 20:06                                                             ` Alexander Larsson
2015-05-28 20:17                                                               ` Kenton Varda
     [not found]                                                                 ` <CAOP=4wggpXOC4qLWgNAdw7Ws4vtYR=hscNYzDCfby+-VUxhoQg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-05-28 21:50                                                                   ` Eric W. Biederman
2015-05-28 21:50                                                                     ` Eric W. Biederman
     [not found]                                                               ` <1432843577.9873.1.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-05-28 20:17                                                                 ` Kenton Varda
2015-05-28 17:30                                                           ` Andy Lutomirski
2015-05-28 17:30                                                         ` Andy Lutomirski
     [not found]                                                           ` <CALCETrUueGomqFG0DSpt5Ern-XW6DE+rAEkd=3Y2ekV+gOwLAA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-05-28 19:42                                                             ` Eric W. Biederman
2015-05-28 19:42                                                               ` Eric W. Biederman
     [not found]                                                               ` <87siagh4kh.fsf-JOvCrm2gF+uungPnsOpG7nhyD016LWXt@public.gmane.org>
2016-03-08  4:59                                                                 ` Andy Lutomirski
2016-03-08  4:59                                                                   ` Andy Lutomirski
     [not found]                                                                   ` <CALCETrXNyyG-LZ8ds5ALbWs_Tfonev4+Ci=XZwWFqsSeszes8g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-03-08  9:16                                                                     ` Alexander Larsson
2016-03-08  9:16                                                                   ` Alexander Larsson
     [not found]                                                                     ` <1457428591.27353.55.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-03-08 18:17                                                                       ` Andy Lutomirski
2016-03-08 18:17                                                                         ` Andy Lutomirski
     [not found]                                                       ` <87oal4odne.fsf-JOvCrm2gF+uungPnsOpG7nhyD016LWXt@public.gmane.org>
2015-05-28 17:01                                                         ` Alexander Larsson
     [not found]                                       ` <CALCETrWyUYgHY53O451AdJUs9Mcjsqmr4fUzoNmYsTP1HLq+VA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-04-02 14:29                                         ` Alexander Larsson
     [not found]                       ` <1427810118.2117.126.camel-d9PhHud1JfjCXq6kfMZ53/egYHeGw8Jk@public.gmane.org>
2015-03-31 13:59                         ` Andy Lutomirski
     [not found]                     ` <CALCETrW8v1NFa7fcJbyJKXk9Msudht5BJ7Zy1Rg7ZC_TS-2Y-Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-03-31 13:55                       ` James Bottomley
     [not found]                   ` <1427808184.2117.122.camel-d9PhHud1JfjCXq6kfMZ53/egYHeGw8Jk@public.gmane.org>
2015-03-31 13:44                     ` Andy Lutomirski
     [not found]       ` <1427447013.2250.9.camel-d9PhHud1JfjCXq6kfMZ53/egYHeGw8Jk@public.gmane.org>
2015-03-31  7:57         ` Alexander Larsson
2015-05-18 21:04     ` Alexander Larsson
2015-05-18 21:04       ` Alexander Larsson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.