• L
    tty: avoid using vfs_iocb_iter_write() for redirected console writes · 2037cd7d
    Linus Torvalds 提交于
    stable inclusion
    from stable-5.10.13
    commit 8fe07159fc53d8103da4ca9899be782ec478692f
    bugzilla: 47995
    
    --------------------------------
    
    commit a9cbbb80 upstream.
    
    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
    9bb48c82 ("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: 9bb48c82 ("tty: implement write_iter")
    Reported-and-tested-by: NHans de Goede <hdegoede@redhat.com>
    Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Cc: stable@kernel.org
    Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
    Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
    Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
    2037cd7d
tty_io.c 85.4 KB