aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Hurley <peter@hurleysoftware.com>2014-11-05 12:13:07 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-11-05 21:50:43 -0500
commitfae76e9adfa450f4c2dd5773265eb3c811a9c484 (patch)
tree88f6086470fe19b2299568b24e4b27d8e3c608f7
parente80a10ee4de8f654cf34170da00f989470331da8 (diff)
tty: Fix hung task on pty hangup
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>
-rw-r--r--drivers/tty/tty_ldisc.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
index 5bdc241628ac..1dbe27824220 100644
--- a/drivers/tty/tty_ldisc.c
+++ b/drivers/tty/tty_ldisc.c
@@ -326,6 +326,24 @@ static inline void __tty_ldisc_unlock(struct tty_struct *tty)
326} 326}
327 327
328static int __lockfunc 328static int __lockfunc
329tty_ldisc_lock(struct tty_struct *tty, unsigned long timeout)
330{
331 int ret;
332
333 ret = __tty_ldisc_lock(tty, timeout);
334 if (!ret)
335 return -EBUSY;
336 set_bit(TTY_LDISC_HALTED, &tty->flags);
337 return 0;
338}
339
340static void tty_ldisc_unlock(struct tty_struct *tty)
341{
342 clear_bit(TTY_LDISC_HALTED, &tty->flags);
343 __tty_ldisc_unlock(tty);
344}
345
346static int __lockfunc
329tty_ldisc_lock_pair_timeout(struct tty_struct *tty, struct tty_struct *tty2, 347tty_ldisc_lock_pair_timeout(struct tty_struct *tty, struct tty_struct *tty2,
330 unsigned long timeout) 348 unsigned long timeout)
331{ 349{
@@ -682,7 +700,7 @@ void tty_ldisc_hangup(struct tty_struct *tty)
682 * 700 *
683 * Avoid racing set_ldisc or tty_ldisc_release 701 * Avoid racing set_ldisc or tty_ldisc_release
684 */ 702 */
685 tty_ldisc_lock_pair(tty, tty->link); 703 tty_ldisc_lock(tty, MAX_SCHEDULE_TIMEOUT);
686 704
687 if (tty->ldisc) { 705 if (tty->ldisc) {
688 706
@@ -704,7 +722,7 @@ void tty_ldisc_hangup(struct tty_struct *tty)
704 WARN_ON(tty_ldisc_open(tty, tty->ldisc)); 722 WARN_ON(tty_ldisc_open(tty, tty->ldisc));
705 } 723 }
706 } 724 }
707 tty_ldisc_enable_pair(tty, tty->link); 725 tty_ldisc_unlock(tty);
708 if (reset) 726 if (reset)
709 tty_reset_termios(tty); 727 tty_reset_termios(tty);
710 728