From: Thomas Zimmermann <tzimmermann@suse.de>
To: javierm@redhat.com, treding@nvidia.com,
maarten.lankhorst@linux.intel.com, mripard@kernel.org,
airlied@gmail.com, simona@ffwll.ch, neil.armstrong@linaro.org,
jesszhan0024@gmail.com, rayyan@ansari.sh
Cc: dri-devel@lists.freedesktop.org, sashiko-reviews@lists.linux.dev,
Thomas Zimmermann <tzimmermann@suse.de>,
Sashiko <sashiko-bot@kernel.org>
Subject: [PATCH v3 5/7] drm/sysfb: simpledrm: Validate mmap size against framebuffer size
Date: Thu, 25 Jun 2026 11:39:37 +0200 [thread overview]
Message-ID: <20260625094509.157581-6-tzimmermann@suse.de> (raw)
In-Reply-To: <20260625094509.157581-1-tzimmermann@suse.de>
The size of the mmap'ed framebuffer could be smaller than the minimum
required framebuffer size. Validate the resource size against the
framebuffer size.
Buggy firmware that triggers this check should be fixed up with a quirk
on a case-by-case base.
v3:
- fix size checks (Sashiko)
- improve error message for alignment check (Thierry)
- do not store aligned size value
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Suggested-by: Sashiko <sashiko-bot@kernel.org>
Reviewed-by: Thierry Reding <treding@nvidia.com>
---
drivers/gpu/drm/sysfb/simpledrm.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/drivers/gpu/drm/sysfb/simpledrm.c b/drivers/gpu/drm/sysfb/simpledrm.c
index a899dfb747bf..9e0711e0095a 100644
--- a/drivers/gpu/drm/sysfb/simpledrm.c
+++ b/drivers/gpu/drm/sysfb/simpledrm.c
@@ -6,6 +6,7 @@
#include <linux/of_address.h>
#include <linux/of_clk.h>
#include <linux/of_reserved_mem.h>
+#include <linux/overflow.h>
#include <linux/platform_data/simplefb.h>
#include <linux/platform_device.h>
#include <linux/pm.h>
@@ -623,6 +624,7 @@ static struct simpledrm_device *simpledrm_device_create(struct drm_driver *drv,
u16 width_mm = 0, height_mm = 0;
struct device_node *panel_node;
const struct drm_format_info *format;
+ u64 size;
struct resource *res, *mem = NULL;
struct drm_plane *primary_plane;
struct drm_crtc *crtc;
@@ -713,6 +715,14 @@ static struct simpledrm_device *simpledrm_device_create(struct drm_driver *drv,
}
stride = pitch;
}
+ if (check_mul_overflow(height, stride, &size)) {
+ drm_err(dev, "framebuffer size exceeds maximum\n");
+ return ERR_PTR(-EINVAL);
+ }
+ if (ALIGN(size, PAGE_SIZE) < PAGE_SIZE) {
+ drm_err(dev, "page-aligned framebuffer exceeds maximum\n");
+ return ERR_PTR(-EINVAL);
+ }
sysfb->fb_mode = drm_sysfb_mode(width, height, width_mm, height_mm);
sysfb->fb_format = format;
@@ -738,6 +748,13 @@ static struct simpledrm_device *simpledrm_device_create(struct drm_driver *drv,
drm_dbg(dev, "using system memory framebuffer at %pr\n", mem);
+ if (size > resource_size(mem)) {
+ drm_err(dev,
+ "framebuffer size of %llu exceeds memory range %pr\n",
+ size, mem);
+ return ERR_PTR(-EINVAL);
+ }
+
screen_base = devm_memremap(dev->dev, mem->start, resource_size(mem), MEMREMAP_WC);
if (IS_ERR(screen_base))
return screen_base;
@@ -771,6 +788,13 @@ static struct simpledrm_device *simpledrm_device_create(struct drm_driver *drv,
mem = res;
}
+ if (size > resource_size(mem)) {
+ drm_err(dev,
+ "framebuffer size of %llu exceeds memory range %pr\n",
+ size, mem);
+ return ERR_PTR(-EINVAL);
+ }
+
screen_base = devm_ioremap_wc(&pdev->dev, mem->start, resource_size(mem));
if (!screen_base)
return ERR_PTR(-ENOMEM);
--
2.54.0
next prev parent reply other threads:[~2026-06-25 9:45 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-25 9:39 [PATCH v3 0/7] drm/sysfb: simpledrm: Various improvements Thomas Zimmermann
2026-06-25 9:39 ` [PATCH v3 1/7] drm/sysfb: simpledrm: Improve framebuffer-size validation Thomas Zimmermann
2026-06-25 10:05 ` sashiko-bot
2026-06-25 9:39 ` [PATCH v3 2/7] drm/sysfb: simpledrm: Improve panel-size validation Thomas Zimmermann
2026-06-25 9:39 ` [PATCH v3 3/7] drm/sysfb: simpledrm: Inline simplefb_get_validated_int() Thomas Zimmermann
2026-06-25 9:39 ` [PATCH v3 4/7] drm/sysfb: simpledrm: Improve stride validation Thomas Zimmermann
2026-06-25 9:39 ` Thomas Zimmermann [this message]
2026-06-25 10:27 ` [PATCH v3 5/7] drm/sysfb: simpledrm: Validate mmap size against framebuffer size sashiko-bot
2026-06-25 9:39 ` [PATCH v3 6/7] drm/of: Implement drm_of_get_panel_orientation() Thomas Zimmermann
2026-06-29 12:27 ` Thierry Reding
2026-06-29 12:44 ` Thomas Zimmermann
2026-06-29 13:19 ` Thierry Reding
2026-06-29 13:29 ` Thierry Reding
2026-06-29 12:28 ` Thierry Reding
2026-06-25 9:39 ` [PATCH v3 7/7] drm/sysfb: simpledrm: Read panel orientation from DT node Thomas Zimmermann
2026-06-29 12:27 ` Thierry Reding
2026-06-25 10:56 ` [PATCH v3 0/7] drm/sysfb: simpledrm: Various improvements Maxime Ripard
2026-06-29 11:02 ` Javier Martinez Canillas
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=20260625094509.157581-6-tzimmermann@suse.de \
--to=tzimmermann@suse.de \
--cc=airlied@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=javierm@redhat.com \
--cc=jesszhan0024@gmail.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=neil.armstrong@linaro.org \
--cc=rayyan@ansari.sh \
--cc=sashiko-bot@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=simona@ffwll.ch \
--cc=treding@nvidia.com \
/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.