[Devel] [PATCH RHEL7 COMMIT] ms/tty: Invert tty_lock/ldisc_sem lock order

Konstantin Khorenko khorenko at virtuozzo.com
Fri Jan 29 06:49:15 PST 2016


The commit is pushed to "branch-rh7-3.10.0-327.3.1-vz7.10.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-327.3.1.vz7.10.8
------>
commit ab9f5d42ce7c9c35e7e2e9066f7873a0a9f889a1
Author: Cyrill Gorcunov <gorcunov at virtuozzo.com>
Date:   Fri Jan 29 18:49:15 2016 +0400

    ms/tty: Invert tty_lock/ldisc_sem lock order
    
    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>
---
 drivers/tty/tty_ldisc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
index d389c82..d1b8ef5 100644
--- a/drivers/tty/tty_ldisc.c
+++ b/drivers/tty/tty_ldisc.c
@@ -524,9 +524,11 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
 	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, int ldisc)
 	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, int ldisc)
 	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