diff options
author | Eric W. Biederman <ebiederm@xmission.com> | 2012-08-20 20:28:58 -0400 |
---|---|---|
committer | Eric W. Biederman <ebiederm@xmission.com> | 2013-01-27 01:22:21 -0500 |
commit | ec2aa8e8dd7d35524a68c89b9e7ceb07fb002561 (patch) | |
tree | e6dccae5db69231b9f7c4bd362bed2031de7516a /fs/devpts | |
parent | e11f0ae388f227d7ad03953e19034dec55286650 (diff) |
userns: Allow the userns root to mount of devpts
- The context in which devpts is mounted has no effect on the creation
of ptys as the /dev/ptmx interface has been used by unprivileged
users for many years.
- Only support unprivileged mounts in combination with the newinstance
option to ensure that mounting of /dev/pts in a user namespace will
not allow the options of an existing mount of devpts to be modified.
- Create /dev/pts/ptmx as the root user in the user namespace that
mounts devpts so that it's permissions to be changed.
Acked-by: Serge Hallyn <serge.hallyn@canonical.com>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Diffstat (limited to 'fs/devpts')
-rw-r--r-- | fs/devpts/inode.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c index 472e6befc54d..073d30b9d1ac 100644 --- a/fs/devpts/inode.c +++ b/fs/devpts/inode.c | |||
@@ -243,6 +243,13 @@ static int mknod_ptmx(struct super_block *sb) | |||
243 | struct dentry *root = sb->s_root; | 243 | struct dentry *root = sb->s_root; |
244 | struct pts_fs_info *fsi = DEVPTS_SB(sb); | 244 | struct pts_fs_info *fsi = DEVPTS_SB(sb); |
245 | struct pts_mount_opts *opts = &fsi->mount_opts; | 245 | struct pts_mount_opts *opts = &fsi->mount_opts; |
246 | kuid_t root_uid; | ||
247 | kgid_t root_gid; | ||
248 | |||
249 | root_uid = make_kuid(current_user_ns(), 0); | ||
250 | root_gid = make_kgid(current_user_ns(), 0); | ||
251 | if (!uid_valid(root_uid) || !gid_valid(root_gid)) | ||
252 | return -EINVAL; | ||
246 | 253 | ||
247 | mutex_lock(&root->d_inode->i_mutex); | 254 | mutex_lock(&root->d_inode->i_mutex); |
248 | 255 | ||
@@ -273,6 +280,8 @@ static int mknod_ptmx(struct super_block *sb) | |||
273 | 280 | ||
274 | mode = S_IFCHR|opts->ptmxmode; | 281 | mode = S_IFCHR|opts->ptmxmode; |
275 | init_special_inode(inode, mode, MKDEV(TTYAUX_MAJOR, 2)); | 282 | init_special_inode(inode, mode, MKDEV(TTYAUX_MAJOR, 2)); |
283 | inode->i_uid = root_uid; | ||
284 | inode->i_gid = root_gid; | ||
276 | 285 | ||
277 | d_add(dentry, inode); | 286 | d_add(dentry, inode); |
278 | 287 | ||
@@ -438,6 +447,12 @@ static struct dentry *devpts_mount(struct file_system_type *fs_type, | |||
438 | if (error) | 447 | if (error) |
439 | return ERR_PTR(error); | 448 | return ERR_PTR(error); |
440 | 449 | ||
450 | /* Require newinstance for all user namespace mounts to ensure | ||
451 | * the mount options are not changed. | ||
452 | */ | ||
453 | if ((current_user_ns() != &init_user_ns) && !opts.newinstance) | ||
454 | return ERR_PTR(-EINVAL); | ||
455 | |||
441 | if (opts.newinstance) | 456 | if (opts.newinstance) |
442 | s = sget(fs_type, NULL, set_anon_super, flags, NULL); | 457 | s = sget(fs_type, NULL, set_anon_super, flags, NULL); |
443 | else | 458 | else |
@@ -491,6 +506,9 @@ static struct file_system_type devpts_fs_type = { | |||
491 | .name = "devpts", | 506 | .name = "devpts", |
492 | .mount = devpts_mount, | 507 | .mount = devpts_mount, |
493 | .kill_sb = devpts_kill_sb, | 508 | .kill_sb = devpts_kill_sb, |
509 | #ifdef CONFIG_DEVPTS_MULTIPLE_INSTANCES | ||
510 | .fs_flags = FS_USERNS_MOUNT | FS_USERNS_DEV_MOUNT, | ||
511 | #endif | ||
494 | }; | 512 | }; |
495 | 513 | ||
496 | /* | 514 | /* |