]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.19/vt-fbcon-deinitialize-resources-in-visual_init-after-failed-memory-allocation.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / queue-4.19 / vt-fbcon-deinitialize-resources-in-visual_init-after-failed-memory-allocation.patch
1 From a1ad1cc9704f64c169261a76e1aee1cf1ae51832 Mon Sep 17 00:00:00 2001
2 From: Grzegorz Halat <ghalat@redhat.com>
3 Date: Fri, 26 Apr 2019 16:59:46 +0200
4 Subject: vt/fbcon: deinitialize resources in visual_init() after failed memory allocation
5
6 From: Grzegorz Halat <ghalat@redhat.com>
7
8 commit a1ad1cc9704f64c169261a76e1aee1cf1ae51832 upstream.
9
10 After memory allocation failure vc_allocate() doesn't clean up data
11 which has been initialized in visual_init(). In case of fbcon this
12 leads to divide-by-0 in fbcon_init() on next open of the same tty.
13
14 memory allocation in vc_allocate() may fail here:
15 1097: vc->vc_screenbuf = kzalloc(vc->vc_screenbuf_size, GFP_KERNEL);
16
17 on next open() fbcon_init() skips vc_font.data initialization:
18 1088: if (!p->fontdata) {
19
20 division by zero in fbcon_init() happens here:
21 1149: new_cols /= vc->vc_font.width;
22
23 Additional check is needed in fbcon_deinit() to prevent
24 usage of uninitialized vc_screenbuf:
25
26 1251: if (vc->vc_hi_font_mask && vc->vc_screenbuf)
27 1252: set_vc_hi_font(vc, false);
28
29 Crash:
30
31 #6 [ffffc90001eafa60] divide_error at ffffffff81a00be4
32 [exception RIP: fbcon_init+463]
33 RIP: ffffffff814b860f RSP: ffffc90001eafb18 RFLAGS: 00010246
34 ...
35 #7 [ffffc90001eafb60] visual_init at ffffffff8154c36e
36 #8 [ffffc90001eafb80] vc_allocate at ffffffff8154f53c
37 #9 [ffffc90001eafbc8] con_install at ffffffff8154f624
38 ...
39
40 Signed-off-by: Grzegorz Halat <ghalat@redhat.com>
41 Reviewed-by: Oleksandr Natalenko <oleksandr@redhat.com>
42 Acked-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
43 Cc: stable <stable@vger.kernel.org>
44 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
45
46 ---
47 drivers/tty/vt/vt.c | 11 +++++++++--
48 drivers/video/fbdev/core/fbcon.c | 2 +-
49 2 files changed, 10 insertions(+), 3 deletions(-)
50
51 --- a/drivers/tty/vt/vt.c
52 +++ b/drivers/tty/vt/vt.c
53 @@ -1059,6 +1059,13 @@ static void visual_init(struct vc_data *
54 vc->vc_screenbuf_size = vc->vc_rows * vc->vc_size_row;
55 }
56
57 +
58 +static void visual_deinit(struct vc_data *vc)
59 +{
60 + vc->vc_sw->con_deinit(vc);
61 + module_put(vc->vc_sw->owner);
62 +}
63 +
64 int vc_allocate(unsigned int currcons) /* return 0 on success */
65 {
66 struct vt_notifier_param param;
67 @@ -1106,6 +1113,7 @@ int vc_allocate(unsigned int currcons) /
68
69 return 0;
70 err_free:
71 + visual_deinit(vc);
72 kfree(vc);
73 vc_cons[currcons].d = NULL;
74 return -ENOMEM;
75 @@ -1334,9 +1342,8 @@ struct vc_data *vc_deallocate(unsigned i
76 param.vc = vc = vc_cons[currcons].d;
77 atomic_notifier_call_chain(&vt_notifier_list, VT_DEALLOCATE, &param);
78 vcs_remove_sysfs(currcons);
79 - vc->vc_sw->con_deinit(vc);
80 + visual_deinit(vc);
81 put_pid(vc->vt_pid);
82 - module_put(vc->vc_sw->owner);
83 vc_uniscr_set(vc, NULL);
84 kfree(vc->vc_screenbuf);
85 vc_cons[currcons].d = NULL;
86 --- a/drivers/video/fbdev/core/fbcon.c
87 +++ b/drivers/video/fbdev/core/fbcon.c
88 @@ -1237,7 +1237,7 @@ finished:
89 if (free_font)
90 vc->vc_font.data = NULL;
91
92 - if (vc->vc_hi_font_mask)
93 + if (vc->vc_hi_font_mask && vc->vc_screenbuf)
94 set_vc_hi_font(vc, false);
95
96 if (!con_is_bound(&fb_con))