diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2021-02-20 21:15:00 -0800 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2021-02-23 13:55:57 +0100 |
commit | 312ed553b12d333afedc3a2636867ae769ccaeb3 (patch) | |
tree | 58fb22a432be2286a4dc561441395bb56815219f | |
parent | 1ef2744ab96362188ec61b5f9243161bab462126 (diff) |
tty: protect tty_write from odd low-level tty disciplines
commit 3342ff2698e9720f4040cc458a2744b2b32f5c3a 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
9bb48c82aced ("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: 9bb48c82aced ("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>
-rw-r--r-- | drivers/tty/tty_io.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index 816e709afa56..082da38762fc 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -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; |