History

tty: cleanup prohibition of direct opening for unix98 pty master

cleanup hack added in v2.6.27-3203-g15582d3 comment from that patch: : pty: If the administrator creates a device for a ptmx slave we should not error : : The open path for ptmx slaves is via the ptmx device. Opening them any : other way is not allowed. Vegard Nossum found that previously this was not : the case and mknod foo c 128 42; cat foo would produce nasty diagnostics : : Signed-off-by: Alan Cox <alan@redhat.com> : Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> devpts_get_tty() returns non-null only for inodes on devpts, but there is no inodes for master-devices, /dev/ptmx (/dev/pts/ptmx) is the only way to open them. Thus we can completely forbid lookup for master-devices and eliminate that hack in tty_init_dev() because tty_open() will get EIO from tty_driver_lookup_tty().

Konstantin Khlebnikov committed 14 years ago

Commit 593a27c1 parent dcd6c923 files · +6 −17Browse files

Unified · Split

3 files
  1. drivers/tty/pty.c +3 −5
  2. drivers/tty/tty_io.c +2 −10
  3. include/linux/tty.h +1 −2
drivers/tty/pty.c+3−5
@@ -515,10 +515,8 @@ static int pty_unix98_ioctl(struct tty_struct *tty, · 514 unmodified lines
515515 static struct tty_struct *ptm_unix98_lookup(struct tty_driver *driver,
516516 struct inode *ptm_inode, int idx)
517517 {
518− struct tty_struct *tty = devpts_get_tty(ptm_inode, idx);
519− if (tty)
520− tty = tty->link;
521− return tty;
518+ /* Master must be open via /dev/ptmx */
519+ return ERR_PTR(-EIO);
522520 }
523521
524522 /**
@@ -677,7 +675,7 @@ static int ptmx_open(struct inode *inode, struct file *filp) · 152 unmodified lines
677675
678676 mutex_lock(&tty_mutex);
679677 tty_lock();
680− tty = tty_init_dev(ptm_driver, index, 1);
678+ tty = tty_init_dev(ptm_driver, index);
681679 mutex_unlock(&tty_mutex);
682680
683681 if (IS_ERR(tty)) {
drivers/tty/tty_io.c+2−10
@@ -1365,7 +1365,6 @@ static int tty_reopen(struct tty_struct *tty) · 1364 unmodified lines
13651365 * @driver: tty driver we are opening a device on
13661366 * @idx: device index
13671367 * @ret_tty: returned tty structure
1368− * @first_ok: ok to open a new device (used by ptmx)
13691368 *
13701369 * Prepare a tty device. This may not be a "new" clean device but
13711370 * could also be an active device. The pty drivers require special
@@ -1385,18 +1384,11 @@ static int tty_reopen(struct tty_struct *tty) · 13 unmodified lines
13851384 * relaxed for the (most common) case of reopening a tty.
13861385 */
13871386
1388−struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx,
1389− int first_ok)
1387+struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx)
13901388 {
13911389 struct tty_struct *tty;
13921390 int retval;
13931391
1394− /* Check if pty master is being opened multiple times */
1395− if (driver->subtype == PTY_TYPE_MASTER &&
1396− (driver->flags & TTY_DRIVER_DEVPTS_MEM) && !first_ok) {
1397− return ERR_PTR(-EIO);
1398− }
1399−
14001392 /*
14011393 * First time open is complex, especially for PTY devices.
14021394 * This code guarantees that either everything succeeds and the
@@ -1950,7 +1942,7 @@ retry_open: · 547 unmodified lines
19501942 if (retval)
19511943 tty = ERR_PTR(retval);
19521944 } else
1953− tty = tty_init_dev(driver, index, 0);
1945+ tty = tty_init_dev(driver, index);
19541946
19551947 mutex_unlock(&tty_mutex);
19561948 if (driver)
include/linux/tty.h+1−2
@@ -480,8 +480,7 @@ extern void free_tty_struct(struct tty_struct *tty); · 479 unmodified lines
480480 extern void initialize_tty_struct(struct tty_struct *tty,
481481 struct tty_driver *driver, int idx);
482482 extern void deinitialize_tty_struct(struct tty_struct *tty);
483−extern struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx,
484− int first_ok);
483+extern struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx);
485484 extern int tty_release(struct inode *inode, struct file *filp);
486485 extern int tty_init_termios(struct tty_struct *tty);
487486