Merged into drm-misc-fixes

Am 25.08.26 um 12:41 schrieb [email protected]:
From: Shixiong Ou <[email protected]>

The framebuffer size calculation `fb_size = linebytes * height` can
overflow when both values are large (e.g., 46341 * 46341 > INT_MAX).
Since linebytes and height are both int types, the multiplication is
performed as int * int, which results in undefined behavior on overflow.

Use check_mul_overflow() to detect and prevent this overflow, consistent
with the approach used in simpledrm.c and corebootdrm.c.

Signed-off-by: Shixiong Ou <[email protected]>
Reviewed-by: Thomas Zimmermann <[email protected]>
---
  drivers/gpu/drm/sysfb/ofdrm.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/sysfb/ofdrm.c b/drivers/gpu/drm/sysfb/ofdrm.c
index 819aed466727..a6dc34b9ec0f 100644
--- a/drivers/gpu/drm/sysfb/ofdrm.c
+++ b/drivers/gpu/drm/sysfb/ofdrm.c
@@ -2,6 +2,7 @@
#include <linux/aperture.h>
  #include <linux/of_address.h>
+#include <linux/overflow.h>
  #include <linux/pci.h>
  #include <linux/platform_device.h>
  #include <linux/pm.h>
@@ -913,7 +914,10 @@ static struct ofdrm_device *ofdrm_device_create(struct 
drm_driver *drv,
                        return ERR_PTR(-EINVAL);
        }
- fb_size = linebytes * height;
+       if (check_mul_overflow(linebytes, height, &fb_size)) {
+               drm_err(dev, "framebuffer size exceeds maximum\n");
+               return ERR_PTR(-EINVAL);
+       }
/*
         * Try to figure out the address of the framebuffer. Unfortunately, Open

--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, (HRB 36809, AG Nürnberg)


Reply via email to