* [PATCH] fbdev: udlfb: don't rebuild the mode list while the framebuffer is in use
@ 2026-09-12 21:15 Xiang Mei
2026-09-12 21:29 ` sashiko-bot
2026-09-12 21:49 ` Helge Deller
0 siblings, 2 replies; 3+ messages in thread
From: Xiang Mei @ 2026-09-12 21:15 UTC (permalink / raw)
To: bernie, deller, linux-fbdev, dri-devel
Cc: gregkh, co+ed9902f2e44184d9, Xiang Mei, stable
dlfb_setup_modes() frees info->modelist with fb_destroy_modelist() and
rebuilds it, but fbcon holds raw pointers into that list in
fb_display[i].mode and nothing un-publishes them the way
do_unregister_framebuffer() and store_modes() do with
fbcon_delete_modelist(). The function does refuse to install a new mode
while the framebuffer has users (dlfb->fb_count != 0), but only after the
list is already destroyed. Reached from the 0666 "edid" sysfs attribute,
an unprivileged write to /sys/class/graphics/fb0/edid therefore fails with
-EINVAL and still leaves every fb_display[i].mode dangling; the next
console switch reads the freed fb_videomode in fb_videomode_to_var().
Test fb_count before touching the list. fbcon takes a reference through
fbcon_open(), so that condition covers exactly the states in which
fb_display[] points into the list, and the errno returned to userspace is
unchanged.
BUG: KASAN: slab-use-after-free in fb_videomode_to_var (drivers/video/fbdev/core/modedb.c:905)
Read of size 4 at addr ffff8880107b449c by task kworker/1:1/47
Workqueue: events console_callback
Call Trace:
fb_videomode_to_var (drivers/video/fbdev/core/modedb.c:905)
display_to_var (drivers/video/fbdev/core/fbcon.c:998)
fbcon_switch (drivers/video/fbdev/core/fbcon.c:2182)
redraw_screen (drivers/tty/vt/vt.c:994)
complete_change_console (drivers/tty/vt/vt_ioctl.c:1141)
console_callback (drivers/tty/vt/vt.c:3358)
process_one_work (kernel/workqueue.c:3396)
worker_thread (kernel/workqueue.c:3479 kernel/workqueue.c:3560)
kthread (kernel/kthread.c:436)
ret_from_fork (arch/x86/kernel/process.c:158)
ret_from_fork_asm (arch/x86/entry/entry_64.S:245)
...
The buggy address is located 28 bytes inside of
freed 96-byte region [ffff8880107b4480, ffff8880107b44e0)
Cc: stable@vger.kernel.org
Fixes: 7d9485e2c53c ("Staging: udlfb: Add functions to expose sysfs metrics and controls")
Reported-by: co+ed9902f2e44184d9@bugs.sh
Closes: https://lore.kernel.org/all/1jSCSNaDKmuUG7h40rTsSl1rMaSwdlJef4rp%40bugs.sh/
Assisted-by: Claude:claude-opus-5
Signed-off-by: Xiang Mei <xmei5@asu.edu>
---
drivers/video/fbdev/udlfb.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
index e78d6f95c9c5..92b352bc7e96 100644
--- a/drivers/video/fbdev/udlfb.c
+++ b/drivers/video/fbdev/udlfb.c
@@ -1293,6 +1293,11 @@ static int dlfb_setup_modes(struct dlfb_data *dlfb,
goto error;
}
+ if (dlfb->fb_count) {
+ result = -EINVAL;
+ goto error;
+ }
+
fb_destroy_modelist(&info->modelist);
memset(&info->monspecs, 0, sizeof(info->monspecs));
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] fbdev: udlfb: don't rebuild the mode list while the framebuffer is in use
2026-09-12 21:15 [PATCH] fbdev: udlfb: don't rebuild the mode list while the framebuffer is in use Xiang Mei
@ 2026-09-12 21:29 ` sashiko-bot
2026-09-12 21:49 ` Helge Deller
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-09-12 21:29 UTC (permalink / raw)
To: Xiang Mei; +Cc: dri-devel
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing locking in edid_store() leads to data races, double free, and memory corruption.
- [High] The patch fails to prevent a Use-After-Free of `fb_info->mode` via sysfs attributes.
- [High] The `edid` sysfs attribute is world-writable (0666), enabling unprivileged users to exploit multiple driver vulnerabilities.
- [Medium] Repeated calls to `dlfb_setup_modes()` leak the old `dlfb->edid` buffer.
- [Medium] Unbounded memory leak of the dynamically allocated `info->monspecs.modedb` array.
--
commit c422e1f65727b9cb9b5d809088416cf97c54aea9
Author: Xiang Mei <xmei5@asu.edu>
fbdev: udlfb: don't rebuild the mode list while the framebuffer is in use
This commit attempts to fix a use-after-free in fb_videomode_to_var() by
checking dlfb->fb_count before destroying the modelist in
dlfb_setup_modes(). This prevents fbcon from referencing a freed mode
list.
Link: https://lore.kernel.org/all/1jSCSNaDKmuUG7h40rTsSl1rMaSwdlJef4rp%40bugs.sh/
> diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
> index e78d6f95c9c5c..92b352bc7e969 100644
> --- a/drivers/video/fbdev/udlfb.c
> +++ b/drivers/video/fbdev/udlfb.c
> @@ -1293,6 +1293,11 @@ static int dlfb_setup_modes(struct dlfb_data *dlfb,
> goto error;
> }
>
> + if (dlfb->fb_count) {
> + result = -EINVAL;
> + goto error;
> + }
> +
> fb_destroy_modelist(&info->modelist);
[Severity: High]
This isn't a bug introduced by this patch, but does writing to the mode sysfs
attribute increment dlfb->fb_count?
If an unprivileged user sets fb_info->mode to a node in info->modelist via
fbsysfs.c:store_mode(), and then writes to the edid sysfs attribute,
dlfb->fb_count remains 0. The check above passes, and fb_destroy_modelist()
is executed, leaving fb_info->mode as a dangling pointer.
Subsequent reads from the mode sysfs attribute would invoke show_mode(),
triggering a use-after-free.
> memset(&info->monspecs, 0, sizeof(info->monspecs));
[Severity: Medium]
This is a pre-existing issue, but does this memset() leak the dynamically
allocated info->monspecs.modedb array?
If fb_edid_to_monspecs() previously parsed the EDID and dynamically allocated
the array of struct fb_videomode, unconditionally zeroing the structure here
appears to erase the pointer before it can be freed, leaking the memory on
every sysfs write.
[Severity: Medium]
While not introduced by this patch, could this leak the old dlfb->edid
buffer?
When dlfb_setup_modes() succeeds:
drivers/video/fbdev/udlfb.c:dlfb_setup_modes() {
...
if (info->monspecs.modedb_len > 0) {
dlfb->edid = edid;
dlfb->edid_size = i;
break;
}
...
}
Does this overwrite dlfb->edid with a newly allocated 128-byte edid buffer
without freeing the previous pointer?
[Severity: High]
This is a pre-existing issue, but is it safe for edid_store() to call
dlfb_ops_set_par() without holding info->lock?
drivers/video/fbdev/udlfb.c:edid_store() {
...
ret = dlfb_ops_set_par(fb_info);
...
}
dlfb_ops_set_par() invokes dlfb_realloc_framebuffer() which performs memory
freeing and list_add() operations, explicitly relying on the lock:
drivers/video/fbdev/udlfb.c:dlfb_realloc_framebuffer() {
/*
* Assumes &info->lock held by caller
*/
static int dlfb_realloc_framebuffer(struct dlfb_data *dlfb,
struct fb_info *info, u32 new_len)
...
}
If an unprivileged user concurrently writes to the edid sysfs attribute,
could this lead to data races resulting in a double-free of
info->screen_buffer and list corruption on dlfb->deferred_free?
[Severity: High]
Finally, as a pre-existing issue, should the edid sysfs attribute be
world-writable?
drivers/video/fbdev/udlfb.c:edid_attr {
static const struct bin_attribute edid_attr = {
.attr.name = "edid",
.attr.mode = 0666,
.size = EDID_LENGTH,
.read = edid_show,
.write = edid_store
};
}
This 0666 permission allows any unprivileged user to alter the physical
display configuration, and easily trigger the memory leaks, double frees,
and use-after-free vulnerabilities mentioned above.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260912211512.2049147-1-xmei5@asu.edu?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] fbdev: udlfb: don't rebuild the mode list while the framebuffer is in use
2026-09-12 21:15 [PATCH] fbdev: udlfb: don't rebuild the mode list while the framebuffer is in use Xiang Mei
2026-09-12 21:29 ` sashiko-bot
@ 2026-09-12 21:49 ` Helge Deller
1 sibling, 0 replies; 3+ messages in thread
From: Helge Deller @ 2026-09-12 21:49 UTC (permalink / raw)
To: Xiang Mei, bernie, linux-fbdev, dri-devel; +Cc: gregkh, co+ed9902f2e44184d9
On 9/12/26 23:15, Xiang Mei wrote:
> dlfb_setup_modes() frees info->modelist with fb_destroy_modelist() and
> rebuilds it, but fbcon holds raw pointers into that list in
> fb_display[i].mode and nothing un-publishes them the way
> do_unregister_framebuffer() and store_modes() do with
> fbcon_delete_modelist(). The function does refuse to install a new mode
> while the framebuffer has users (dlfb->fb_count != 0), but only after the
> list is already destroyed. Reached from the 0666 "edid" sysfs attribute,
> an unprivileged write to /sys/class/graphics/fb0/edid therefore fails with
> -EINVAL and still leaves every fb_display[i].mode dangling; the next
> console switch reads the freed fb_videomode in fb_videomode_to_var().
>
> Test fb_count before touching the list. fbcon takes a reference through
> fbcon_open(), so that condition covers exactly the states in which
> fb_display[] points into the list, and the errno returned to userspace is
> unchanged.
>
> BUG: KASAN: slab-use-after-free in fb_videomode_to_var (drivers/video/fbdev/core/modedb.c:905)
> Read of size 4 at addr ffff8880107b449c by task kworker/1:1/47
> Workqueue: events console_callback
> Call Trace:
> fb_videomode_to_var (drivers/video/fbdev/core/modedb.c:905)
> display_to_var (drivers/video/fbdev/core/fbcon.c:998)
> fbcon_switch (drivers/video/fbdev/core/fbcon.c:2182)
> redraw_screen (drivers/tty/vt/vt.c:994)
> complete_change_console (drivers/tty/vt/vt_ioctl.c:1141)
> console_callback (drivers/tty/vt/vt.c:3358)
> process_one_work (kernel/workqueue.c:3396)
> worker_thread (kernel/workqueue.c:3479 kernel/workqueue.c:3560)
> kthread (kernel/kthread.c:436)
> ret_from_fork (arch/x86/kernel/process.c:158)
> ret_from_fork_asm (arch/x86/entry/entry_64.S:245)
> ...
> The buggy address is located 28 bytes inside of
> freed 96-byte region [ffff8880107b4480, ffff8880107b44e0)
>
> Cc: stable@vger.kernel.org
> Fixes: 7d9485e2c53c ("Staging: udlfb: Add functions to expose sysfs metrics and controls")
> Reported-by: co+ed9902f2e44184d9@bugs.sh
> Closes: https://lore.kernel.org/all/1jSCSNaDKmuUG7h40rTsSl1rMaSwdlJef4rp%40bugs.sh/
> Assisted-by: Claude:claude-opus-5
> Signed-off-by: Xiang Mei <xmei5@asu.edu>
> ---
> drivers/video/fbdev/udlfb.c | 5 +++++
> 1 file changed, 5 insertions(+)
Looks good.
Applied.
Thanks!
Helge
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-09-12 21:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-12 21:15 [PATCH] fbdev: udlfb: don't rebuild the mode list while the framebuffer is in use Xiang Mei
2026-09-12 21:29 ` sashiko-bot
2026-09-12 21:49 ` Helge Deller
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.