Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Praneeth Balasubramanian <praneethb2002@gmail.com>
To: Helge Deller <deller@gmx.de>, Bernie Thompson <bernie@plugable.com>
Cc: Mikulas Patocka <mpatocka@redhat.com>, Xiang Mei <xmei5@asu.edu>,
	linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org,
	linux-kernel@vger.kernel.org,
	Praneeth Balasubramanian <praneethb2002@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH] fbdev: udlfb: Hold info->lock when edid_store() sets the mode
Date: Fri,  4 Dec 2026 10:51:36 -0800	[thread overview]
Message-ID: <20261204185136.1688369-1-praneethb2002@gmail.com> (raw)

edid_store() calls dlfb_setup_modes(), which takes info->lock and drops
it before it returns, and then calls dlfb_ops_set_par() with no lock
held. Since commit 7433914efd58 ("udlfb: allow reallocating the
framebuffer"), dlfb_ops_set_par() calls dlfb_realloc_framebuffer(), whose
comment says "Assumes &info->lock held by caller". The fbdev core holds
info->lock when it calls ->fb_set_par(), for example for
FBIOPUT_VSCREENINFO.

The edid attribute has mode 0666. Two writes to it at the same time go
through dlfb_setup_modes() one after the other, but then call
dlfb_ops_set_par() at the same time. dlfb_setup_modes() refuses to run
while the device is open, but a process can open /dev/fbN after that
check and race FBIOPUT_VSCREENINFO with the write in the same way. Either
way dlfb_realloc_framebuffer() runs twice at once. Both runs can queue
the same old buffer on dlfb->deferred_free, which is then vfree()d twice
when the device goes away, and the unlocked list_add() can corrupt that
list. The stores to info->screen_buffer and info->fix.smem_len can also
interleave, so the green screen fill in dlfb_ops_set_par() and later
writes to /dev/fbN can use the length of one buffer with the other,
smaller one.

Take info->lock around dlfb_ops_set_par() in edid_store(), as the fbdev
core does.

The missing lock was found by a static check that turns the locking rule
in a function's comment into a Clang context-analysis requirement on its
callers. The sashiko review of an earlier udlfb fix also points it out.

Link: https://lore.kernel.org/all/20260912212923.016901F000FF@smtp.kernel.org/
Fixes: 7433914efd58 ("udlfb: allow reallocating the framebuffer")
Cc: stable@vger.kernel.org
Signed-off-by: Praneeth Balasubramanian <praneethb2002@gmail.com>
---

Notes:
    This was found by a compiler-based check, part of research at UCSB SecLab.
    The locking rule stated in the kernel-doc comment of the called function
    was turned into a Clang context-analysis requirement (__must_hold) on that
    function, and Clang 23 with CONFIG_WARN_CONTEXT_ANALYSIS then checked every
    caller. An LLM was used only to turn the comment into a machine-readable
    rule; the report itself comes from the compiler. The patch and changelog
    were drafted with Claude Opus 5.5. I reviewed the patch and take
    responsibility for it.
    
    Testing: builds without new warnings with W=1 (x86_64, clang 23,
    allmodconfig). Not runtime-tested; I do not have this hardware, and I
    have not observed the race myself.

 drivers/video/fbdev/udlfb.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
index 8b7b4bdac4fb..521a8392df82 100644
--- a/drivers/video/fbdev/udlfb.c
+++ b/drivers/video/fbdev/udlfb.c
@@ -1496,7 +1496,9 @@ static ssize_t edid_store(
 	if (!dlfb->edid || memcmp(src, dlfb->edid, src_size))
 		return -EINVAL;
 
+	mutex_lock(&fb_info->lock);
 	ret = dlfb_ops_set_par(fb_info);
+	mutex_unlock(&fb_info->lock);
 	if (ret)
 		return ret;
 
-- 
2.25.1


                 reply	other threads:[~2026-12-04 18:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261204185136.1688369-1-praneethb2002@gmail.com \
    --to=praneethb2002@gmail.com \
    --cc=bernie@plugable.com \
    --cc=deller@gmx.de \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpatocka@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=xmei5@asu.edu \
    /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