tty: Fix hung task on pty hangup
authorPeter Hurley <peter@hurleysoftware.com>
Wed, 5 Nov 2014 17:13:07 +0000 (12:13 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 6 Nov 2014 02:50:43 +0000 (18:50 -0800)
When hanging up one end of a pty pair, there may be waiting
readers/writers on the other end which may not exit, preventing
tty_ldisc_lock_pair() from acquiring the other side's ldisc lock.

Only acquire this side's ldisc lock; although this will no longer
prevent the other side from writing new input, that input will not
be processing until after the ldisc hangup is complete.

Reported-by: Sasha Levin <sasha.levin@oracle.com>
Reviewed-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/tty_ldisc.c

index 5bdc241628ac5970c44291f068de70c678137275..1dbe27824220266e1dd23b71bab7f6edadae32d1 100644 (file)
@@ -325,6 +325,24 @@ static inline void __tty_ldisc_unlock(struct tty_struct *tty)
        return ldsem_up_write(&tty->ldisc_sem);
 }
 
+static int __lockfunc
+tty_ldisc_lock(struct tty_struct *tty, unsigned long timeout)
+{
+       int ret;
+
+       ret = __tty_ldisc_lock(tty, timeout);
+       if (!ret)
+               return -EBUSY;
+       set_bit(TTY_LDISC_HALTED, &tty->flags);
+       return 0;
+}
+
+static void tty_ldisc_unlock(struct tty_struct *tty)
+{
+       clear_bit(TTY_LDISC_HALTED, &tty->flags);
+       __tty_ldisc_unlock(tty);
+}
+
 static int __lockfunc
 tty_ldisc_lock_pair_timeout(struct tty_struct *tty, struct tty_struct *tty2,
                            unsigned long timeout)
@@ -682,7 +700,7 @@ void tty_ldisc_hangup(struct tty_struct *tty)
         *
         * Avoid racing set_ldisc or tty_ldisc_release
         */
-       tty_ldisc_lock_pair(tty, tty->link);
+       tty_ldisc_lock(tty, MAX_SCHEDULE_TIMEOUT);
 
        if (tty->ldisc) {
 
@@ -704,7 +722,7 @@ void tty_ldisc_hangup(struct tty_struct *tty)
                        WARN_ON(tty_ldisc_open(tty, tty->ldisc));
                }
        }
-       tty_ldisc_enable_pair(tty, tty->link);
+       tty_ldisc_unlock(tty);
        if (reset)
                tty_reset_termios(tty);
 
This page took 0.027178 seconds and 5 git commands to generate.