diff options
author | Eric W. Biederman <ebiederm@xmission.com> | 2016-06-02 11:29:47 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-06-05 13:36:01 -0400 |
commit | eedf265aa003b4781de24cfed40a655a664457e6 (patch) | |
tree | 0e37f0a0c6fd15f7528aa3d3bfaec5685f083282 /drivers/tty | |
parent | 049ec1b5a76d34a6980cccdb7c0baeb4eed7a993 (diff) |
devpts: Make each mount of devpts an independent filesystem.
The /dev/ptmx device node is changed to lookup the directory entry "pts"
in the same directory as the /dev/ptmx device node was opened in. If
there is a "pts" entry and that entry is a devpts filesystem /dev/ptmx
uses that filesystem. Otherwise the open of /dev/ptmx fails.
The DEVPTS_MULTIPLE_INSTANCES configuration option is removed, so that
userspace can now safely depend on each mount of devpts creating a new
instance of the filesystem.
Each mount of devpts is now a separate and equal filesystem.
Reserved ttys are now available to all instances of devpts where the
mounter is in the initial mount namespace.
A new vfs helper path_pts is introduced that finds a directory entry
named "pts" in the directory of the passed in path, and changes the
passed in path to point to it. The helper path_pts uses a function
path_parent_directory that was factored out of follow_dotdot.
In the implementation of devpts:
- devpts_mnt is killed as it is no longer meaningful if all mounts of
devpts are equal.
- pts_sb_from_inode is replaced by just inode->i_sb as all cached
inodes in the tty layer are now from the devpts filesystem.
- devpts_add_ref is rolled into the new function devpts_ptmx. And the
unnecessary inode hold is removed.
- devpts_del_ref is renamed devpts_release and reduced to just a
deacrivate_super.
- The newinstance mount option continues to be accepted but is now
ignored.
In devpts_fs.h definitions for when !CONFIG_UNIX98_PTYS are removed as
they are never used.
Documentation/filesystems/devices.txt is updated to describe the current
situation.
This has been verified to work properly on openwrt-15.05, centos5,
centos6, centos7, debian-6.0.2, debian-7.9, debian-8.2, ubuntu-14.04.3,
ubuntu-15.10, fedora23, magia-5, mint-17.3, opensuse-42.1,
slackware-14.1, gentoo-20151225 (13.0?), archlinux-2015-12-01. With the
caveat that on centos6 and on slackware-14.1 that there wind up being
two instances of the devpts filesystem mounted on /dev/pts, the lower
copy does not end up getting used.
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Greg KH <greg@kroah.com>
Cc: Peter Hurley <peter@hurleysoftware.com>
Cc: Peter Anvin <hpa@zytor.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Serge Hallyn <serge.hallyn@ubuntu.com>
Cc: Willy Tarreau <w@1wt.eu>
Cc: Aurelien Jarno <aurelien@aurel32.net>
Cc: One Thousand Gnomes <gnomes@lxorguk.ukuu.org.uk>
Cc: Jann Horn <jann@thejh.net>
Cc: Jiri Slaby <jslaby@suse.com>
Cc: Florian Weimer <fw@deneb.enyo.de>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/tty')
-rw-r--r-- | drivers/tty/Kconfig | 11 | ||||
-rw-r--r-- | drivers/tty/pty.c | 15 |
2 files changed, 8 insertions, 18 deletions
diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig index 82c4d2e45319..95103054c0e4 100644 --- a/drivers/tty/Kconfig +++ b/drivers/tty/Kconfig | |||
@@ -120,17 +120,6 @@ config UNIX98_PTYS | |||
120 | All modern Linux systems use the Unix98 ptys. Say Y unless | 120 | All modern Linux systems use the Unix98 ptys. Say Y unless |
121 | you're on an embedded system and want to conserve memory. | 121 | you're on an embedded system and want to conserve memory. |
122 | 122 | ||
123 | config DEVPTS_MULTIPLE_INSTANCES | ||
124 | bool "Support multiple instances of devpts" | ||
125 | depends on UNIX98_PTYS | ||
126 | default n | ||
127 | ---help--- | ||
128 | Enable support for multiple instances of devpts filesystem. | ||
129 | If you want to have isolated PTY namespaces (eg: in containers), | ||
130 | say Y here. Otherwise, say N. If enabled, each mount of devpts | ||
131 | filesystem with the '-o newinstance' option will create an | ||
132 | independent PTY namespace. | ||
133 | |||
134 | config LEGACY_PTYS | 123 | config LEGACY_PTYS |
135 | bool "Legacy (BSD) PTY support" | 124 | bool "Legacy (BSD) PTY support" |
136 | default y | 125 | default y |
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c index dd4b8417e7f4..f856c4544eea 100644 --- a/drivers/tty/pty.c +++ b/drivers/tty/pty.c | |||
@@ -668,7 +668,7 @@ static void pty_unix98_remove(struct tty_driver *driver, struct tty_struct *tty) | |||
668 | else | 668 | else |
669 | fsi = tty->link->driver_data; | 669 | fsi = tty->link->driver_data; |
670 | devpts_kill_index(fsi, tty->index); | 670 | devpts_kill_index(fsi, tty->index); |
671 | devpts_put_ref(fsi); | 671 | devpts_release(fsi); |
672 | } | 672 | } |
673 | 673 | ||
674 | static const struct tty_operations ptm_unix98_ops = { | 674 | static const struct tty_operations ptm_unix98_ops = { |
@@ -733,10 +733,11 @@ static int ptmx_open(struct inode *inode, struct file *filp) | |||
733 | if (retval) | 733 | if (retval) |
734 | return retval; | 734 | return retval; |
735 | 735 | ||
736 | fsi = devpts_get_ref(inode, filp); | 736 | fsi = devpts_acquire(filp); |
737 | retval = -ENODEV; | 737 | if (IS_ERR(fsi)) { |
738 | if (!fsi) | 738 | retval = PTR_ERR(fsi); |
739 | goto out_free_file; | 739 | goto out_free_file; |
740 | } | ||
740 | 741 | ||
741 | /* find a device that is not in use. */ | 742 | /* find a device that is not in use. */ |
742 | mutex_lock(&devpts_mutex); | 743 | mutex_lock(&devpts_mutex); |
@@ -745,7 +746,7 @@ static int ptmx_open(struct inode *inode, struct file *filp) | |||
745 | 746 | ||
746 | retval = index; | 747 | retval = index; |
747 | if (index < 0) | 748 | if (index < 0) |
748 | goto out_put_ref; | 749 | goto out_put_fsi; |
749 | 750 | ||
750 | 751 | ||
751 | mutex_lock(&tty_mutex); | 752 | mutex_lock(&tty_mutex); |
@@ -789,8 +790,8 @@ err_release: | |||
789 | return retval; | 790 | return retval; |
790 | out: | 791 | out: |
791 | devpts_kill_index(fsi, index); | 792 | devpts_kill_index(fsi, index); |
792 | out_put_ref: | 793 | out_put_fsi: |
793 | devpts_put_ref(fsi); | 794 | devpts_release(fsi); |
794 | out_free_file: | 795 | out_free_file: |
795 | tty_free_file(filp); | 796 | tty_free_file(filp); |
796 | return retval; | 797 | return retval; |