[Devel] [PATCH rh7 3.10] tty: Invert tty_lock/ldisc_sem lock order

Cyrill Gorcunov gorcunov at virtuozzo.com
Fri Jan 29 05:24:07 PST 2016


ML: c8483bc9deff9bf9118aaab2e840b973b75cac3e

From: Peter Hurley <peter at hurleysoftware.com>
Date: Wed, 5 Nov 2014 12:12:45 -0500

Dropping the tty lock to acquire the tty->ldisc_sem allows several
race conditions (such as hangup while changing the ldisc) which requires
extra states and testing. The ldisc_sem->tty_lock lock order has
not been required since tty buffer ownership was moved to tty_port.

Reviewed-by: Alan Cox <alan at linux.intel.com>
Signed-off-by: Peter Hurley <peter at hurleysoftware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh at linuxfoundation.org>

https://jira.sw.ru/browse/PSBM-43454

Signed-off-by: Cyrill Gorcunov <gorcunov at virtuozzo.com>
CC: Vladimir Davydov <vdavydov at virtuozzo.com>
CC: Konstantin Khorenko <khorenko at virtuozzo.com>
---

Kostya, it's an addition to PSBM-43454.

 drivers/tty/tty_ldisc.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Index: linux-pcs7.git/drivers/tty/tty_ldisc.c
===================================================================
--- linux-pcs7.git.orig/drivers/tty/tty_ldisc.c
+++ linux-pcs7.git/drivers/tty/tty_ldisc.c
@@ -524,9 +524,11 @@ int tty_set_ldisc(struct tty_struct *tty
 	if (IS_ERR(new_ldisc))
 		return PTR_ERR(new_ldisc);
 
+	tty_lock(tty);
 	retval = tty_ldisc_lock_pair_timeout(tty, o_tty, 5 * HZ);
 	if (retval) {
 		tty_ldisc_put(new_ldisc);
+		tty_unlock(tty);
 		return retval;
 	}
 
@@ -537,6 +539,7 @@ int tty_set_ldisc(struct tty_struct *tty
 	if (tty->ldisc->ops->num == ldisc) {
 		tty_ldisc_enable_pair(tty, o_tty);
 		tty_ldisc_put(new_ldisc);
+		tty_unlock(tty);
 		return 0;
 	}
 
@@ -544,7 +547,6 @@ int tty_set_ldisc(struct tty_struct *tty
 	tty->receive_room = 0;
 
 	o_ldisc = tty->ldisc;
-	tty_lock(tty);
 
 	/* FIXME: for testing only */
 	WARN_ON(test_bit(TTY_HUPPED, &tty->flags));


More information about the Devel mailing list