From: Helge Deller <deller@gmx.de>
To: Mingyu Wang <25181214217@stu.xidian.edu.cn>, simona@ffwll.ch
Cc: linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] fbdev: core: Clamp total_size to smem_len in read/write functions
Date: Sat, 25 Jul 2026 17:29:58 +0200 [thread overview]
Message-ID: <bb8a8d13-07fb-4ee9-aed2-172c86cf3ac0@gmx.de> (raw)
In-Reply-To: <20260721071522.106306-1-25181214217@stu.xidian.edu.cn>
On 7/21/26 09:15, Mingyu Wang wrote:
> Some legacy fbdev drivers may incorrectly set info->screen_size to a
> value larger than the actual mapped framebuffer size (info->fix.smem_len)
> during mode switches. This could allow out-of-bounds I/O and system
> memory accesses in fb_io_read(), fb_io_write(), fb_sys_read(), and
> fb_sys_write().
>
> Prevent this by clamping total_size to smem_len when smem_len is non-zero.
> Virtual framebuffers (smem_len == 0) are unaffected.
>
> This is a hardening measure; no specific crash is fixed by this patch.
>
> Signed-off-by: Mingyu Wang <25181214217@stu.xidian.edu.cn>
> ---
> v2:
> - Apply the clamp to fb_sys_read() and fb_sys_write() as well to prevent
> similar OOB accesses in system memory framebuffers (Reported by Sashiko).
> - Update commit message to clearly state this is a hardening measure.
> ---
> drivers/video/fbdev/core/fb_io_fops.c | 16 ++++++++++++++++
> drivers/video/fbdev/core/fb_sys_fops.c | 16 ++++++++++++++++
> 2 files changed, 32 insertions(+)
Sounds reasonable.
I've added it to fbdev git tree for wider testing.
Thanks!
Helge
> diff --git a/drivers/video/fbdev/core/fb_io_fops.c b/drivers/video/fbdev/core/fb_io_fops.c
> index 6ab60fcd0050..335f16d2cc23 100644
> --- a/drivers/video/fbdev/core/fb_io_fops.c
> +++ b/drivers/video/fbdev/core/fb_io_fops.c
> @@ -24,6 +24,14 @@ ssize_t fb_io_read(struct fb_info *info, char __user *buf, size_t count, loff_t
> if (total_size == 0)
> total_size = info->fix.smem_len;
>
> + /*
> + * Security Hardening: Defend against buggy legacy drivers that may
> + * calculate a malformed screen_size. Clamp total_size to the actual
> + * hardware mapped memory limit (smem_len) to prevent OOB access.
> + */
> + if (info->fix.smem_len && total_size > info->fix.smem_len)
> + total_size = info->fix.smem_len;
> +
> if (p >= total_size)
> return 0;
>
> @@ -88,6 +96,14 @@ ssize_t fb_io_write(struct fb_info *info, const char __user *buf, size_t count,
> if (total_size == 0)
> total_size = info->fix.smem_len;
>
> + /*
> + * Security Hardening: Defend against buggy legacy drivers that may
> + * calculate a malformed screen_size. Clamp total_size to the actual
> + * hardware mapped memory limit (smem_len) to prevent OOB access.
> + */
> + if (info->fix.smem_len && total_size > info->fix.smem_len)
> + total_size = info->fix.smem_len;
> +
> if (p > total_size)
> return -EFBIG;
>
> diff --git a/drivers/video/fbdev/core/fb_sys_fops.c b/drivers/video/fbdev/core/fb_sys_fops.c
> index be96b3b3942e..e97cf02f7c70 100644
> --- a/drivers/video/fbdev/core/fb_sys_fops.c
> +++ b/drivers/video/fbdev/core/fb_sys_fops.c
> @@ -35,6 +35,14 @@ ssize_t fb_sys_read(struct fb_info *info, char __user *buf, size_t count,
> if (total_size == 0)
> total_size = info->fix.smem_len;
>
> + /*
> + * Security Hardening: Defend against buggy legacy drivers that may
> + * calculate a malformed screen_size. Clamp total_size to the actual
> + * hardware mapped memory limit (smem_len) to prevent OOB access.
> + */
> + if (info->fix.smem_len && total_size > info->fix.smem_len)
> + total_size = info->fix.smem_len;
> +
> if (p >= total_size)
> return 0;
>
> @@ -80,6 +88,14 @@ ssize_t fb_sys_write(struct fb_info *info, const char __user *buf,
> if (total_size == 0)
> total_size = info->fix.smem_len;
>
> + /*
> + * Security Hardening: Defend against buggy legacy drivers that may
> + * calculate a malformed screen_size. Clamp total_size to the actual
> + * hardware mapped memory limit (smem_len) to prevent OOB access.
> + */
> + if (info->fix.smem_len && total_size > info->fix.smem_len)
> + total_size = info->fix.smem_len;
> +
> if (p > total_size)
> return -EFBIG;
>
prev parent reply other threads:[~2026-07-25 15:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-21 7:15 [PATCH v2] fbdev: core: Clamp total_size to smem_len in read/write functions Mingyu Wang
2026-07-25 15:29 ` Helge Deller [this message]
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=bb8a8d13-07fb-4ee9-aed2-172c86cf3ac0@gmx.de \
--to=deller@gmx.de \
--cc=25181214217@stu.xidian.edu.cn \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-fbdev@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=simona@ffwll.ch \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox