summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorJiri Slaby <jslaby@suse.cz>2022-07-07 11:25:58 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-07-29 18:19:28 +0300
commit08afa87f58d83dfe040572ed591b47e8cb9e225c (patch)
tree0835155e1b0c06ce9abfbbe74c7d280c0b26fc3a /include
parenta4bb7ef2d6f6d7158539f95b2fa97d658ea3cf75 (diff)
downloadlinux-08afa87f58d83dfe040572ed591b47e8cb9e225c.tar.xz
tty: use new tty_insert_flip_string_and_push_buffer() in pty_write()
commit a501ab75e7624d133a5a3c7ec010687c8b961d23 upstream. There is a race in pty_write(). pty_write() can be called in parallel with e.g. ioctl(TIOCSTI) or ioctl(TCXONC) which also inserts chars to the buffer. Provided, tty_flip_buffer_push() in pty_write() is called outside the lock, it can commit inconsistent tail. This can lead to out of bounds writes and other issues. See the Link below. To fix this, we have to introduce a new helper called tty_insert_flip_string_and_push_buffer(). It does both tty_insert_flip_string() and tty_flip_buffer_commit() under the port lock. It also calls queue_work(), but outside the lock. See 71a174b39f10 (pty: do tty_flip_buffer_push without port->lock in pty_write) for the reasons. Keep the helper internal-only (in drivers' tty.h). It is not intended to be used widely. Link: https://seclists.org/oss-sec/2022/q2/155 Fixes: 71a174b39f10 (pty: do tty_flip_buffer_push without port->lock in pty_write) Cc: 一只狗 <chennbnbnb@gmail.com> Cc: Dan Carpenter <dan.carpenter@oracle.com> Suggested-by: Hillf Danton <hdanton@sina.com> Signed-off-by: Jiri Slaby <jslaby@suse.cz> Link: https://lore.kernel.org/r/20220707082558.9250-2-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'include')
-rw-r--r--include/linux/tty_flip.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/include/linux/tty_flip.h b/include/linux/tty_flip.h
index e183f74b19a0..c326bfdb5ec2 100644
--- a/include/linux/tty_flip.h
+++ b/include/linux/tty_flip.h
@@ -39,4 +39,7 @@ static inline int tty_insert_flip_string(struct tty_port *port,
extern void tty_buffer_lock_exclusive(struct tty_port *port);
extern void tty_buffer_unlock_exclusive(struct tty_port *port);
+int tty_insert_flip_string_and_push_buffer(struct tty_port *port,
+ const unsigned char *chars, size_t cnt);
+
#endif /* _LINUX_TTY_FLIP_H */