Merge branch 'master' of git://git.infradead.org/users/pcmoore/selinux into ra-next
[firefly-linux-kernel-4.4.55.git] / drivers / tty / tty_io.c
index 0fa5db4c7a7a9614d055457649f9add9493d95b3..3a1a01af9a805b38b05f1833eefa80400072f4f4 100644 (file)
@@ -604,7 +604,7 @@ static int tty_signal_session_leader(struct tty_struct *tty, int exit_session)
  *               redirect lock for undoing redirection
  *               file list lock for manipulating list of ttys
  *               tty_ldiscs_lock from called functions
- *               termios_mutex resetting termios data
+ *               termios_rwsem resetting termios data
  *               tasklist_lock to walk task list for hangup event
  *                 ->siglock to protect ->signal/->sighand
  */
@@ -629,6 +629,11 @@ static void __tty_hangup(struct tty_struct *tty, int exit_session)
 
        tty_lock(tty);
 
+       if (test_bit(TTY_HUPPED, &tty->flags)) {
+               tty_unlock(tty);
+               return;
+       }
+
        /* some functions below drop BTM, so we need this bit */
        set_bit(TTY_HUPPING, &tty->flags);
 
@@ -664,7 +669,6 @@ static void __tty_hangup(struct tty_struct *tty, int exit_session)
 
        spin_lock_irq(&tty->ctrl_lock);
        clear_bit(TTY_THROTTLED, &tty->flags);
-       clear_bit(TTY_PUSH, &tty->flags);
        clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
        put_pid(tty->session);
        put_pid(tty->pgrp);
@@ -850,7 +854,8 @@ void disassociate_ctty(int on_exit)
                        struct pid *tty_pgrp = tty_get_pgrp(tty);
                        if (tty_pgrp) {
                                kill_pgrp(tty_pgrp, SIGHUP, on_exit);
-                               kill_pgrp(tty_pgrp, SIGCONT, on_exit);
+                               if (!on_exit)
+                                       kill_pgrp(tty_pgrp, SIGCONT, on_exit);
                                put_pid(tty_pgrp);
                        }
                }
@@ -2230,7 +2235,7 @@ static int tiocsti(struct tty_struct *tty, char __user *p)
  *
  *     Copies the kernel idea of the window size into the user buffer.
  *
- *     Locking: tty->termios_mutex is taken to ensure the winsize data
+ *     Locking: tty->winsize_mutex is taken to ensure the winsize data
  *             is consistent.
  */
 
@@ -2238,9 +2243,9 @@ static int tiocgwinsz(struct tty_struct *tty, struct winsize __user *arg)
 {
        int err;
 
-       mutex_lock(&tty->termios_mutex);
+       mutex_lock(&tty->winsize_mutex);
        err = copy_to_user(arg, &tty->winsize, sizeof(*arg));
-       mutex_unlock(&tty->termios_mutex);
+       mutex_unlock(&tty->winsize_mutex);
 
        return err ? -EFAULT: 0;
 }
@@ -2261,7 +2266,7 @@ int tty_do_resize(struct tty_struct *tty, struct winsize *ws)
        unsigned long flags;
 
        /* Lock the tty */
-       mutex_lock(&tty->termios_mutex);
+       mutex_lock(&tty->winsize_mutex);
        if (!memcmp(ws, &tty->winsize, sizeof(*ws)))
                goto done;
        /* Get the PID values and reference them so we can
@@ -2276,7 +2281,7 @@ int tty_do_resize(struct tty_struct *tty, struct winsize *ws)
 
        tty->winsize = *ws;
 done:
-       mutex_unlock(&tty->termios_mutex);
+       mutex_unlock(&tty->winsize_mutex);
        return 0;
 }
 EXPORT_SYMBOL(tty_do_resize);
@@ -3015,7 +3020,9 @@ void initialize_tty_struct(struct tty_struct *tty,
        tty->session = NULL;
        tty->pgrp = NULL;
        mutex_init(&tty->legacy_mutex);
-       mutex_init(&tty->termios_mutex);
+       mutex_init(&tty->throttle_mutex);
+       init_rwsem(&tty->termios_rwsem);
+       mutex_init(&tty->winsize_mutex);
        init_ldsem(&tty->ldisc_sem);
        init_waitqueue_head(&tty->write_wait);
        init_waitqueue_head(&tty->read_wait);