From: sashiko-bot@kernel.org
To: "Ian Bridges" <icb@fastmail.org>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] fbdev: Fix fb_new_modelist to prevent null-ptr-deref in fb_videomode_to_var
Date: Thu, 25 Jun 2026 04:26:06 +0000 [thread overview]
Message-ID: <20260625042606.DBD031F000E9@smtp.kernel.org> (raw)
In-Reply-To: <ajyq2Fr-2fMfftGC@dev>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Buffer overflow in `show_modes()` due to unbounded accumulation of offset.
--
commit c6eace86a62190121a8b0640238eca3a23f8495d
Author: Ian Bridges <icb@fastmail.org>
fbdev: Fix fb_new_modelist to prevent null-ptr-deref in fb_videomode_to_var
This commit fixes a null pointer dereference in fb_videomode_to_var by
ensuring that the current mode is kept in the modelist during
fb_new_modelist() if it is not already present.
> diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
> index e5221653ec2b9..2f1c56e5a7a23 100644
> --- a/drivers/video/fbdev/core/fbmem.c
> +++ b/drivers/video/fbdev/core/fbmem.c
[ ... ]
> @@ -767,6 +767,18 @@ int fb_new_modelist(struct fb_info *info)
> if (list_empty(&info->modelist))
> return 1;
>
> + /*
> + * The new modelist may not contain the current mode (info->var), and
> + * fbcon_new_modelist() below only re-points consoles mapped to this
> + * framebuffer. Add the current mode here so info->var keeps a match
> + * even when fbcon is unbound.
> + */
[Severity: High]
This is a pre-existing issue, but while reviewing how modelists are populated
here, I noticed an older problem when the modelist is read from sysfs.
Does this code overflow the sysfs buffer on the kernel heap?
If a driver populates the framebuffer's modelist with many entries, or root
writes them via the store_modes sysfs interface, the offset i accumulates
the return value of mode_string() continuously in show_modes():
drivers/video/fbdev/core/fbsysfs.c:show_modes() {
...
i += mode_string(buf, i, mode);
...
}
The mode_string() function passes this offset directly to snprintf:
drivers/video/fbdev/core/fbsysfs.c:mode_string() {
...
return snprintf(&buf[offset], PAGE_SIZE - offset, "%c:%dx%d%c-%d\n",
m, mode->xres, mode->yres, v, mode->refresh);
}
Because snprintf returns the number of characters that would have been
written regardless of truncation, the offset will eventually exceed PAGE_SIZE
if there are enough modes.
When offset is greater than PAGE_SIZE, the expression PAGE_SIZE - offset
integer-underflows to a massive positive size_t value, causing snprintf
to write past the 1-page sysfs buffer allocation.
> + if (!fb_match_mode(&info->var, &info->modelist)) {
> + fb_var_to_videomode(&mode, &info->var);
> + if (fb_add_videomode(&mode, &info->modelist))
> + return 1;
> + }
> +
> fbcon_new_modelist(info);
>
> return 0;
--
Sashiko AI review · https://sashiko.dev/#/patchset/ajyq2Fr-2fMfftGC@dev?part=1
prev parent reply other threads:[~2026-06-25 4:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-25 4:13 [PATCH] fbdev: Fix fb_new_modelist to prevent null-ptr-deref in fb_videomode_to_var Ian Bridges
2026-06-25 4:26 ` sashiko-bot [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=20260625042606.DBD031F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=icb@fastmail.org \
--cc=sashiko-reviews@lists.linux.dev \
/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.