Skip to contentSkip to conversation

fbdev: radeonfb: reject a zero pixclock in radeonfb_check_var()

PATCH In review Helge Deller 3 participants 5 messages Nov 20 – Nov 23

Subsystems (5)
lore
Share & tools
lore

Helge Deller

author maintainer
#0 lore raw

PATCH 1/2 fbdev: radeonfb: reject a zero pixclock in radeonfb_check_var()

From: Jianqiang Zou <[email protected]>

radeonfb_set_par() derives the dot clock from the user supplied struct fb_var_screeninfo:

	dotClock = 1000000000 / pixClock;

where pixClock is copied from mode->pixclock. A zero pixclock bypasses the existing validation and makes the kernel divide by zero in radeonfb_set_par().

The driver does have a check for this: fb_validate_mode() returns -EINVAL when pixclock is 0, but radeon_match_mode() only calls it when the output has no scaler and an EDID-derived mode database is available:

	if (has_rmx == 0 && rinfo->mon1_modedb)
		if (fb_validate_mode(...))
			return -EINVAL;

mon1_modedb is only filled in when an EDID is read, so when no EDID-derived mode database is available the validation is skipped and the invalid mode reaches radeonfb_set_par().

Reject a zero pixclock in radeonfb_check_var() before matching the mode. fb_set_var() calls it on the FBIOPUT_VSCREENINFO path before ->fb_set_par(), so the invalid value is rejected before the mode is applied. This is the same check other fbdev drivers use (i740fb, arkfb, s3fb).

Reproduced on Linux 7.3.0 using a custom QEMU PCI stub device with vendor/device ID 1002:5955; no physical Radeon hardware was used. A single FBIOPUT_VSCREENINFO with pixclock = 0 is enough to trigger the divide error.

---
 drivers/video/fbdev/aty/radeon_base.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/video/fbdev/aty/radeon_base.c +3 -0
index 387bc5f96765..45dd42134e81 100644
@@ -836,6 +836,9 @@ static int radeonfb_check_var (struct fb_var_screeninfo *var, struct fb_info *in
         int nom, den;
 	unsigned int pitch;
 
+	if (!var->pixclock)
+		return -EINVAL;
+
 	if (radeon_match_mode(rinfo, &v, var))
 		return -EINVAL;
 
Signature · 1 line
2.56.1
author maintainer
#1 lore raw

PATCH 2/2 fbcon: Don't drop last logo line if logo is same size as screen

Henri reported a regression that when a custom bootlogo is exactly as big as the screen, a white bar with the size of the font height is displayed at the bottom of the display.

This patch fixes this off-by-one bug, but now -as sashiko-bot noticed- since the logo covers the whole screen there is no area left in which the text can be scrolled. To avoid accesses outside the screen memory simply keep the text area covering the full screen (and possibly overwriting) the full-screen logo.

Fixes 94e6a058b168 ("fbcon: Fix KASAN slab-out-of-bounds Read in fbcon_prepare_logo")
---
 drivers/video/fbdev/core/fbcon.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/video/fbdev/core/fbcon.c +4 -2
index d7890e119dc7..cc311dc0e2e4 100644
@@ -666,7 +666,7 @@ static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
 	logo_height = fb_prepare_logo(info, par->rotate);
 	logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
 	logo_lines = min(logo_lines, rows);
-	logo_lines = min(logo_lines, new_rows - 1);
+	logo_lines = min(logo_lines, new_rows);
 	if (logo_lines <= 0) {
 		logo_lines = 0;
 		logo_shown = FBCON_LOGO_DONTSHOW;
@@ -734,7 +734,9 @@ static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
 		pr_info("fbcon: disable boot-logo (boot-logo bigger than screen).\n");
 	} else {
 		logo_shown = FBCON_LOGO_DRAW;
-		vc->vc_top = logo_lines;
+		/* keep vc_top if logo covers whole screen */
+		if (logo_lines < vc->vc_bottom)
+			vc->vc_top = logo_lines;
 	}
 }
 #endif /* MODULE */
Signature · 1 line
2.56.1
#2 lore raw

