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: 2b022ab754
("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>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
75ddbc1fb1
commit
b9ca5f8560
@@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user