]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.4/fbdev-fix-divide-error-in-fb_var_to_videomode.patch
drop drm-rockchip-shutdown-drm-subsystem-on-shutdown.patch from 4.4.y and 4.9.y
[thirdparty/kernel/stable-queue.git] / queue-4.4 / fbdev-fix-divide-error-in-fb_var_to_videomode.patch
1 From cf84807f6dd0be5214378e66460cfc9187f532f9 Mon Sep 17 00:00:00 2001
2 From: Shile Zhang <shile.zhang@linux.alibaba.com>
3 Date: Mon, 1 Apr 2019 17:47:00 +0200
4 Subject: fbdev: fix divide error in fb_var_to_videomode
5
6 From: Shile Zhang <shile.zhang@linux.alibaba.com>
7
8 commit cf84807f6dd0be5214378e66460cfc9187f532f9 upstream.
9
10 To fix following divide-by-zero error found by Syzkaller:
11
12 divide error: 0000 [#1] SMP PTI
13 CPU: 7 PID: 8447 Comm: test Kdump: loaded Not tainted 4.19.24-8.al7.x86_64 #1
14 Hardware name: Alibaba Cloud Alibaba Cloud ECS, BIOS rel-1.12.0-0-ga698c8995f-prebuilt.qemu.org 04/01/2014
15 RIP: 0010:fb_var_to_videomode+0xae/0xc0
16 Code: 04 44 03 46 78 03 4e 7c 44 03 46 68 03 4e 70 89 ce d1 ee 69 c0 e8 03 00 00 f6 c2 01 0f 45 ce 83 e2 02 8d 34 09 0f 45 ce 31 d2 <41> f7 f0 31 d2 f7 f1 89 47 08 f3 c3 66 0f 1f 44 00 00 0f 1f 44 00
17 RSP: 0018:ffffb7e189347bf0 EFLAGS: 00010246
18 RAX: 00000000e1692410 RBX: ffffb7e189347d60 RCX: 0000000000000000
19 RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffffb7e189347c10
20 RBP: ffff99972a091c00 R08: 0000000000000000 R09: 0000000000000000
21 R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000100
22 R13: 0000000000010000 R14: 00007ffd66baf6d0 R15: 0000000000000000
23 FS: 00007f2054d11740(0000) GS:ffff99972fbc0000(0000) knlGS:0000000000000000
24 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
25 CR2: 00007f205481fd20 CR3: 00000004288a0001 CR4: 00000000001606a0
26 Call Trace:
27 fb_set_var+0x257/0x390
28 ? lookup_fast+0xbb/0x2b0
29 ? fb_open+0xc0/0x140
30 ? chrdev_open+0xa6/0x1a0
31 do_fb_ioctl+0x445/0x5a0
32 do_vfs_ioctl+0x92/0x5f0
33 ? __alloc_fd+0x3d/0x160
34 ksys_ioctl+0x60/0x90
35 __x64_sys_ioctl+0x16/0x20
36 do_syscall_64+0x5b/0x190
37 entry_SYSCALL_64_after_hwframe+0x44/0xa9
38 RIP: 0033:0x7f20548258d7
39 Code: 44 00 00 48 8b 05 b9 15 2d 00 64 c7 00 26 00 00 00 48 c7 c0 ff ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 b8 10 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 89 15 2d 00 f7 d8 64 89 01 48
40
41 It can be triggered easily with following test code:
42
43 #include <linux/fb.h>
44 #include <fcntl.h>
45 #include <sys/ioctl.h>
46 int main(void)
47 {
48 struct fb_var_screeninfo var = {.activate = 0x100, .pixclock = 60};
49 int fd = open("/dev/fb0", O_RDWR);
50 if (fd < 0)
51 return 1;
52
53 if (ioctl(fd, FBIOPUT_VSCREENINFO, &var))
54 return 1;
55
56 return 0;
57 }
58
59 Signed-off-by: Shile Zhang <shile.zhang@linux.alibaba.com>
60 Cc: Fredrik Noring <noring@nocrew.org>
61 Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
62 Reviewed-by: Mukesh Ojha <mojha@codeaurora.org>
63 Signed-off-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
64 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
65
66 ---
67 drivers/video/fbdev/core/modedb.c | 3 +++
68 1 file changed, 3 insertions(+)
69
70 --- a/drivers/video/fbdev/core/modedb.c
71 +++ b/drivers/video/fbdev/core/modedb.c
72 @@ -933,6 +933,9 @@ void fb_var_to_videomode(struct fb_video
73 if (var->vmode & FB_VMODE_DOUBLE)
74 vtotal *= 2;
75
76 + if (!htotal || !vtotal)
77 + return;
78 +
79 hfreq = pixclock/htotal;
80 mode->refresh = hfreq/vtotal;
81 }