Re: [PATCH 2/2] fbcon: Don't drop last logo line if logo is same size as screen

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] fbcon: full-screen boot-logo overwritten by update_region() in fbcon_switch() --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] fbcon: full-screen boot-logo overwritten by update_region() in fbcon_switch()
--

commit 1d5d014858b9e8c6374a333c00292505b2a11f3a
Author: Helge Deller <[email protected]>

fbcon: Don't drop last logo line if logo is same size as screen

This commit allows logo_lines to reach new_rows in fbcon_prepare_logo() so a full-screen boot logo is not truncated by one character row, while keeping vc->vc_top unchanged when logo_lines reaches vc->vc_bottom.

Quoted 14 lines
drivers/video/fbdev/core/fbcon.c +1 -1
index 7720dfc80c165..12a27b520260e 100644
@@ -637,7 +637,7 @@ static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
 	logo_height = fb_prepare_logo(info, par->rotate);
 	logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
 	logo_lines = min(logo_lines, rows);
-	logo_lines = min(logo_lines, new_rows - 1);
+	logo_lines = min(logo_lines, new_rows);
 	if (logo_lines <= 0) {
 		logo_lines = 0;
 		logo_shown = FBCON_LOGO_DONTSHOW;

drivers/video/fbdev/core/fbcon.c static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info, · line 713

Quoted 10 lines
drivers/video/fbdev/core/fbcon.c +3 -1
@@ -705,7 +705,9 @@ static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
 		pr_info("fbcon: disable boot-logo (boot-logo bigger than screen).\n");
 	} else {
 		logo_shown = FBCON_LOGO_DRAW;
-		vc->vc_top = logo_lines;
+		/* keep vc_top if logo covers whole screen */
+		if (logo_lines < vc->vc_bottom)
+			vc->vc_top = logo_lines;
 	}
 }
 #endif /* MODULE */

[Severity: Medium]
When the boot logo covers the whole screen (logo_lines == vc->vc_bottom), does leaving vc->vc_top at 0 cause fbcon_switch() to immediately erase the logo?

Earlier in fbcon_prepare_logo(), scr_memsetw() fills logo_lines rows of vc->vc_origin with erase characters. When fbcon_switch() runs with logo_shown == FBCON_LOGO_DRAW, it draws the logo and then redraws the text region starting from vc->vc_top:

drivers/video/fbdev/core/fbcon.c:fbcon_switch() {
    ...
	if (logo_shown == FBCON_LOGO_DRAW) {

		logo_shown = fg_console;
		fb_show_logo(info, par->rotate);
		update_region(vc,
			      vc->vc_origin + vc->vc_size_row * vc->vc_top,
			      vc->vc_size_row * (vc->vc_bottom -
						 vc->vc_top) / 2);
		return false;
	}
    ...
}

With vc->vc_top left at 0, update_region() blits those blank erase characters from vc->vc_origin over all rows 0..vc->vc_bottom - 1 right after fb_show_logo(), wiping out the full-screen logo.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#3 lore raw
In reply to Helge Deller

Hi Helge, Jianqiang,

Quoted 30 lines · Helge Deller

From: Jianqiang Zou <[email protected]>

radeonfb_set_par() derives the dot clock from the user supplied struct fb_var_screeninfo:

        dotClock = 1000000000 / pixClock;

where pixClock is copied from mode->pixclock. A zero pixclock bypasses the existing validation and makes the kernel divide by zero in radeonfb_set_par().

The driver does have a check for this: fb_validate_mode() returns -EINVAL when pixclock is 0, but radeon_match_mode() only calls it when the output has no scaler and an EDID-derived mode database is available:

        if (has_rmx == 0 && rinfo->mon1_modedb)
                if (fb_validate_mode(...))
                        return -EINVAL;

mon1_modedb is only filled in when an EDID is read, so when no EDID-derived mode database is available the validation is skipped and the invalid mode reaches radeonfb_set_par().

Reject a zero pixclock in radeonfb_check_var() before matching the mode. fb_set_var() calls it on the FBIOPUT_VSCREENINFO path before ->fb_set_par(), so the invalid value is rejected before the mode is applied. This is the same check other fbdev drivers use (i740fb, arkfb, s3fb).

Quoted 8 lines

