Skip to content

Commit

Permalink
tty: protect tty_write from odd low-level tty disciplines
Browse files Browse the repository at this point in the history
commit 3342ff2 upstream.

Al root-caused a new warning from syzbot to the ttyprintk tty driver
returning a write count larger than the data the tty layer actually gave
it.  Which confused the tty write code mightily, and with the new
iov_iter based code, caused a WARNING in iov_iter_revert().

syzbot correctly bisected the source of the new warning to commit
9bb48c8 ("tty: implement write_iter"), but the oddity goes back
much further, it just didn't get caught by anything before.

Reported-by: syzbot+3d2c27c2b7dc2a94814d@syzkaller.appspotmail.com
Fixes: 9bb48c8 ("tty: implement write_iter")
Debugged-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
torvalds authored and gregkh committed Feb 23, 2021
1 parent 1ef2744 commit 312ed55
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion drivers/tty/tty_io.c
Expand Up @@ -962,11 +962,14 @@ static inline ssize_t do_tty_write(
if (ret <= 0)
break;

written += ret;
if (ret > size)
break;

/* FIXME! Have Al check this! */
if (ret != size)
iov_iter_revert(from, size-ret);

written += ret;
count -= ret;
if (!count)
break;
Expand Down

0 comments on commit 312ed55

Please sign in to comment.