Skip to contentSkip to conversation

fbdev: tgafb: Fix potential divide by zero

PATCH In review harperchen 3 participants 5 messages Mar 7, 2023 – Mar 9, 2023 Framebuffer layer

lore
Share & tools
lore

harperchen

author
#0 lore raw

PATCH 1/1 fbdev: tgafb: Fix potential divide by zero

fb_set_var would by called when user invokes ioctl with cmd FBIOPUT_VSCREENINFO. User-provided data would finally reach tgafb_check_var. In case var->pixclock is assigned to zero, divide by zero would occur when checking whether reciprocal of var->pixclock is too high.

Similar crashes have happened in other fbdev drivers. There is no check and modification on var->pixclock along the call chain to tgafb_check_var. We believe it could also be triggered in driver tgafb from user site.

---
 drivers/video/fbdev/tgafb.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/video/fbdev/tgafb.c +3 -0
index 14d37c49633c..b44004880f0d 100644
@@ -173,6 +173,9 @@ tgafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
 {
 	struct tga_par *par = (struct tga_par *)info->par;
 
+	if (!var->pixclock)
+		return -EINVAL;
+
 	if (par->tga_type == TGA_TYPE_8PLANE) {
 		if (var->bits_per_pixel != 8)
 			return -EINVAL;
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 6 lines · harperchen

fb_set_var would by called when user invokes ioctl with cmd FBIOPUT_VSCREENINFO. User-provided data would finally reach tgafb_check_var. In case var->pixclock is assigned to zero, divide by zero would occur when checking whether reciprocal of var->pixclock is too high.

Quoted 6 lines

Similar crashes have happened in other fbdev drivers. There is no check and modification on var->pixclock along the call chain to tgafb_check_var. We believe it could also be triggered in driver tgafb from user site.

Could you provide a real name?
Otherwise applied to fbdev git tree.

Thanks!
Helge

Quoted 18 lines
---
  drivers/video/fbdev/tgafb.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/video/fbdev/tgafb.c +3 -0
index 14d37c49633c..b44004880f0d 100644
@@ -173,6 +173,9 @@ tgafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  {
  	struct tga_par *par = (struct tga_par *)info->par;
 
+	if (!var->pixclock)
+		return -EINVAL;
+
  	if (par->tga_type == TGA_TYPE_8PLANE) {
  		if (var->bits_per_pixel != 8)
  			return -EINVAL;
author
#2 lore raw

Dear Helge,

Thank you for the kind words. My real name is Wei Chen.

Please apply this patch to fbdev git tree if it is correct.

Best,
Wei

Quoted 40 lines · Helge Deller
Quoted 6 lines · harperchen

fb_set_var would by called when user invokes ioctl with cmd FBIOPUT_VSCREENINFO. User-provided data would finally reach tgafb_check_var. In case var->pixclock is assigned to zero, divide by zero would occur when checking whether reciprocal of var->pixclock is too high.

Quoted 6 lines

Similar crashes have happened in other fbdev drivers. There is no check and modification on var->pixclock along the call chain to tgafb_check_var. We believe it could also be triggered in driver tgafb from user site.

Could you provide a real name?
Otherwise applied to fbdev git tree.

Thanks!
Helge

Quoted 18 lines
---
  drivers/video/fbdev/tgafb.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/video/fbdev/tgafb.c +3 -0
index 14d37c49633c..b44004880f0d 100644
@@ -173,6 +173,9 @@ tgafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  {
      struct tga_par *par = (struct tga_par *)info->par;
 
+     if (!var->pixclock)
+             return -EINVAL;
+
      if (par->tga_type == TGA_TYPE_8PLANE) {
              if (var->bits_per_pixel != 8)
                      return -EINVAL;
#3 lore raw
In reply to Helge Deller
Quoted 12 lines · Helge Deller
Quoted 11 lines · harperchen

fb_set_var would by called when user invokes ioctl with cmd FBIOPUT_VSCREENINFO. User-provided data would finally reach tgafb_check_var. In case var->pixclock is assigned to zero, divide by zero would occur when checking whether reciprocal of var->pixclock is too high.

Similar crashes have happened in other fbdev drivers. There is no check and modification on var->pixclock along the call chain to tgafb_check_var. We believe it could also be triggered in driver tgafb from user site.

Quoted 4 lines
Quoted 1 line

Could you provide a real name?
Otherwise applied to fbdev git tree.

See commit d4563201f33a ("Documentation: simplify and clarify DCO contribution example language").

BR,
Jani.

Quoted 23 lines

Thanks!
Helge

Quoted 18 lines
---
  drivers/video/fbdev/tgafb.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/video/fbdev/tgafb.c +3 -0
index 14d37c49633c..b44004880f0d 100644
@@ -173,6 +173,9 @@ tgafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  {
  	struct tga_par *par = (struct tga_par *)info->par;
 
+	if (!var->pixclock)
+		return -EINVAL;
+
  	if (par->tga_type == TGA_TYPE_8PLANE) {
  		if (var->bits_per_pixel != 8)
  			return -EINVAL;
Signature · 1 line
Jani Nikula, Intel Open Source Graphics Center
maintainer
#4 lore raw
Quoted 13 lines · Jani Nikula
Quoted 12 lines · Helge Deller
Quoted 11 lines · harperchen

fb_set_var would by called when user invokes ioctl with cmd FBIOPUT_VSCREENINFO. User-provided data would finally reach tgafb_check_var. In case var->pixclock is assigned to zero, divide by zero would occur when checking whether reciprocal of var->pixclock is too high.

Similar crashes have happened in other fbdev drivers. There is no check and modification on var->pixclock along the call chain to tgafb_check_var. We believe it could also be triggered in driver tgafb from user site.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Could you provide a real name?
Otherwise applied to fbdev git tree.

See commit d4563201f33a ("Documentation: simplify and clarify DCO contribution example language").

Nice. Thanks for that link!
Btw, I did applied that patch yesterday to my tree with just the nickname, but of course I do prefer real names which is why I asked.

Helge