]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commit
tty: improve tty_insert_flip_char() fast path
authorArnd Bergmann <arnd@arndb.de>
Tue, 20 Jun 2017 21:10:41 +0000 (23:10 +0200)
committerThadeu Lima de Souza Cascardo <cascardo@canonical.com>
Thu, 5 Oct 2017 17:56:21 +0000 (14:56 -0300)
commit9eeee6f56d3ff7386e4824dcd67e2f70a2c85d94
tree5947ea4319f80025547bd840ac04c1b68cb834d8
parent1731176807330afa5c824413020bc488c71dab60
tty: improve tty_insert_flip_char() fast path

BugLink: http://bugs.launchpad.net/bugs/1721477
commit 979990c6284814617d8f2179d197f72ff62b5d85 upstream.

kernelci.org reports a crazy stack usage for the VT code when CONFIG_KASAN
is enabled:

drivers/tty/vt/keyboard.c: In function 'kbd_keycode':
drivers/tty/vt/keyboard.c:1452:1: error: the frame size of 2240 bytes is larger than 2048 bytes [-Werror=frame-larger-than=]

The problem is that tty_insert_flip_char() gets inlined many times into
kbd_keycode(), and also into other functions, and each copy requires 128
bytes for stack redzone to check for a possible out-of-bounds access on
the 'ch' and 'flags' arguments that are passed into
tty_insert_flip_string_flags as a variable-length string.

This introduces a new __tty_insert_flip_char() function for the slow
path, which receives the two arguments by value. This completely avoids
the problem and the stack usage goes back down to around 100 bytes.

Without KASAN, this is also slightly better, as we don't have to
spill the arguments to the stack but can simply pass 'ch' and 'flag'
in registers, saving a few bytes in .text for each call site.

This should be backported to linux-4.0 or later, which first introduced
the stack sanitizer in the kernel.

Fixes: c420f167db8c ("kasan: enable stack instrumentation")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
drivers/tty/tty_buffer.c
include/linux/tty_flip.h