diff options
author | Alan Cox <alan@redhat.com> | 2008-10-13 05:41:03 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-10-13 12:51:42 -0400 |
commit | 15582d36a15978355d2168eaa018a3736db7281f (patch) | |
tree | 6ea2b94bb4504cf0d8dffdecbd85a60fe0d69c06 /drivers/char/tty_io.c | |
parent | dbda4c0b97b18fd59b3964548361b4f92357f730 (diff) |
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>
Diffstat (limited to 'drivers/char/tty_io.c')
-rw-r--r-- | drivers/char/tty_io.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c index f40298e9873a..2e96ce0fddc5 100644 --- a/drivers/char/tty_io.c +++ b/drivers/char/tty_io.c | |||
@@ -1227,7 +1227,8 @@ static void tty_line_name(struct tty_driver *driver, int index, char *p) | |||
1227 | * init_dev - initialise a tty device | 1227 | * init_dev - initialise a tty device |
1228 | * @driver: tty driver we are opening a device on | 1228 | * @driver: tty driver we are opening a device on |
1229 | * @idx: device index | 1229 | * @idx: device index |
1230 | * @tty: returned tty structure | 1230 | * @ret_tty: returned tty structure |
1231 | * @first_ok: ok to open a new device (used by ptmx) | ||
1231 | * | 1232 | * |
1232 | * Prepare a tty device. This may not be a "new" clean device but | 1233 | * Prepare a tty device. This may not be a "new" clean device but |
1233 | * could also be an active device. The pty drivers require special | 1234 | * could also be an active device. The pty drivers require special |
@@ -1248,7 +1249,7 @@ static void tty_line_name(struct tty_driver *driver, int index, char *p) | |||
1248 | */ | 1249 | */ |
1249 | 1250 | ||
1250 | static int init_dev(struct tty_driver *driver, int idx, | 1251 | static int init_dev(struct tty_driver *driver, int idx, |
1251 | struct tty_struct **ret_tty) | 1252 | struct tty_struct **ret_tty, int first_ok) |
1252 | { | 1253 | { |
1253 | struct tty_struct *tty, *o_tty; | 1254 | struct tty_struct *tty, *o_tty; |
1254 | struct ktermios *tp, **tp_loc, *o_tp, **o_tp_loc; | 1255 | struct ktermios *tp, **tp_loc, *o_tp, **o_tp_loc; |
@@ -1279,6 +1280,11 @@ static int init_dev(struct tty_driver *driver, int idx, | |||
1279 | } | 1280 | } |
1280 | if (tty) goto fast_track; | 1281 | if (tty) goto fast_track; |
1281 | 1282 | ||
1283 | if (driver->subtype == PTY_TYPE_MASTER && | ||
1284 | (driver->flags & TTY_DRIVER_DEVPTS_MEM) && !first_ok) { | ||
1285 | retval = -EIO; | ||
1286 | goto end_init; | ||
1287 | } | ||
1282 | /* | 1288 | /* |
1283 | * First time open is complex, especially for PTY devices. | 1289 | * First time open is complex, especially for PTY devices. |
1284 | * This code guarantees that either everything succeeds and the | 1290 | * This code guarantees that either everything succeeds and the |
@@ -1413,7 +1419,7 @@ static int init_dev(struct tty_driver *driver, int idx, | |||
1413 | 1419 | ||
1414 | if (retval) | 1420 | if (retval) |
1415 | goto release_mem_out; | 1421 | goto release_mem_out; |
1416 | goto success; | 1422 | goto success; |
1417 | 1423 | ||
1418 | /* | 1424 | /* |
1419 | * This fast open can be used if the tty is already open. | 1425 | * This fast open can be used if the tty is already open. |
@@ -1795,7 +1801,7 @@ static void release_dev(struct file *filp) | |||
1795 | } | 1801 | } |
1796 | 1802 | ||
1797 | /** | 1803 | /** |
1798 | * tty_open - open a tty device | 1804 | * __tty_open - open a tty device |
1799 | * @inode: inode of device file | 1805 | * @inode: inode of device file |
1800 | * @filp: file pointer to tty | 1806 | * @filp: file pointer to tty |
1801 | * | 1807 | * |
@@ -1874,7 +1880,7 @@ retry_open: | |||
1874 | return -ENODEV; | 1880 | return -ENODEV; |
1875 | } | 1881 | } |
1876 | got_driver: | 1882 | got_driver: |
1877 | retval = init_dev(driver, index, &tty); | 1883 | retval = init_dev(driver, index, &tty, 0); |
1878 | mutex_unlock(&tty_mutex); | 1884 | mutex_unlock(&tty_mutex); |
1879 | if (retval) | 1885 | if (retval) |
1880 | return retval; | 1886 | return retval; |
@@ -1971,7 +1977,7 @@ static int __ptmx_open(struct inode *inode, struct file *filp) | |||
1971 | return index; | 1977 | return index; |
1972 | 1978 | ||
1973 | mutex_lock(&tty_mutex); | 1979 | mutex_lock(&tty_mutex); |
1974 | retval = init_dev(ptm_driver, index, &tty); | 1980 | retval = init_dev(ptm_driver, index, &tty, 1); |
1975 | mutex_unlock(&tty_mutex); | 1981 | mutex_unlock(&tty_mutex); |
1976 | 1982 | ||
1977 | if (retval) | 1983 | if (retval) |