Skip to contentSkip to conversation

drm/fb-helper: add virtual screen size check to drm_fb_helper_check_var()

PATCH Superseded Andrey Strachuk 2 participants 2 messages Aug 11, 2022

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/fb-helper: add virtual screen size check to drm_fb_helper_check_var()

Add virtual screen size check to drm_fb_helper_check_var() in order to validate userspace input.

Found by Linux Verification Center (linuxtesting.org) with syzkaller.

Fixes 6c11df58fd1a ("fbmem: Check virtual screen sizes in fb_set_var()")
---
 drivers/gpu/drm/drm_fb_helper.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/gpu/drm/drm_fb_helper.c +10 -0
index 2d4cee6a10ff..d21fe89358af 100644
@@ -1355,6 +1355,16 @@ int drm_fb_helper_check_var(struct fb_var_screeninfo *var,
 	    (drm_format_info_block_height(fb->format, 0) > 1))
 		return -EINVAL;
 
+	/* verify that virtual resolution >= physical resolution */
+	if (var->xres_virtual < var->xres ||
+	    var->yres_virtual < var->yres) {
+		drm_dbg_kms(dev, "requested virtual screen size that is "
+				"below the physical size(%ux%u vs. %ux%u)\n",
+			var->xres_virtual, var->yres_virtual,
+			var->xres, var->yres);
+		return -EINVAL;
+	}
+
 	/*
 	 * Changes struct fb_var_screeninfo are currently not pushed back
 	 * to KMS, hence fail if different settings are requested.
Signature · 1 line
2.25.1
#1 lore raw

Hi Andrey,

Quoted 6 lines · Andrey Strachuk

Add virtual screen size check to drm_fb_helper_check_var() in order to validate userspace input.

Found by Linux Verification Center (linuxtesting.org) with syzkaller.

Thanks for your patch!

Quoted 1 line
Fixes 6c11df58fd1a ("fbmem: Check virtual screen sizes in fb_set_var()")

This Fixes tag is misleading: the bug has existed since basically forever.

Quoted 4 lines
drivers/gpu/drm/drm_fb_helper.c +0 -0
@@ -1355,6 +1355,16 @@ int drm_fb_helper_check_var(struct fb_var_screeninfo *var,
            (drm_format_info_block_height(fb->format, 0) > 1))

drivers/gpu/drm/drm_fb_helper.c int drm_fb_helper_check_var(struct fb_var_screeninfo *var, · line 1365

Quoted 10 lines
drivers/gpu/drm/drm_fb_helper.c +8 -0
                return -EINVAL;
 
+       /* verify that virtual resolution >= physical resolution */
+       if (var->xres_virtual < var->xres ||
+           var->yres_virtual < var->yres) {
+               drm_dbg_kms(dev, "requested virtual screen size that is "
+                               "below the physical size(%ux%u vs. %ux%u)\n",
+                       var->xres_virtual, var->yres_virtual,
+                       var->xres, var->yres);
+               return -EINVAL;

According to the fbdev rounding rules, invalid values should be rounded up, if possible. Hence it is better to not return an error, but round up:

    if (var->xres_virtual < var->xres)
            var->xres_virtual = var->xres;
    if (var->yres_virtual < var->yres)
            var->yres_virtual = var->yres;

drivers/gpu/drm/drm_fb_helper.c int drm_fb_helper_check_var(struct fb_var_screeninfo *var, · line 1370

Quoted 5 lines
drivers/gpu/drm/drm_fb_helper.c +2 -0
+       }
+
        /*
         * Changes struct fb_var_screeninfo are currently not pushed back
         * to KMS, hence fail if different settings are requested.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds