Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 54ebbfb1 authored by Aleksa Sarai's avatar Aleksa Sarai Committed by Greg Kroah-Hartman
Browse files

tty: add TIOCGPTPEER ioctl



When opening the slave end of a PTY, it is not possible for userspace to
safely ensure that /dev/pts/$num is actually a slave (in cases where the
mount namespace in which devpts was mounted is controlled by an
untrusted process). In addition, there are several unresolvable
race conditions if userspace were to attempt to detect attacks through
stat(2) and other similar methods [in addition it is not clear how
userspace could detect attacks involving FUSE].

Resolve this by providing an interface for userpace to safely open the
"peer" end of a PTY file descriptor by using the dentry cached by
devpts. Since it is not possible to have an open master PTY without
having its slave exposed in /dev/pts this interface is safe. This
interface currently does not provide a way to get the master pty (since
it is not clear whether such an interface is safe or even useful).

Cc: Christian Brauner <christian.brauner@ubuntu.com>
Cc: Valentin Rothberg <vrothberg@suse.com>
Signed-off-by: default avatarAleksa Sarai <asarai@suse.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 5f0f187f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -100,6 +100,7 @@
#define TIOCGPKT	_IOR('T', 0x38, int) /* Get packet mode state */
#define TIOCGPTLCK	_IOR('T', 0x39, int) /* Get Pty lock state */
#define TIOCGEXCL	_IOR('T', 0x40, int) /* Get exclusive mode state */
#define TIOCGPTPEER	_IOR('T', 0x41, int) /* Safely open the slave */

#define TIOCSERCONFIG	0x5453
#define TIOCSERGWILD	0x5454
+1 −0
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@
#define TIOCGPKT	_IOR('T', 0x38, int) /* Get packet mode state */
#define TIOCGPTLCK	_IOR('T', 0x39, int) /* Get Pty lock state */
#define TIOCGEXCL	_IOR('T', 0x40, int) /* Get exclusive mode state */
#define TIOCGPTPEER	_IOR('T', 0x41, int) /* Safely open the slave */

/* I hope the range from 0x5480 on is free ... */
#define TIOCSCTTY	0x5480		/* become controlling tty */
+1 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@
#define TIOCGPKT	_IOR('T', 0x38, int) /* Get packet mode state */
#define TIOCGPTLCK	_IOR('T', 0x39, int) /* Get Pty lock state */
#define TIOCGEXCL	_IOR('T', 0x40, int) /* Get exclusive mode state */
#define TIOCGPTPEER	_IOR('T', 0x41, int) /* Safely open the slave */

#define FIONCLEX	0x5450  /* these numbers need to be adjusted. */
#define FIOCLEX		0x5451
+1 −0
Original line number Diff line number Diff line
@@ -100,6 +100,7 @@
#define TIOCGPKT	_IOR('T', 0x38, int) /* Get packet mode state */
#define TIOCGPTLCK	_IOR('T', 0x39, int) /* Get Pty lock state */
#define TIOCGEXCL	_IOR('T', 0x40, int) /* Get exclusive mode state */
#define TIOCGPTPEER	_IOR('T', 0x41, int) /* Safely open the slave */

#define TIOCSERCONFIG	0x5453
#define TIOCSERGWILD	0x5454
+1 −0
Original line number Diff line number Diff line
@@ -93,6 +93,7 @@
#define TIOCGPKT	_IOR('T', 0x38, int) /* Get packet mode state */
#define TIOCGPTLCK	_IOR('T', 0x39, int) /* Get Pty lock state */
#define TIOCGEXCL	_IOR('T', 0x40, int) /* Get exclusive mode state */
#define TIOCGPTPEER	_IOR('T', 0x41, int) /* Safely open the slave */

#define TIOCSERCONFIG	_IO('T', 83) /* 0x5453 */
#define TIOCSERGWILD	_IOR('T', 84,  int) /* 0x5454 */
Loading