From: Peter Hurley Date: Sun, 11 Oct 2015 00:28:44 +0000 (-0400) Subject: tty: Prevent tty teardown during tty_write_message() X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=4b41b9539a1e9531f942ededfcdcff372317d2e7;p=GitHub%2Fmoto-9609%2Fandroid_kernel_motorola_exynos9610.git tty: Prevent tty teardown during tty_write_message() tty_write_message() allows the caller to directly write to a specific tty. Since the line discipline is bypassed for the direct write, nothing prevents the tty from being torn down after the tty count is checked. Hold the tty lock for the duration of the direct write. Signed-off-by: Peter Hurley Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index 071671a8674f..173fdeba0987 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -1200,11 +1200,9 @@ void tty_write_message(struct tty_struct *tty, char *msg) if (tty) { mutex_lock(&tty->atomic_write_lock); tty_lock(tty); - if (tty->ops->write && tty->count > 0) { - tty_unlock(tty); + if (tty->ops->write && tty->count > 0) tty->ops->write(tty, msg, strlen(msg)); - } else - tty_unlock(tty); + tty_unlock(tty); tty_write_unlock(tty); } return;