Skip to contentSkip to conversation

fbdev: udlfb: Hold info->lock when edid_store() sets the mode

PATCH New Praneeth Balasubramanian 1 participant 1 message Dec 4

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fbdev: udlfb: Hold info->lock when edid_store() sets the mode

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.

Fixes 7433914efd58 ("udlfb: allow reallocating the framebuffer")

---

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(+)
drivers/video/fbdev/udlfb.c +2 -0
index 8b7b4bdac4fb..521a8392df82 100644
@@ -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;
 
Signature · 1 line
2.25.1