]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
fbdev: core: fbcvt: avoid division by 0 in fb_cvt_hperiod()
authorSergey Shtylyov <s.shtylyov@omp.ru>
Wed, 14 May 2025 20:35:58 +0000 (23:35 +0300)
committerHelge Deller <deller@gmx.de>
Sat, 31 May 2025 08:24:02 +0000 (10:24 +0200)
In fb_find_mode_cvt(), iff mode->refresh somehow happens to be 0x80000000,
cvt.f_refresh will become 0 when multiplying it by 2 due to overflow. It's
then passed to fb_cvt_hperiod(), where it's used as a divider -- division
by 0 will result in kernel oops. Add a sanity check for cvt.f_refresh to
avoid such overflow...

Found by Linux Verification Center (linuxtesting.org) with the Svace static
analysis tool.

Fixes: 96fe6a2109db ("[PATCH] fbdev: Add VESA Coordinated Video Timings (CVT) support")
Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>
Signed-off-by: Helge Deller <deller@gmx.de>
drivers/video/fbdev/core/fbcvt.c

index 64843464c66135b4c5c083418c8c89ae237f052a..cd3821bd82e566ed906cab1b68a3066e17235c87 100644 (file)
@@ -312,7 +312,7 @@ int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int rb)
        cvt.f_refresh = cvt.refresh;
        cvt.interlace = 1;
 
-       if (!cvt.xres || !cvt.yres || !cvt.refresh) {
+       if (!cvt.xres || !cvt.yres || !cvt.refresh || cvt.f_refresh > INT_MAX) {
                printk(KERN_INFO "fbcvt: Invalid input parameters\n");
                return 1;
        }