diff options
| author | Eric W. Biederman <ebiederm@xmission.com> | 2016-09-14 14:53:38 -0400 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2016-09-23 05:31:31 -0400 |
| commit | e98d41370392dbc3e94c8802ce4e9eec9efdf92e (patch) | |
| tree | f3aeb2482e3a348fad2376a5f998b880956d9369 /fs/devpts | |
| parent | 6bd1d8758db278cb97989a0ebd85059fd948b73b (diff) | |
devpts: Change the owner of /dev/pts/ptmx to the mounter of /dev/pts
In 99.99% of the cases only root in a user namespace can mount /dev/pts
and in those cases the owner of /dev/pts/ptmx will remain root.root
In the oddball case where someone else has CAP_SYS_ADMIN this code
modifies the /dev/pts mount code to use current_fsuid and current_fsgid
as the values to use when creating the /dev/ptmx inode. As is done
when any other file is created.
This is a code simplification, and it allows running without a root
user entirely.
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/devpts')
| -rw-r--r-- | fs/devpts/inode.c | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c index 17593d3fcdbe..442d1a7e671b 100644 --- a/fs/devpts/inode.c +++ b/fs/devpts/inode.c | |||
| @@ -272,13 +272,8 @@ static int mknod_ptmx(struct super_block *sb) | |||
| 272 | struct dentry *root = sb->s_root; | 272 | struct dentry *root = sb->s_root; |
| 273 | struct pts_fs_info *fsi = DEVPTS_SB(sb); | 273 | struct pts_fs_info *fsi = DEVPTS_SB(sb); |
| 274 | struct pts_mount_opts *opts = &fsi->mount_opts; | 274 | struct pts_mount_opts *opts = &fsi->mount_opts; |
| 275 | kuid_t root_uid; | 275 | kuid_t ptmx_uid = current_fsuid(); |
| 276 | kgid_t root_gid; | 276 | kgid_t ptmx_gid = current_fsgid(); |
| 277 | |||
| 278 | root_uid = make_kuid(current_user_ns(), 0); | ||
| 279 | root_gid = make_kgid(current_user_ns(), 0); | ||
| 280 | if (!uid_valid(root_uid) || !gid_valid(root_gid)) | ||
| 281 | return -EINVAL; | ||
| 282 | 277 | ||
| 283 | inode_lock(d_inode(root)); | 278 | inode_lock(d_inode(root)); |
| 284 | 279 | ||
| @@ -309,8 +304,8 @@ static int mknod_ptmx(struct super_block *sb) | |||
| 309 | 304 | ||
| 310 | mode = S_IFCHR|opts->ptmxmode; | 305 | mode = S_IFCHR|opts->ptmxmode; |
| 311 | init_special_inode(inode, mode, MKDEV(TTYAUX_MAJOR, 2)); | 306 | init_special_inode(inode, mode, MKDEV(TTYAUX_MAJOR, 2)); |
| 312 | inode->i_uid = root_uid; | 307 | inode->i_uid = ptmx_uid; |
| 313 | inode->i_gid = root_gid; | 308 | inode->i_gid = ptmx_gid; |
| 314 | 309 | ||
| 315 | d_add(dentry, inode); | 310 | d_add(dentry, inode); |
| 316 | 311 | ||
