* [PATCH tty-next 2/6] devpts: Move the creation of /dev/pts/ptmx into fill_super
2016-09-14 18:53 ` [PATCH tty-next 1/6] devpts: Move parse_mount_options into fill_super Eric W. Biederman
@ 2016-09-14 18:53 ` Eric W. Biederman
2016-09-14 18:53 ` [PATCH tty-next 3/6] devpts: Simplify devpts_mount by using mount_nodev Eric W. Biederman
` (3 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Eric W. Biederman @ 2016-09-14 18:53 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby
Cc: H. Peter Anvin, linux-kernel, linux-fsdevel, Linux Containers,
Eric W. Biederman
The code makes more sense here and things are just clearer.
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
fs/devpts/inode.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
index c59d39f2d512..43773543a783 100644
--- a/fs/devpts/inode.c
+++ b/fs/devpts/inode.c
@@ -425,11 +425,19 @@ devpts_fill_super(struct super_block *s, void *data, int silent)
set_nlink(inode, 2);
s->s_root = d_make_root(inode);
- if (s->s_root)
- return 0;
+ if (!s->s_root) {
+ pr_err("get root dentry failed\n");
+ goto fail;
+ }
- pr_err("get root dentry failed\n");
+ error = mknod_ptmx(s);
+ if (error)
+ goto fail_dput;
+ return 0;
+fail_dput:
+ dput(s->s_root);
+ s->s_root = NULL;
fail:
return error;
}
@@ -456,11 +464,6 @@ static struct dentry *devpts_mount(struct file_system_type *fs_type,
goto out_undo_sget;
s->s_flags |= MS_ACTIVE;
}
-
- error = mknod_ptmx(s);
- if (error)
- goto out_undo_sget;
-
return dget(s->s_root);
out_undo_sget:
--
2.8.3
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH tty-next 3/6] devpts: Simplify devpts_mount by using mount_nodev
2016-09-14 18:53 ` [PATCH tty-next 1/6] devpts: Move parse_mount_options into fill_super Eric W. Biederman
2016-09-14 18:53 ` [PATCH tty-next 2/6] devpts: Move the creation of /dev/pts/ptmx " Eric W. Biederman
@ 2016-09-14 18:53 ` Eric W. Biederman
2016-09-14 18:53 ` [PATCH tty-next 4/6] devpts: Make devpts_kill_sb safe if fsi is NULL Eric W. Biederman
` (2 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Eric W. Biederman @ 2016-09-14 18:53 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby
Cc: H. Peter Anvin, linux-kernel, linux-fsdevel, Linux Containers,
Eric W. Biederman
Now that all of the work of setting up a superblock has been moved to
devpts_fill_super simplify devpts_mount by calling mount_nodev instead
of rolling mount_nodev by hand.
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
fs/devpts/inode.c | 19 +------------------
1 file changed, 1 insertion(+), 18 deletions(-)
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
index 43773543a783..a48b40b0bd1e 100644
--- a/fs/devpts/inode.c
+++ b/fs/devpts/inode.c
@@ -451,24 +451,7 @@ fail:
static struct dentry *devpts_mount(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
{
- int error;
- struct super_block *s;
-
- s = sget(fs_type, NULL, set_anon_super, flags, NULL);
- if (IS_ERR(s))
- return ERR_CAST(s);
-
- if (!s->s_root) {
- error = devpts_fill_super(s, data, flags & MS_SILENT ? 1 : 0);
- if (error)
- goto out_undo_sget;
- s->s_flags |= MS_ACTIVE;
- }
- return dget(s->s_root);
-
-out_undo_sget:
- deactivate_locked_super(s);
- return ERR_PTR(error);
+ return mount_nodev(fs_type, flags, data, devpts_fill_super);
}
static void devpts_kill_sb(struct super_block *sb)
--
2.8.3
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH tty-next 4/6] devpts: Make devpts_kill_sb safe if fsi is NULL
2016-09-14 18:53 ` [PATCH tty-next 1/6] devpts: Move parse_mount_options into fill_super Eric W. Biederman
2016-09-14 18:53 ` [PATCH tty-next 2/6] devpts: Move the creation of /dev/pts/ptmx " Eric W. Biederman
2016-09-14 18:53 ` [PATCH tty-next 3/6] devpts: Simplify devpts_mount by using mount_nodev Eric W. Biederman
@ 2016-09-14 18:53 ` Eric W. Biederman
2016-09-14 18:53 ` [PATCH tty-next 5/6] devpts: Remove sync_filesystems Eric W. Biederman
2016-09-14 18:53 ` [PATCH tty-next 6/6] devpts: Change the owner of /dev/pts/ptmx to the mounter of /dev/pts Eric W. Biederman
4 siblings, 0 replies; 9+ messages in thread
From: Eric W. Biederman @ 2016-09-14 18:53 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby
Cc: H. Peter Anvin, linux-kernel, linux-fsdevel, Linux Containers,
Eric W. Biederman
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
fs/devpts/inode.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
index a48b40b0bd1e..e058ec677207 100644
--- a/fs/devpts/inode.c
+++ b/fs/devpts/inode.c
@@ -458,7 +458,8 @@ static void devpts_kill_sb(struct super_block *sb)
{
struct pts_fs_info *fsi = DEVPTS_SB(sb);
- ida_destroy(&fsi->allocated_ptys);
+ if (fsi)
+ ida_destroy(&fsi->allocated_ptys);
kfree(fsi);
kill_litter_super(sb);
}
--
2.8.3
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH tty-next 5/6] devpts: Remove sync_filesystems
2016-09-14 18:53 ` [PATCH tty-next 1/6] devpts: Move parse_mount_options into fill_super Eric W. Biederman
` (2 preceding siblings ...)
2016-09-14 18:53 ` [PATCH tty-next 4/6] devpts: Make devpts_kill_sb safe if fsi is NULL Eric W. Biederman
@ 2016-09-14 18:53 ` Eric W. Biederman
2016-09-14 18:53 ` [PATCH tty-next 6/6] devpts: Change the owner of /dev/pts/ptmx to the mounter of /dev/pts Eric W. Biederman
4 siblings, 0 replies; 9+ messages in thread
From: Eric W. Biederman @ 2016-09-14 18:53 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby
Cc: H. Peter Anvin, linux-kernel, linux-fsdevel, Linux Containers,
Eric W. Biederman
devpts does not and never will have anything to sync
so don't bother calling sync_filesystems on remount.
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
fs/devpts/inode.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
index e058ec677207..17593d3fcdbe 100644
--- a/fs/devpts/inode.c
+++ b/fs/devpts/inode.c
@@ -336,7 +336,6 @@ static int devpts_remount(struct super_block *sb, int *flags, char *data)
struct pts_fs_info *fsi = DEVPTS_SB(sb);
struct pts_mount_opts *opts = &fsi->mount_opts;
- sync_filesystem(sb);
err = parse_mount_options(data, PARSE_REMOUNT, opts);
/*
--
2.8.3
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH tty-next 6/6] devpts: Change the owner of /dev/pts/ptmx to the mounter of /dev/pts
2016-09-14 18:53 ` [PATCH tty-next 1/6] devpts: Move parse_mount_options into fill_super Eric W. Biederman
` (3 preceding siblings ...)
2016-09-14 18:53 ` [PATCH tty-next 5/6] devpts: Remove sync_filesystems Eric W. Biederman
@ 2016-09-14 18:53 ` Eric W. Biederman
4 siblings, 0 replies; 9+ messages in thread
From: Eric W. Biederman @ 2016-09-14 18:53 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby
Cc: H. Peter Anvin, linux-kernel, linux-fsdevel, Linux Containers,
Eric W. Biederman
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>
---
fs/devpts/inode.c | 13 ++++---------
1 file 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)
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;
-
- 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;
+ kuid_t ptmx_uid = current_fsuid();
+ kgid_t ptmx_gid = current_fsgid();
inode_lock(d_inode(root));
@@ -309,8 +304,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.8.3
^ permalink raw reply related [flat|nested] 9+ messages in thread