]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-6.1/fbmon-prevent-division-by-zero-in-fb_videomode_from_.patch
Fixes for 6.1
[thirdparty/kernel/stable-queue.git] / queue-6.1 / fbmon-prevent-division-by-zero-in-fb_videomode_from_.patch
1 From fe6a7d6bdb5004c5b5e57e94be16d60769df9473 Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Tue, 19 Mar 2024 11:13:44 +0300
4 Subject: fbmon: prevent division by zero in fb_videomode_from_videomode()
5
6 From: Roman Smirnov <r.smirnov@omp.ru>
7
8 [ Upstream commit c2d953276b8b27459baed1277a4fdd5dd9bd4126 ]
9
10 The expression htotal * vtotal can have a zero value on
11 overflow. It is necessary to prevent division by zero like in
12 fb_var_to_videomode().
13
14 Found by Linux Verification Center (linuxtesting.org) with Svace.
15
16 Signed-off-by: Roman Smirnov <r.smirnov@omp.ru>
17 Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>
18 Signed-off-by: Helge Deller <deller@gmx.de>
19 Signed-off-by: Sasha Levin <sashal@kernel.org>
20 ---
21 drivers/video/fbdev/core/fbmon.c | 7 ++++---
22 1 file changed, 4 insertions(+), 3 deletions(-)
23
24 diff --git a/drivers/video/fbdev/core/fbmon.c b/drivers/video/fbdev/core/fbmon.c
25 index b0e690f41025a..9ca99da3a56a0 100644
26 --- a/drivers/video/fbdev/core/fbmon.c
27 +++ b/drivers/video/fbdev/core/fbmon.c
28 @@ -1311,7 +1311,7 @@ int fb_get_mode(int flags, u32 val, struct fb_var_screeninfo *var, struct fb_inf
29 int fb_videomode_from_videomode(const struct videomode *vm,
30 struct fb_videomode *fbmode)
31 {
32 - unsigned int htotal, vtotal;
33 + unsigned int htotal, vtotal, total;
34
35 fbmode->xres = vm->hactive;
36 fbmode->left_margin = vm->hback_porch;
37 @@ -1344,8 +1344,9 @@ int fb_videomode_from_videomode(const struct videomode *vm,
38 vtotal = vm->vactive + vm->vfront_porch + vm->vback_porch +
39 vm->vsync_len;
40 /* prevent division by zero */
41 - if (htotal && vtotal) {
42 - fbmode->refresh = vm->pixelclock / (htotal * vtotal);
43 + total = htotal * vtotal;
44 + if (total) {
45 + fbmode->refresh = vm->pixelclock / total;
46 /* a mode must have htotal and vtotal != 0 or it is invalid */
47 } else {
48 fbmode->refresh = 0;
49 --
50 2.43.0
51