tty: avoid using vfs_iocb_iter_write() for redirected console writes
authorLinus Torvalds <torvalds@linux-foundation.org>
Fri, 29 Jan 2021 20:28:20 +0000 (12:28 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 29 Jan 2021 21:12:17 +0000 (13:12 -0800)
commita9cbbb80e3e7dd38ceac166e0698f161862a18ae
tree2567f5c3ee01e89af561811f34aa81b938d91606
parentbec4c2968fce2f44ce62d05288a633cd99a722eb
tty: avoid using vfs_iocb_iter_write() for redirected console writes

It turns out that the vfs_iocb_iter_{read,write}() functions are
entirely broken, and don't actually use the passed-in file pointer for
IO - only for the preparatory work (permission checking and for the
write_iter function lookup).

That worked fine for overlayfs, which always builds the new iocb with
the same file pointer that it passes in, but in the general case it ends
up doing nonsensical things (and could cause an iterator call that
doesn't even match the passed-in file pointer).

This subtly broke the tty conversion to write_iter in commit
9bb48c82aced ("tty: implement write_iter"), because the console
redirection didn't actually end up redirecting anything, since the
passed-in file pointer was basically ignored, and the actual write was
done with the original non-redirected console tty after all.

The main visible effect of this is that the console messages were no
longer logged to /var/log/boot.log during graphical boot.

Fix the issue by simply not using the vfs write "helper" function at
all, and just redirecting the write entirely internally to the tty
layer.  Do the target writability permission checks when actually
registering the target tty with TIOCCONS instead of at write time.

Fixes: 9bb48c82aced ("tty: implement write_iter")
Reported-and-tested-by: Hans de Goede <hdegoede@redhat.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: stable@kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/tty/tty_io.c