linux-stable/drivers/tty/vt
Grzegorz Halat ff818b449a vt/fbcon: deinitialize resources in visual_init() after failed memory allocation
commit a1ad1cc970 upstream.

After memory allocation failure vc_allocate() doesn't clean up data
which has been initialized in visual_init(). In case of fbcon this
leads to divide-by-0 in fbcon_init() on next open of the same tty.

memory allocation in vc_allocate() may fail here:
1097:     vc->vc_screenbuf = kzalloc(vc->vc_screenbuf_size, GFP_KERNEL);

on next open() fbcon_init() skips vc_font.data initialization:
1088:     if (!p->fontdata) {

division by zero in fbcon_init() happens here:
1149:     new_cols /= vc->vc_font.width;

Additional check is needed in fbcon_deinit() to prevent
usage of uninitialized vc_screenbuf:

1251:        if (vc->vc_hi_font_mask && vc->vc_screenbuf)
1252:                set_vc_hi_font(vc, false);

Crash:

 #6 [ffffc90001eafa60] divide_error at ffffffff81a00be4
    [exception RIP: fbcon_init+463]
    RIP: ffffffff814b860f  RSP: ffffc90001eafb18  RFLAGS: 00010246
...
 #7 [ffffc90001eafb60] visual_init at ffffffff8154c36e
 #8 [ffffc90001eafb80] vc_allocate at ffffffff8154f53c
 #9 [ffffc90001eafbc8] con_install at ffffffff8154f624
...

Signed-off-by: Grzegorz Halat <ghalat@redhat.com>
Reviewed-by: Oleksandr Natalenko <oleksandr@redhat.com>
Acked-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-06-09 09:17:21 +02:00
..
.gitignore
consolemap.c treewide: kmalloc() -> kmalloc_array() 2018-06-12 16:19:22 -07:00
cp437.uni
defkeymap.c_shipped
defkeymap.map
keyboard.c tty/vt: fix write/write race in ioctl(KDSKBSENT) handler 2019-05-22 07:37:41 +02:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
selection.c vt: selection: take screen contents from uniscr if available 2018-07-21 09:18:27 +02:00
vc_screen.c vt: unicode fallback for scrollback 2018-06-28 21:38:12 +09:00
vt.c vt/fbcon: deinitialize resources in visual_init() after failed memory allocation 2019-06-09 09:17:21 +02:00
vt_ioctl.c tty: vt_ioctl: fix potential Spectre v1 2018-09-18 15:51:30 +02:00