summaryrefslogtreecommitdiffstats
path: root/drivers/tty/tty_io.c
diff options
context:
space:
mode:
authorSahara <keun-o.park@darkmatter.ae>2019-02-11 11:09:15 +0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-03-28 01:28:23 +0900
commitb9ca5f8560af244489b4a1bc1ae88b341f24bc95 (patch)
tree2fa81b283d5ff446fe29cf26aea8b6c05db22479 /drivers/tty/tty_io.c
parent75ddbc1fb11efac87b611d48e9802f6fe2bb2163 (diff)
downloadlinux-b9ca5f8560af244489b4a1bc1ae88b341f24bc95.tar.gz
linux-b9ca5f8560af244489b4a1bc1ae88b341f24bc95.tar.bz2
linux-b9ca5f8560af244489b4a1bc1ae88b341f24bc95.zip
tty: pty: Fix race condition between release_one_tty and pty_write
Especially when a linked tty is used such as pty, the linked tty port's buf works have not been cancelled while master tty port's buf work has been cancelled. Since release_one_tty and flush_to_ldisc run in workqueue threads separately, when pty_cleanup happens and link tty port is freed, flush_to_ldisc tries to access freed port and port->itty, eventually it causes a panic. This patch utilizes the magic value with holding the tty_mutex to check if the tty->link is valid. Fixes: 2b022ab7542d ("pty: cancel pty slave port buf's work in tty_release") Signed-off-by: Sahara <keun-o.park@darkmatter.ae> Cc: stable <stable@vger.kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty/tty_io.c')
-rw-r--r--drivers/tty/tty_io.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 5fa250157025..c27777f3b8c4 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -1448,10 +1448,13 @@ static void release_one_tty(struct work_struct *work)
struct tty_driver *driver = tty->driver;
struct module *owner = driver->owner;
+ mutex_lock(&tty_mutex);
if (tty->ops->cleanup)
tty->ops->cleanup(tty);
tty->magic = 0;
+ mutex_unlock(&tty_mutex);
+
tty_driver_kref_put(driver);
module_put(owner);