All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Melbin K Mathew" <mlbnkm1@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2 1/2] fbdev: bound mode sysfs output to the sysfs buffer
Date: Wed, 01 Jul 2026 23:26:57 +0000	[thread overview]
Message-ID: <20260701232657.E0EFC1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260701231706.234715-2-mlbnkm1@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Lockless reads of `fb_info->var` cause torn reads and state corruption.
--

commit b5317fd1a6886d886e344587e27b5ae1721b2542
Author: Melbin K Mathew <mlbnkm1@gmail.com>

fbdev: bound mode sysfs output to the sysfs buffer
    
mode_string() uses snprintf() which can return a value larger than the
remaining buffer space. show_modes() accumulates the return value into i
without checking whether i has reached PAGE_SIZE. This commit adds a size
parameter to mode_string() and uses scnprintf() to return only the bytes
actually written.
    
Cc: stable@vger.kernel.org

> diff --git a/drivers/video/fbdev/core/fbsysfs.c b/drivers/video/fbdev/core/fbsysfs.c
> index ea196603c7a87..af21dc5052df3 100644
> --- a/drivers/video/fbdev/core/fbsysfs.c
> +++ b/drivers/video/fbdev/core/fbsysfs.c

[ ... ]

> @@ -64,7 +67,7 @@ static ssize_t store_mode(struct device *device, struct device_attribute *attr,
>  
>  	list_for_each_entry(modelist, &fb_info->modelist, list) {
>  		mode = &modelist->mode;
> -		i = mode_string(mstr, 0, mode);
> +		i = mode_string(mstr, sizeof(mstr), 0, mode);
>  		if (strncmp(mstr, buf, max(count, i)) == 0) {
>  
>  			var = fb_info->var;

[Severity: High]
This isn't a bug introduced by this patch, but while looking at fbsysfs.c,
I noticed several other functions perform a lockless copy of the
fb_info->var struct:

    var = fb_info->var;

This happens in store_bpp(), store_rotate(), store_virtual(), and store_pan().

If this lockless sysfs read races with an ioctl(FBIOPUT_VSCREENINFO)
executing fb_set_var() (which modifies info->var under fb_info->lock),
could it tear the large struct fb_var_screeninfo?

Modifying and writing this corrupted state back to the hardware via activate()
or fb_pan_display() might configure the display controller with invalid 
settings, potentially causing display corruption or crashes in low-level 
graphics drivers.

Should these other functions also serialize their access with lock_fb_info()?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260701221757.231490-1-mlbnkm1@gmail.com?part=1

  reply	other threads:[~2026-07-01 23:27 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-01 22:17 [PATCH] fbdev: protect mode sysfs reads with lock_fb_info() Melbin K Mathew
2026-07-01 22:30 ` sashiko-bot
2026-07-01 23:17 ` [PATCH v2 0/2] fbdev: fix mode sysfs lifetime and bounds issues Melbin K Mathew
2026-07-01 23:42   ` [PATCH v3 0/3] " Melbin K Mathew
2026-07-01 23:42   ` [PATCH v3 1/3] fbdev: bound mode sysfs output to the sysfs buffer Melbin K Mathew
2026-07-01 23:54     ` sashiko-bot
2026-07-01 23:42   ` [PATCH v3 2/3] fbdev: clear fb_info->mode before deleting a videomode Melbin K Mathew
2026-07-01 23:42   ` [PATCH v3 3/3] fbdev: serialize mode sysfs access with lock_fb_info() Melbin K Mathew
2026-07-01 23:56     ` sashiko-bot
2026-07-02  0:05       ` Melbin K Mathew
2026-07-01 23:17 ` [PATCH v2 1/2] fbdev: bound mode sysfs output to the sysfs buffer Melbin K Mathew
2026-07-01 23:26   ` sashiko-bot [this message]
2026-07-01 23:17 ` [PATCH v2 2/2] fbdev: serialize mode sysfs access with lock_fb_info() Melbin K Mathew
2026-07-01 23:29   ` sashiko-bot

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=20260701232657.E0EFC1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=mlbnkm1@gmail.com \
    --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.