linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fbdev: fbmon: fix potential divide error in fb_validate_mode
@ 2023-10-14 12:14 Zhang Shurong
  2023-10-16 21:15 ` Helge Deller
  0 siblings, 1 reply; 2+ messages in thread
From: Zhang Shurong @ 2023-10-14 12:14 UTC (permalink / raw)
  To: daniel; +Cc: deller, linux-fbdev, dri-devel, linux-kernel, Zhang Shurong

We can easily use FBIOPUT_VSCREENINFO set fb_var_screeninfo, so
it's possible for a divide by zero error to occur.

Fix this by making sure the divisor is non-zero before the computation.

Signed-off-by: Zhang Shurong <zhang_shurong@foxmail.com>
---
 drivers/video/fbdev/core/fbmon.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/video/fbdev/core/fbmon.c b/drivers/video/fbdev/core/fbmon.c
index 79e5bfbdd34c..bdd15b8e3a71 100644
--- a/drivers/video/fbdev/core/fbmon.c
+++ b/drivers/video/fbdev/core/fbmon.c
@@ -1470,6 +1470,9 @@ int fb_validate_mode(const struct fb_var_screeninfo *var, struct fb_info *info)
 	if (var->vmode & FB_VMODE_DOUBLE)
 		vtotal *= 2;
 
+	if (!htotal || !vtotal)
+		return -EINVAL;
+
 	hfreq = pixclock/htotal;
 	hfreq = (hfreq + 500) / 1000 * 1000;
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] fbdev: fbmon: fix potential divide error in fb_validate_mode
  2023-10-14 12:14 [PATCH] fbdev: fbmon: fix potential divide error in fb_validate_mode Zhang Shurong
@ 2023-10-16 21:15 ` Helge Deller
  0 siblings, 0 replies; 2+ messages in thread
From: Helge Deller @ 2023-10-16 21:15 UTC (permalink / raw)
  To: Zhang Shurong, daniel; +Cc: linux-fbdev, dri-devel, linux-kernel

On 10/14/23 14:14, Zhang Shurong wrote:
> We can easily use FBIOPUT_VSCREENINFO set fb_var_screeninfo, so
> it's possible for a divide by zero error to occur.
>
> Fix this by making sure the divisor is non-zero before the computation.
>
> Signed-off-by: Zhang Shurong <zhang_shurong@foxmail.com>
> ---
>   drivers/video/fbdev/core/fbmon.c | 3 +++
>   1 file changed, 3 insertions(+)
>
> diff --git a/drivers/video/fbdev/core/fbmon.c b/drivers/video/fbdev/core/fbmon.c
> index 79e5bfbdd34c..bdd15b8e3a71 100644
> --- a/drivers/video/fbdev/core/fbmon.c
> +++ b/drivers/video/fbdev/core/fbmon.c
> @@ -1470,6 +1470,9 @@ int fb_validate_mode(const struct fb_var_screeninfo *var, struct fb_info *info)
>   	if (var->vmode & FB_VMODE_DOUBLE)
>   		vtotal *= 2;
>
> +	if (!htotal || !vtotal)
> +		return -EINVAL;

This is above here:
         htotal = var->xres + var->right_margin + var->hsync_len +
                 var->left_margin;
         vtotal = var->yres + var->lower_margin + var->vsync_len +
                 var->upper_margin;

I don't see how htotal and vtotal can become zero...

Helge

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-10-16 21:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-14 12:14 [PATCH] fbdev: fbmon: fix potential divide error in fb_validate_mode Zhang Shurong
2023-10-16 21:15 ` Helge Deller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).