All of lore.kernel.org
 help / color / mirror / Atom feed
From: saeed.mirzamohammadi@oracle.com
To: linux-kernel@vger.kernel.org
Cc: b.zolnierkie@samsung.com, akpm@linux-foundation.org,
	rppt@kernel.org, daniel.vetter@ffwll.ch, jani.nikula@intel.com,
	gustavoars@kernel.org, dri-devel@lists.freedesktop.org,
	linux-fbdev@vger.kernel.org
Subject: [PATCH 1/1] video: fbdev: fix divide error in fbcon_switch
Date: Wed, 21 Oct 2020 16:57:58 -0700	[thread overview]
Message-ID: <20201021235758.59993-1-saeed.mirzamohammadi@oracle.com> (raw)

From: Saeed Mirzamohammadi <saeed.mirzamohammadi@oracle.com>

This patch fixes the issue due to:

[   89.572883] divide_error: 0000 [#1] SMP KASAN PTI
[   89.572897] CPU: 3 PID: 16083 Comm: repro Not tainted 5.9.0-rc7.20200930.rc1.allarch-19-g3e32d0d.syzk #5
[   89.572902] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 0.5.1 01/01/2011
[   89.572934] RIP: 0010:cirrusfb_check_var+0x84/0x1260

The error happens when the pixels value is calculated before performing the sanity checks on bits_per_pixel.
A bits_per_pixel set to zero causes divide by zero error.

This patch moves the calculation after the sanity check.

Signed-off-by: Saeed Mirzamohammadi <saeed.mirzamohammadi@oracle.com>
Tested-by: Saeed Mirzamohammadi <saeed.mirzamohammadi@oracle.com>
---
 drivers/video/fbdev/cirrusfb.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/cirrusfb.c b/drivers/video/fbdev/cirrusfb.c
index 15a9ee7cd734..a7749101b094 100644
--- a/drivers/video/fbdev/cirrusfb.c
+++ b/drivers/video/fbdev/cirrusfb.c
@@ -531,7 +531,7 @@ static int cirrusfb_check_var(struct fb_var_screeninfo *var,
 {
 	int yres;
 	/* memory size in pixels */
-	unsigned pixels = info->screen_size * 8 / var->bits_per_pixel;
+	unsigned int pixels;
 	struct cirrusfb_info *cinfo = info->par;
 
 	switch (var->bits_per_pixel) {
@@ -573,6 +573,7 @@ static int cirrusfb_check_var(struct fb_var_screeninfo *var,
 		return -EINVAL;
 	}
 
+	pixels = info->screen_size * 8 / var->bits_per_pixel;
 	if (var->xres_virtual < var->xres)
 		var->xres_virtual = var->xres;
 	/* use highest possible virtual resolution */
-- 
2.27.0


WARNING: multiple messages have this Message-ID (diff)
From: saeed.mirzamohammadi@oracle.com
To: linux-kernel@vger.kernel.org
Cc: linux-fbdev@vger.kernel.org, b.zolnierkie@samsung.com,
	jani.nikula@intel.com, daniel.vetter@ffwll.ch,
	gustavoars@kernel.org, dri-devel@lists.freedesktop.org,
	akpm@linux-foundation.org, rppt@kernel.org
Subject: [PATCH 1/1] video: fbdev: fix divide error in fbcon_switch
Date: Wed, 21 Oct 2020 16:57:58 -0700	[thread overview]
Message-ID: <20201021235758.59993-1-saeed.mirzamohammadi@oracle.com> (raw)

From: Saeed Mirzamohammadi <saeed.mirzamohammadi@oracle.com>

This patch fixes the issue due to:

[   89.572883] divide_error: 0000 [#1] SMP KASAN PTI
[   89.572897] CPU: 3 PID: 16083 Comm: repro Not tainted 5.9.0-rc7.20200930.rc1.allarch-19-g3e32d0d.syzk #5
[   89.572902] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 0.5.1 01/01/2011
[   89.572934] RIP: 0010:cirrusfb_check_var+0x84/0x1260

The error happens when the pixels value is calculated before performing the sanity checks on bits_per_pixel.
A bits_per_pixel set to zero causes divide by zero error.

This patch moves the calculation after the sanity check.

Signed-off-by: Saeed Mirzamohammadi <saeed.mirzamohammadi@oracle.com>
Tested-by: Saeed Mirzamohammadi <saeed.mirzamohammadi@oracle.com>
---
 drivers/video/fbdev/cirrusfb.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/cirrusfb.c b/drivers/video/fbdev/cirrusfb.c
index 15a9ee7cd734..a7749101b094 100644
--- a/drivers/video/fbdev/cirrusfb.c
+++ b/drivers/video/fbdev/cirrusfb.c
@@ -531,7 +531,7 @@ static int cirrusfb_check_var(struct fb_var_screeninfo *var,
 {
 	int yres;
 	/* memory size in pixels */
-	unsigned pixels = info->screen_size * 8 / var->bits_per_pixel;
+	unsigned int pixels;
 	struct cirrusfb_info *cinfo = info->par;
 
 	switch (var->bits_per_pixel) {
@@ -573,6 +573,7 @@ static int cirrusfb_check_var(struct fb_var_screeninfo *var,
 		return -EINVAL;
 	}
 
+	pixels = info->screen_size * 8 / var->bits_per_pixel;
 	if (var->xres_virtual < var->xres)
 		var->xres_virtual = var->xres;
 	/* use highest possible virtual resolution */
-- 
2.27.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

             reply	other threads:[~2020-10-21 23:59 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-21 23:57 saeed.mirzamohammadi [this message]
2020-10-21 23:57 ` [PATCH 1/1] video: fbdev: fix divide error in fbcon_switch saeed.mirzamohammadi
2020-10-22  0:33 ` Saeed Mirzamohammadi
2020-10-22  0:33   ` Saeed Mirzamohammadi
2020-10-22  7:28 ` Thomas Zimmermann
2020-10-22  7:28   ` Thomas Zimmermann
2020-10-22  7:34 ` Thomas Zimmermann
2020-10-22  7:34   ` Thomas Zimmermann
2020-10-25 23:31   ` Saeed Mirzamohammadi
2020-10-26 17:00   ` Saeed Mirzamohammadi
2020-10-26 17:00     ` Saeed Mirzamohammadi
2020-10-27  6:22     ` Greg KH
2020-10-27  6:22       ` Greg KH
2020-10-27 16:22       ` Saeed Mirzamohammadi
2020-10-27 16:33       ` Saeed Mirzamohammadi
2020-10-27 17:12       ` Saeed Mirzamohammadi
2020-10-29 11:03         ` Greg KH
2020-10-29 11:03           ` Greg KH
2020-10-29 11:13           ` Jani Nikula
2020-10-29 11:13             ` Jani Nikula
2020-10-29 11:30             ` Greg KH
2020-10-29 11:30               ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201021235758.59993-1-saeed.mirzamohammadi@oracle.com \
    --to=saeed.mirzamohammadi@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=b.zolnierkie@samsung.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gustavoars@kernel.org \
    --cc=jani.nikula@intel.com \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rppt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.