* [PATCH] fbdev: udlfb: Hold info->lock when edid_store() sets the mode
@ 2026-12-04 18:51 Praneeth Balasubramanian
0 siblings, 0 replies; only message in thread
From: Praneeth Balasubramanian @ 2026-12-04 18:51 UTC (permalink / raw)
To: Helge Deller, Bernie Thompson
Cc: Mikulas Patocka, Xiang Mei, linux-fbdev, dri-devel, linux-kernel,
Praneeth Balasubramanian, stable
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-04 18:51 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 18:51 [PATCH] fbdev: udlfb: Hold info->lock when edid_store() sets the mode Praneeth Balasubramanian
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox