Skip to content

Commit

Permalink
tty: Prevent tty teardown during tty_write_message()
Browse files Browse the repository at this point in the history
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 <peter@hurleysoftware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Peter Hurley authored and Greg Kroah-Hartman committed Oct 18, 2015
1 parent 1e86b5b commit 4b41b95
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions drivers/tty/tty_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4b41b95

Please sign in to comment.