diff options
Diffstat (limited to 'drivers/char/tty_io.c')
-rw-r--r-- | drivers/char/tty_io.c | 156 |
1 files changed, 90 insertions, 66 deletions
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c index 59499ee0fe6a..d71f0fc34b46 100644 --- a/drivers/char/tty_io.c +++ b/drivers/char/tty_io.c | |||
@@ -142,7 +142,6 @@ ssize_t redirected_tty_write(struct file *, const char __user *, | |||
142 | size_t, loff_t *); | 142 | size_t, loff_t *); |
143 | static unsigned int tty_poll(struct file *, poll_table *); | 143 | static unsigned int tty_poll(struct file *, poll_table *); |
144 | static int tty_open(struct inode *, struct file *); | 144 | static int tty_open(struct inode *, struct file *); |
145 | static int tty_release(struct inode *, struct file *); | ||
146 | long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg); | 145 | long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg); |
147 | #ifdef CONFIG_COMPAT | 146 | #ifdef CONFIG_COMPAT |
148 | static long tty_compat_ioctl(struct file *file, unsigned int cmd, | 147 | static long tty_compat_ioctl(struct file *file, unsigned int cmd, |
@@ -506,8 +505,6 @@ static void do_tty_hangup(struct work_struct *work) | |||
506 | if (!tty) | 505 | if (!tty) |
507 | return; | 506 | return; |
508 | 507 | ||
509 | /* inuse_filps is protected by the single kernel lock */ | ||
510 | lock_kernel(); | ||
511 | 508 | ||
512 | spin_lock(&redirect_lock); | 509 | spin_lock(&redirect_lock); |
513 | if (redirect && redirect->private_data == tty) { | 510 | if (redirect && redirect->private_data == tty) { |
@@ -516,7 +513,10 @@ static void do_tty_hangup(struct work_struct *work) | |||
516 | } | 513 | } |
517 | spin_unlock(&redirect_lock); | 514 | spin_unlock(&redirect_lock); |
518 | 515 | ||
516 | /* inuse_filps is protected by the single kernel lock */ | ||
517 | lock_kernel(); | ||
519 | check_tty_count(tty, "do_tty_hangup"); | 518 | check_tty_count(tty, "do_tty_hangup"); |
519 | |||
520 | file_list_lock(); | 520 | file_list_lock(); |
521 | /* This breaks for file handles being sent over AF_UNIX sockets ? */ | 521 | /* This breaks for file handles being sent over AF_UNIX sockets ? */ |
522 | list_for_each_entry(filp, &tty->tty_files, f_u.fu_list) { | 522 | list_for_each_entry(filp, &tty->tty_files, f_u.fu_list) { |
@@ -708,6 +708,8 @@ void disassociate_ctty(int on_exit) | |||
708 | struct tty_struct *tty; | 708 | struct tty_struct *tty; |
709 | struct pid *tty_pgrp = NULL; | 709 | struct pid *tty_pgrp = NULL; |
710 | 710 | ||
711 | if (!current->signal->leader) | ||
712 | return; | ||
711 | 713 | ||
712 | tty = get_current_tty(); | 714 | tty = get_current_tty(); |
713 | if (tty) { | 715 | if (tty) { |
@@ -773,8 +775,7 @@ void no_tty(void) | |||
773 | { | 775 | { |
774 | struct task_struct *tsk = current; | 776 | struct task_struct *tsk = current; |
775 | lock_kernel(); | 777 | lock_kernel(); |
776 | if (tsk->signal->leader) | 778 | disassociate_ctty(0); |
777 | disassociate_ctty(0); | ||
778 | unlock_kernel(); | 779 | unlock_kernel(); |
779 | proc_clear_tty(tsk); | 780 | proc_clear_tty(tsk); |
780 | } | 781 | } |
@@ -1017,14 +1018,16 @@ out: | |||
1017 | 1018 | ||
1018 | void tty_write_message(struct tty_struct *tty, char *msg) | 1019 | void tty_write_message(struct tty_struct *tty, char *msg) |
1019 | { | 1020 | { |
1020 | lock_kernel(); | ||
1021 | if (tty) { | 1021 | if (tty) { |
1022 | mutex_lock(&tty->atomic_write_lock); | 1022 | mutex_lock(&tty->atomic_write_lock); |
1023 | if (tty->ops->write && !test_bit(TTY_CLOSING, &tty->flags)) | 1023 | lock_kernel(); |
1024 | if (tty->ops->write && !test_bit(TTY_CLOSING, &tty->flags)) { | ||
1025 | unlock_kernel(); | ||
1024 | tty->ops->write(tty, msg, strlen(msg)); | 1026 | tty->ops->write(tty, msg, strlen(msg)); |
1027 | } else | ||
1028 | unlock_kernel(); | ||
1025 | tty_write_unlock(tty); | 1029 | tty_write_unlock(tty); |
1026 | } | 1030 | } |
1027 | unlock_kernel(); | ||
1028 | return; | 1031 | return; |
1029 | } | 1032 | } |
1030 | 1033 | ||
@@ -1202,14 +1205,21 @@ static int tty_driver_install_tty(struct tty_driver *driver, | |||
1202 | struct tty_struct *tty) | 1205 | struct tty_struct *tty) |
1203 | { | 1206 | { |
1204 | int idx = tty->index; | 1207 | int idx = tty->index; |
1208 | int ret; | ||
1205 | 1209 | ||
1206 | if (driver->ops->install) | 1210 | if (driver->ops->install) { |
1207 | return driver->ops->install(driver, tty); | 1211 | lock_kernel(); |
1212 | ret = driver->ops->install(driver, tty); | ||
1213 | unlock_kernel(); | ||
1214 | return ret; | ||
1215 | } | ||
1208 | 1216 | ||
1209 | if (tty_init_termios(tty) == 0) { | 1217 | if (tty_init_termios(tty) == 0) { |
1218 | lock_kernel(); | ||
1210 | tty_driver_kref_get(driver); | 1219 | tty_driver_kref_get(driver); |
1211 | tty->count++; | 1220 | tty->count++; |
1212 | driver->ttys[idx] = tty; | 1221 | driver->ttys[idx] = tty; |
1222 | unlock_kernel(); | ||
1213 | return 0; | 1223 | return 0; |
1214 | } | 1224 | } |
1215 | return -ENOMEM; | 1225 | return -ENOMEM; |
@@ -1302,10 +1312,14 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx, | |||
1302 | struct tty_struct *tty; | 1312 | struct tty_struct *tty; |
1303 | int retval; | 1313 | int retval; |
1304 | 1314 | ||
1315 | lock_kernel(); | ||
1305 | /* Check if pty master is being opened multiple times */ | 1316 | /* Check if pty master is being opened multiple times */ |
1306 | if (driver->subtype == PTY_TYPE_MASTER && | 1317 | if (driver->subtype == PTY_TYPE_MASTER && |
1307 | (driver->flags & TTY_DRIVER_DEVPTS_MEM) && !first_ok) | 1318 | (driver->flags & TTY_DRIVER_DEVPTS_MEM) && !first_ok) { |
1319 | unlock_kernel(); | ||
1308 | return ERR_PTR(-EIO); | 1320 | return ERR_PTR(-EIO); |
1321 | } | ||
1322 | unlock_kernel(); | ||
1309 | 1323 | ||
1310 | /* | 1324 | /* |
1311 | * First time open is complex, especially for PTY devices. | 1325 | * First time open is complex, especially for PTY devices. |
@@ -1335,7 +1349,6 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx, | |||
1335 | * If we fail here just call release_tty to clean up. No need | 1349 | * If we fail here just call release_tty to clean up. No need |
1336 | * to decrement the use counts, as release_tty doesn't care. | 1350 | * to decrement the use counts, as release_tty doesn't care. |
1337 | */ | 1351 | */ |
1338 | |||
1339 | retval = tty_ldisc_setup(tty, tty->link); | 1352 | retval = tty_ldisc_setup(tty, tty->link); |
1340 | if (retval) | 1353 | if (retval) |
1341 | goto release_mem_out; | 1354 | goto release_mem_out; |
@@ -1350,7 +1363,9 @@ release_mem_out: | |||
1350 | if (printk_ratelimit()) | 1363 | if (printk_ratelimit()) |
1351 | printk(KERN_INFO "tty_init_dev: ldisc open failed, " | 1364 | printk(KERN_INFO "tty_init_dev: ldisc open failed, " |
1352 | "clearing slot %d\n", idx); | 1365 | "clearing slot %d\n", idx); |
1366 | lock_kernel(); | ||
1353 | release_tty(tty, idx); | 1367 | release_tty(tty, idx); |
1368 | unlock_kernel(); | ||
1354 | return ERR_PTR(retval); | 1369 | return ERR_PTR(retval); |
1355 | } | 1370 | } |
1356 | 1371 | ||
@@ -1408,6 +1423,8 @@ static void release_one_tty(struct work_struct *work) | |||
1408 | list_del_init(&tty->tty_files); | 1423 | list_del_init(&tty->tty_files); |
1409 | file_list_unlock(); | 1424 | file_list_unlock(); |
1410 | 1425 | ||
1426 | put_pid(tty->pgrp); | ||
1427 | put_pid(tty->session); | ||
1411 | free_tty_struct(tty); | 1428 | free_tty_struct(tty); |
1412 | } | 1429 | } |
1413 | 1430 | ||
@@ -1464,7 +1481,17 @@ static void release_tty(struct tty_struct *tty, int idx) | |||
1464 | tty_kref_put(tty); | 1481 | tty_kref_put(tty); |
1465 | } | 1482 | } |
1466 | 1483 | ||
1467 | /* | 1484 | /** |
1485 | * tty_release - vfs callback for close | ||
1486 | * @inode: inode of tty | ||
1487 | * @filp: file pointer for handle to tty | ||
1488 | * | ||
1489 | * Called the last time each file handle is closed that references | ||
1490 | * this tty. There may however be several such references. | ||
1491 | * | ||
1492 | * Locking: | ||
1493 | * Takes bkl. See tty_release_dev | ||
1494 | * | ||
1468 | * Even releasing the tty structures is a tricky business.. We have | 1495 | * Even releasing the tty structures is a tricky business.. We have |
1469 | * to be very careful that the structures are all released at the | 1496 | * to be very careful that the structures are all released at the |
1470 | * same time, as interrupts might otherwise get the wrong pointers. | 1497 | * same time, as interrupts might otherwise get the wrong pointers. |
@@ -1472,20 +1499,20 @@ static void release_tty(struct tty_struct *tty, int idx) | |||
1472 | * WSH 09/09/97: rewritten to avoid some nasty race conditions that could | 1499 | * WSH 09/09/97: rewritten to avoid some nasty race conditions that could |
1473 | * lead to double frees or releasing memory still in use. | 1500 | * lead to double frees or releasing memory still in use. |
1474 | */ | 1501 | */ |
1475 | void tty_release_dev(struct file *filp) | 1502 | |
1503 | int tty_release(struct inode *inode, struct file *filp) | ||
1476 | { | 1504 | { |
1477 | struct tty_struct *tty, *o_tty; | 1505 | struct tty_struct *tty, *o_tty; |
1478 | int pty_master, tty_closing, o_tty_closing, do_sleep; | 1506 | int pty_master, tty_closing, o_tty_closing, do_sleep; |
1479 | int devpts; | 1507 | int devpts; |
1480 | int idx; | 1508 | int idx; |
1481 | char buf[64]; | 1509 | char buf[64]; |
1482 | struct inode *inode; | ||
1483 | 1510 | ||
1484 | inode = filp->f_path.dentry->d_inode; | ||
1485 | tty = (struct tty_struct *)filp->private_data; | 1511 | tty = (struct tty_struct *)filp->private_data; |
1486 | if (tty_paranoia_check(tty, inode, "tty_release_dev")) | 1512 | if (tty_paranoia_check(tty, inode, "tty_release_dev")) |
1487 | return; | 1513 | return 0; |
1488 | 1514 | ||
1515 | lock_kernel(); | ||
1489 | check_tty_count(tty, "tty_release_dev"); | 1516 | check_tty_count(tty, "tty_release_dev"); |
1490 | 1517 | ||
1491 | tty_fasync(-1, filp, 0); | 1518 | tty_fasync(-1, filp, 0); |
@@ -1500,19 +1527,22 @@ void tty_release_dev(struct file *filp) | |||
1500 | if (idx < 0 || idx >= tty->driver->num) { | 1527 | if (idx < 0 || idx >= tty->driver->num) { |
1501 | printk(KERN_DEBUG "tty_release_dev: bad idx when trying to " | 1528 | printk(KERN_DEBUG "tty_release_dev: bad idx when trying to " |
1502 | "free (%s)\n", tty->name); | 1529 | "free (%s)\n", tty->name); |
1503 | return; | 1530 | unlock_kernel(); |
1531 | return 0; | ||
1504 | } | 1532 | } |
1505 | if (!devpts) { | 1533 | if (!devpts) { |
1506 | if (tty != tty->driver->ttys[idx]) { | 1534 | if (tty != tty->driver->ttys[idx]) { |
1535 | unlock_kernel(); | ||
1507 | printk(KERN_DEBUG "tty_release_dev: driver.table[%d] not tty " | 1536 | printk(KERN_DEBUG "tty_release_dev: driver.table[%d] not tty " |
1508 | "for (%s)\n", idx, tty->name); | 1537 | "for (%s)\n", idx, tty->name); |
1509 | return; | 1538 | return 0; |
1510 | } | 1539 | } |
1511 | if (tty->termios != tty->driver->termios[idx]) { | 1540 | if (tty->termios != tty->driver->termios[idx]) { |
1541 | unlock_kernel(); | ||
1512 | printk(KERN_DEBUG "tty_release_dev: driver.termios[%d] not termios " | 1542 | printk(KERN_DEBUG "tty_release_dev: driver.termios[%d] not termios " |
1513 | "for (%s)\n", | 1543 | "for (%s)\n", |
1514 | idx, tty->name); | 1544 | idx, tty->name); |
1515 | return; | 1545 | return 0; |
1516 | } | 1546 | } |
1517 | } | 1547 | } |
1518 | #endif | 1548 | #endif |
@@ -1526,26 +1556,30 @@ void tty_release_dev(struct file *filp) | |||
1526 | if (tty->driver->other && | 1556 | if (tty->driver->other && |
1527 | !(tty->driver->flags & TTY_DRIVER_DEVPTS_MEM)) { | 1557 | !(tty->driver->flags & TTY_DRIVER_DEVPTS_MEM)) { |
1528 | if (o_tty != tty->driver->other->ttys[idx]) { | 1558 | if (o_tty != tty->driver->other->ttys[idx]) { |
1559 | unlock_kernel(); | ||
1529 | printk(KERN_DEBUG "tty_release_dev: other->table[%d] " | 1560 | printk(KERN_DEBUG "tty_release_dev: other->table[%d] " |
1530 | "not o_tty for (%s)\n", | 1561 | "not o_tty for (%s)\n", |
1531 | idx, tty->name); | 1562 | idx, tty->name); |
1532 | return; | 1563 | return 0 ; |
1533 | } | 1564 | } |
1534 | if (o_tty->termios != tty->driver->other->termios[idx]) { | 1565 | if (o_tty->termios != tty->driver->other->termios[idx]) { |
1566 | unlock_kernel(); | ||
1535 | printk(KERN_DEBUG "tty_release_dev: other->termios[%d] " | 1567 | printk(KERN_DEBUG "tty_release_dev: other->termios[%d] " |
1536 | "not o_termios for (%s)\n", | 1568 | "not o_termios for (%s)\n", |
1537 | idx, tty->name); | 1569 | idx, tty->name); |
1538 | return; | 1570 | return 0; |
1539 | } | 1571 | } |
1540 | if (o_tty->link != tty) { | 1572 | if (o_tty->link != tty) { |
1573 | unlock_kernel(); | ||
1541 | printk(KERN_DEBUG "tty_release_dev: bad pty pointers\n"); | 1574 | printk(KERN_DEBUG "tty_release_dev: bad pty pointers\n"); |
1542 | return; | 1575 | return 0; |
1543 | } | 1576 | } |
1544 | } | 1577 | } |
1545 | #endif | 1578 | #endif |
1546 | if (tty->ops->close) | 1579 | if (tty->ops->close) |
1547 | tty->ops->close(tty, filp); | 1580 | tty->ops->close(tty, filp); |
1548 | 1581 | ||
1582 | unlock_kernel(); | ||
1549 | /* | 1583 | /* |
1550 | * Sanity check: if tty->count is going to zero, there shouldn't be | 1584 | * Sanity check: if tty->count is going to zero, there shouldn't be |
1551 | * any waiters on tty->read_wait or tty->write_wait. We test the | 1585 | * any waiters on tty->read_wait or tty->write_wait. We test the |
@@ -1568,6 +1602,7 @@ void tty_release_dev(struct file *filp) | |||
1568 | opens on /dev/tty */ | 1602 | opens on /dev/tty */ |
1569 | 1603 | ||
1570 | mutex_lock(&tty_mutex); | 1604 | mutex_lock(&tty_mutex); |
1605 | lock_kernel(); | ||
1571 | tty_closing = tty->count <= 1; | 1606 | tty_closing = tty->count <= 1; |
1572 | o_tty_closing = o_tty && | 1607 | o_tty_closing = o_tty && |
1573 | (o_tty->count <= (pty_master ? 1 : 0)); | 1608 | (o_tty->count <= (pty_master ? 1 : 0)); |
@@ -1598,6 +1633,7 @@ void tty_release_dev(struct file *filp) | |||
1598 | 1633 | ||
1599 | printk(KERN_WARNING "tty_release_dev: %s: read/write wait queue " | 1634 | printk(KERN_WARNING "tty_release_dev: %s: read/write wait queue " |
1600 | "active!\n", tty_name(tty, buf)); | 1635 | "active!\n", tty_name(tty, buf)); |
1636 | unlock_kernel(); | ||
1601 | mutex_unlock(&tty_mutex); | 1637 | mutex_unlock(&tty_mutex); |
1602 | schedule(); | 1638 | schedule(); |
1603 | } | 1639 | } |
@@ -1661,8 +1697,10 @@ void tty_release_dev(struct file *filp) | |||
1661 | mutex_unlock(&tty_mutex); | 1697 | mutex_unlock(&tty_mutex); |
1662 | 1698 | ||
1663 | /* check whether both sides are closing ... */ | 1699 | /* check whether both sides are closing ... */ |
1664 | if (!tty_closing || (o_tty && !o_tty_closing)) | 1700 | if (!tty_closing || (o_tty && !o_tty_closing)) { |
1665 | return; | 1701 | unlock_kernel(); |
1702 | return 0; | ||
1703 | } | ||
1666 | 1704 | ||
1667 | #ifdef TTY_DEBUG_HANGUP | 1705 | #ifdef TTY_DEBUG_HANGUP |
1668 | printk(KERN_DEBUG "freeing tty structure..."); | 1706 | printk(KERN_DEBUG "freeing tty structure..."); |
@@ -1680,10 +1718,12 @@ void tty_release_dev(struct file *filp) | |||
1680 | /* Make this pty number available for reallocation */ | 1718 | /* Make this pty number available for reallocation */ |
1681 | if (devpts) | 1719 | if (devpts) |
1682 | devpts_kill_index(inode, idx); | 1720 | devpts_kill_index(inode, idx); |
1721 | unlock_kernel(); | ||
1722 | return 0; | ||
1683 | } | 1723 | } |
1684 | 1724 | ||
1685 | /** | 1725 | /** |
1686 | * __tty_open - open a tty device | 1726 | * tty_open - open a tty device |
1687 | * @inode: inode of device file | 1727 | * @inode: inode of device file |
1688 | * @filp: file pointer to tty | 1728 | * @filp: file pointer to tty |
1689 | * | 1729 | * |
@@ -1703,7 +1743,7 @@ void tty_release_dev(struct file *filp) | |||
1703 | * ->siglock protects ->signal/->sighand | 1743 | * ->siglock protects ->signal/->sighand |
1704 | */ | 1744 | */ |
1705 | 1745 | ||
1706 | static int __tty_open(struct inode *inode, struct file *filp) | 1746 | static int tty_open(struct inode *inode, struct file *filp) |
1707 | { | 1747 | { |
1708 | struct tty_struct *tty = NULL; | 1748 | struct tty_struct *tty = NULL; |
1709 | int noctty, retval; | 1749 | int noctty, retval; |
@@ -1720,10 +1760,12 @@ retry_open: | |||
1720 | retval = 0; | 1760 | retval = 0; |
1721 | 1761 | ||
1722 | mutex_lock(&tty_mutex); | 1762 | mutex_lock(&tty_mutex); |
1763 | lock_kernel(); | ||
1723 | 1764 | ||
1724 | if (device == MKDEV(TTYAUX_MAJOR, 0)) { | 1765 | if (device == MKDEV(TTYAUX_MAJOR, 0)) { |
1725 | tty = get_current_tty(); | 1766 | tty = get_current_tty(); |
1726 | if (!tty) { | 1767 | if (!tty) { |
1768 | unlock_kernel(); | ||
1727 | mutex_unlock(&tty_mutex); | 1769 | mutex_unlock(&tty_mutex); |
1728 | return -ENXIO; | 1770 | return -ENXIO; |
1729 | } | 1771 | } |
@@ -1755,12 +1797,14 @@ retry_open: | |||
1755 | goto got_driver; | 1797 | goto got_driver; |
1756 | } | 1798 | } |
1757 | } | 1799 | } |
1800 | unlock_kernel(); | ||
1758 | mutex_unlock(&tty_mutex); | 1801 | mutex_unlock(&tty_mutex); |
1759 | return -ENODEV; | 1802 | return -ENODEV; |
1760 | } | 1803 | } |
1761 | 1804 | ||
1762 | driver = get_tty_driver(device, &index); | 1805 | driver = get_tty_driver(device, &index); |
1763 | if (!driver) { | 1806 | if (!driver) { |
1807 | unlock_kernel(); | ||
1764 | mutex_unlock(&tty_mutex); | 1808 | mutex_unlock(&tty_mutex); |
1765 | return -ENODEV; | 1809 | return -ENODEV; |
1766 | } | 1810 | } |
@@ -1770,6 +1814,7 @@ got_driver: | |||
1770 | tty = tty_driver_lookup_tty(driver, inode, index); | 1814 | tty = tty_driver_lookup_tty(driver, inode, index); |
1771 | 1815 | ||
1772 | if (IS_ERR(tty)) { | 1816 | if (IS_ERR(tty)) { |
1817 | unlock_kernel(); | ||
1773 | mutex_unlock(&tty_mutex); | 1818 | mutex_unlock(&tty_mutex); |
1774 | return PTR_ERR(tty); | 1819 | return PTR_ERR(tty); |
1775 | } | 1820 | } |
@@ -1784,8 +1829,10 @@ got_driver: | |||
1784 | 1829 | ||
1785 | mutex_unlock(&tty_mutex); | 1830 | mutex_unlock(&tty_mutex); |
1786 | tty_driver_kref_put(driver); | 1831 | tty_driver_kref_put(driver); |
1787 | if (IS_ERR(tty)) | 1832 | if (IS_ERR(tty)) { |
1833 | unlock_kernel(); | ||
1788 | return PTR_ERR(tty); | 1834 | return PTR_ERR(tty); |
1835 | } | ||
1789 | 1836 | ||
1790 | filp->private_data = tty; | 1837 | filp->private_data = tty; |
1791 | file_move(filp, &tty->tty_files); | 1838 | file_move(filp, &tty->tty_files); |
@@ -1813,21 +1860,29 @@ got_driver: | |||
1813 | printk(KERN_DEBUG "error %d in opening %s...", retval, | 1860 | printk(KERN_DEBUG "error %d in opening %s...", retval, |
1814 | tty->name); | 1861 | tty->name); |
1815 | #endif | 1862 | #endif |
1816 | tty_release_dev(filp); | 1863 | tty_release(inode, filp); |
1817 | if (retval != -ERESTARTSYS) | 1864 | if (retval != -ERESTARTSYS) { |
1865 | unlock_kernel(); | ||
1818 | return retval; | 1866 | return retval; |
1819 | if (signal_pending(current)) | 1867 | } |
1868 | if (signal_pending(current)) { | ||
1869 | unlock_kernel(); | ||
1820 | return retval; | 1870 | return retval; |
1871 | } | ||
1821 | schedule(); | 1872 | schedule(); |
1822 | /* | 1873 | /* |
1823 | * Need to reset f_op in case a hangup happened. | 1874 | * Need to reset f_op in case a hangup happened. |
1824 | */ | 1875 | */ |
1825 | if (filp->f_op == &hung_up_tty_fops) | 1876 | if (filp->f_op == &hung_up_tty_fops) |
1826 | filp->f_op = &tty_fops; | 1877 | filp->f_op = &tty_fops; |
1878 | unlock_kernel(); | ||
1827 | goto retry_open; | 1879 | goto retry_open; |
1828 | } | 1880 | } |
1881 | unlock_kernel(); | ||
1882 | |||
1829 | 1883 | ||
1830 | mutex_lock(&tty_mutex); | 1884 | mutex_lock(&tty_mutex); |
1885 | lock_kernel(); | ||
1831 | spin_lock_irq(¤t->sighand->siglock); | 1886 | spin_lock_irq(¤t->sighand->siglock); |
1832 | if (!noctty && | 1887 | if (!noctty && |
1833 | current->signal->leader && | 1888 | current->signal->leader && |
@@ -1835,43 +1890,12 @@ got_driver: | |||
1835 | tty->session == NULL) | 1890 | tty->session == NULL) |
1836 | __proc_set_tty(current, tty); | 1891 | __proc_set_tty(current, tty); |
1837 | spin_unlock_irq(¤t->sighand->siglock); | 1892 | spin_unlock_irq(¤t->sighand->siglock); |
1893 | unlock_kernel(); | ||
1838 | mutex_unlock(&tty_mutex); | 1894 | mutex_unlock(&tty_mutex); |
1839 | return 0; | 1895 | return 0; |
1840 | } | 1896 | } |
1841 | 1897 | ||
1842 | /* BKL pushdown: scary code avoidance wrapper */ | ||
1843 | static int tty_open(struct inode *inode, struct file *filp) | ||
1844 | { | ||
1845 | int ret; | ||
1846 | |||
1847 | lock_kernel(); | ||
1848 | ret = __tty_open(inode, filp); | ||
1849 | unlock_kernel(); | ||
1850 | return ret; | ||
1851 | } | ||
1852 | |||
1853 | |||
1854 | |||
1855 | |||
1856 | /** | ||
1857 | * tty_release - vfs callback for close | ||
1858 | * @inode: inode of tty | ||
1859 | * @filp: file pointer for handle to tty | ||
1860 | * | ||
1861 | * Called the last time each file handle is closed that references | ||
1862 | * this tty. There may however be several such references. | ||
1863 | * | ||
1864 | * Locking: | ||
1865 | * Takes bkl. See tty_release_dev | ||
1866 | */ | ||
1867 | 1898 | ||
1868 | static int tty_release(struct inode *inode, struct file *filp) | ||
1869 | { | ||
1870 | lock_kernel(); | ||
1871 | tty_release_dev(filp); | ||
1872 | unlock_kernel(); | ||
1873 | return 0; | ||
1874 | } | ||
1875 | 1899 | ||
1876 | /** | 1900 | /** |
1877 | * tty_poll - check tty status | 1901 | * tty_poll - check tty status |
@@ -1930,8 +1954,10 @@ static int tty_fasync(int fd, struct file *filp, int on) | |||
1930 | pid = task_pid(current); | 1954 | pid = task_pid(current); |
1931 | type = PIDTYPE_PID; | 1955 | type = PIDTYPE_PID; |
1932 | } | 1956 | } |
1957 | get_pid(pid); | ||
1933 | spin_unlock_irqrestore(&tty->ctrl_lock, flags); | 1958 | spin_unlock_irqrestore(&tty->ctrl_lock, flags); |
1934 | retval = __f_setown(filp, pid, type, 0); | 1959 | retval = __f_setown(filp, pid, type, 0); |
1960 | put_pid(pid); | ||
1935 | if (retval) | 1961 | if (retval) |
1936 | goto out; | 1962 | goto out; |
1937 | } else { | 1963 | } else { |
@@ -2005,7 +2031,7 @@ static int tiocgwinsz(struct tty_struct *tty, struct winsize __user *arg) | |||
2005 | * @rows: rows (character) | 2031 | * @rows: rows (character) |
2006 | * @cols: cols (character) | 2032 | * @cols: cols (character) |
2007 | * | 2033 | * |
2008 | * Update the termios variables and send the neccessary signals to | 2034 | * Update the termios variables and send the necessary signals to |
2009 | * peform a terminal resize correctly | 2035 | * peform a terminal resize correctly |
2010 | */ | 2036 | */ |
2011 | 2037 | ||
@@ -2317,9 +2343,7 @@ static int tiocsetd(struct tty_struct *tty, int __user *p) | |||
2317 | if (get_user(ldisc, p)) | 2343 | if (get_user(ldisc, p)) |
2318 | return -EFAULT; | 2344 | return -EFAULT; |
2319 | 2345 | ||
2320 | lock_kernel(); | ||
2321 | ret = tty_set_ldisc(tty, ldisc); | 2346 | ret = tty_set_ldisc(tty, ldisc); |
2322 | unlock_kernel(); | ||
2323 | 2347 | ||
2324 | return ret; | 2348 | return ret; |
2325 | } | 2349 | } |