Reproduced on Linux 7.3.0 using a custom QEMU PCI stub device with vendor/device ID 1002:5955; no physical Radeon hardware was used. A single FBIOPUT_VSCREENINFO with pixclock = 0 is enough to trigger the divide error.

Thanks for your patch, which is now commit b3f1631d362539cf ("fbdev:
radeonfb: reject a zero pixclock in radeonfb_check_var()") in v7.4-rc4.

drivers/video/fbdev/aty/radeon_base.c static int radeonfb_check_var (struct fb_var_screeninfo *var, struct fb_info *in · line 841

Quoted 9 lines
drivers/video/fbdev/aty/radeon_base.c +3 -0
@@ -836,6 +836,9 @@ static int radeonfb_check_var (struct fb_var_screeninfo *var, struct fb_info *in
         int nom, den;
        unsigned int pitch;
 
+       if (!var->pixclock)
+               return -EINVAL;
+

This violates fbdev API rounding rules:
1. If a value doesn't fit, it must be rounded up by the driver,
2. If a value is too large, -EINVAL must be returned.

drivers/video/fbdev/aty/radeon_base.c static int radeonfb_check_var (struct fb_var_screeninfo *var, struct fb_info *in · line 843

Quoted 2 lines
drivers/video/fbdev/aty/radeon_base.c +0 -0
        if (radeon_match_mode(rinfo, &v, var))
                return -EINVAL;

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

author maintainer
#4 lore raw
Quoted 52 lines · Geert Uytterhoeven

Hi Helge, Jianqiang,

Quoted 30 lines · Helge Deller

From: Jianqiang Zou <[email protected]>

radeonfb_set_par() derives the dot clock from the user supplied struct fb_var_screeninfo:

         dotClock = 1000000000 / pixClock;

where pixClock is copied from mode->pixclock. A zero pixclock bypasses the existing validation and makes the kernel divide by zero in radeonfb_set_par().

The driver does have a check for this: fb_validate_mode() returns -EINVAL when pixclock is 0, but radeon_match_mode() only calls it when the output has no scaler and an EDID-derived mode database is available:

         if (has_rmx == 0 && rinfo->mon1_modedb)
                 if (fb_validate_mode(...))
                         return -EINVAL;

mon1_modedb is only filled in when an EDID is read, so when no EDID-derived mode database is available the validation is skipped and the invalid mode reaches radeonfb_set_par().

Reject a zero pixclock in radeonfb_check_var() before matching the mode. fb_set_var() calls it on the FBIOPUT_VSCREENINFO path before ->fb_set_par(), so the invalid value is rejected before the mode is applied. This is the same check other fbdev drivers use (i740fb, arkfb, s3fb).

Quoted 8 lines

Reproduced on Linux 7.3.0 using a custom QEMU PCI stub device with vendor/device ID 1002:5955; no physical Radeon hardware was used. A single FBIOPUT_VSCREENINFO with pixclock = 0 is enough to trigger the divide error.

Thanks for your patch, which is now commit b3f1631d362539cf ("fbdev:
radeonfb: reject a zero pixclock in radeonfb_check_var()") in v7.4-rc4.

Quoted 6 lines
drivers/video/fbdev/aty/radeon_base.c +0 -0
@@ -836,6 +836,9 @@ static int radeonfb_check_var (struct fb_var_screeninfo *var, struct fb_info *in
          int nom, den;
         unsigned int pitch;
 
Quoted 10 lines

drivers/video/fbdev/aty/radeon_base.c static int radeonfb_check_var (struct fb_var_screeninfo *var, struct fb_info *in · line 841

Quoted 3 lines
drivers/video/fbdev/aty/radeon_base.c +3 -0
+       if (!var->pixclock)
+               return -EINVAL;
+

This violates fbdev API rounding rules:
1. If a value doesn't fit, it must be rounded up by the driver,
2. If a value is too large, -EINVAL must be returned.

Quoted 2 lines
drivers/video/fbdev/aty/radeon_base.c +0 -0
         if (radeon_match_mode(rinfo, &v, var))
                 return -EINVAL;

Oops... you are right!
Jianqiang Zou, will you send another patch fixing this?

Helge