Skip to contentSkip to conversation

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

PATCH Applied Zou Jianqiang 2 participants 3 messages Nov 1 – Nov 18

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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 b6b058cee..a69e58914 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.43.0
#1 lore raw
Quoted 45 lines · Jianqiang Zou

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 +0 -0
index b6b058cee..a69e58914 100644

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

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;
+
  	if (radeon_match_mode(rinfo, &v, var))
  		return -EINVAL;
 

Hi Benjamin and Helge,

I'm following up on the radeonfb patch I sent on November 1. It rejects a zero pixclock in radeonfb_check_var() to prevent a divide-by-zero in radeonfb_set_par().

Could you review the patch when you have a chance and apply it if it looks good? If any changes or additional testing would help, please let me know.

Thanks,
Jianqiang

maintainer Applied
#2 lore raw
In reply to Zou Jianqiang
Quoted 35 lines · Zou Jianqiang

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.

Quoted 4 lines
---
  drivers/video/fbdev/aty/radeon_base.c | 3 +++
  1 file changed, 3 insertions(+)

applied.

Thanks!
Helge