* [PATCH v2 0/2] fbdev: fix udlfb shadow buffer and framebuffer registration
@ 2026-12-04 9:35 YuanZhe Liu
2026-12-04 16:08 ` [PATCH v2 1/2] fbdev: udlfb: fix shadow buffer handling when the framebuffer grows YuanZhe Liu
0 siblings, 1 reply; 5+ messages in thread
From: YuanZhe Liu @ 2026-12-04 9:35 UTC (permalink / raw)
To: Bernie Thompson, Simona Vetter
Cc: Helge Deller, Thomas Zimmermann, linux-fbdev, dri-devel,
linux-kernel, stable, Bin Yu, Cheng Wen
This series fixes two independent problems in the fbdev paths used by
the udlfb driver. Both were found while analyzing failures observed on
a DisplayLink USB adapter; the changes are compile-tested only and no
hardware testing was performed.
Patch 1 fixes an out-of-bounds read when the framebuffer is switched to
a larger mode while the shadow buffer is disabled or its allocation
fails. The driver kept the previous, smaller shadow buffer and
dlfb_render_hline() used it to compare lines of the larger framebuffer.
Patch 2 fixes framebuffer registration reporting a failure after the
framebuffer has already been registered. A failed console takeover is
not fatal for the framebuffer itself, but drivers treated the error as
fatal, freed the live fb_info and left a dangling entry in
registered_fb[]; the next open then dereferenced freed memory.
Changes in v2:
- Patch 1: publish the new buffers and geometry under
dlfb->render_mutex, free the stale shadow buffer directly, and
validate damage requests against the installed framebuffer.
Patch 2 is unchanged.
Based on v7.3.5.
YuanZhe Liu (2):
fbdev: udlfb: fix shadow buffer handling when the framebuffer grows
fbdev: fbmem: don't fail registration when fbcon cannot take over
drivers/video/fbdev/core/fbmem.c | 8 +++++-
drivers/video/fbdev/udlfb.c | 45 +++++++++++++++++++++++++-------
2 files changed, 43 insertions(+), 10 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v2 1/2] fbdev: udlfb: fix shadow buffer handling when the framebuffer grows 2026-12-04 9:35 [PATCH v2 0/2] fbdev: fix udlfb shadow buffer and framebuffer registration YuanZhe Liu @ 2026-12-04 16:08 ` YuanZhe Liu 2026-12-04 16:08 ` [PATCH v2 2/2] fbdev: fbmem: don't fail registration when fbcon cannot take over YuanZhe Liu 2026-12-04 16:28 ` [PATCH v2 1/2] fbdev: udlfb: fix shadow buffer handling when the framebuffer grows sashiko-bot 0 siblings, 2 replies; 5+ messages in thread From: YuanZhe Liu @ 2026-12-04 16:08 UTC (permalink / raw) To: Bernie Thompson, Simona Vetter Cc: Helge Deller, Thomas Zimmermann, linux-fbdev, dri-devel, linux-kernel, stable, Bin Yu, Cheng Wen dlfb_realloc_framebuffer() grows the virtual framebuffer when a larger video mode is set. The shadow buffer that mirrors the data sent to the device is only reallocated when shadowing is enabled and the allocation succeeds. If shadowing is disabled at runtime or the allocation fails, the driver keeps the previous, smaller shadow buffer, and dlfb_render_hline() later compares lines of the larger framebuffer against it, reading beyond the end of the smaller allocation. Allocate the new shadow buffer before publishing the new geometry and replace both buffers under dlfb->render_mutex, which serializes damage rendering. Free the old shadow buffer directly afterwards; it is only used by damage rendering, which no longer references it. info->var can already describe the new mode before dlfb_ops_set_par() installs the matching framebuffer. Reject damage requests that do not fit into the installed framebuffer, so that concurrent rendering cannot walk past the buffers of the previous mode either. Fixes: 7433914efd58 ("udlfb: allow reallocating the framebuffer") Cc: stable@vger.kernel.org Co-developed-by: Bin Yu <byu@xidian.edu.cn> Signed-off-by: Bin Yu <byu@xidian.edu.cn> Co-developed-by: Cheng Wen <wencheng@xidian.edu.cn> Signed-off-by: Cheng Wen <wencheng@xidian.edu.cn> Signed-off-by: YuanZhe Liu <25031212351@stu.xidian.edu.cn> --- Changes in v2: - Publish the new buffers and geometry under dlfb->render_mutex and free the stale shadow buffer directly instead of deferring it. - Validate damage requests against the installed framebuffer so that concurrent rendering cannot walk past the previous mode's buffers. drivers/video/fbdev/udlfb.c | 45 +++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c index 8b7b4bdac4fb..66d30cdfbe60 100644 --- a/drivers/video/fbdev/udlfb.c +++ b/drivers/video/fbdev/udlfb.c @@ -646,6 +646,18 @@ static int dlfb_handle_damage(struct dlfb_data *dlfb, int x, int y, int width, i goto unlock_ret; } + /* + * info->var can describe the new mode before dlfb_ops_set_par() + * installs the matching framebuffer. Reject damage that does not + * fit into the framebuffer that is currently installed. + */ + if (height > 0 && + ((u64)y + height - 1) * dlfb->info->fix.line_length + + (u64)(x + width) * BPP > dlfb->info->fix.smem_len) { + ret = -EINVAL; + goto unlock_ret; + } + if (!atomic_read(&dlfb->usb_active)) { ret = 0; goto unlock_ret; @@ -1209,6 +1221,7 @@ static int dlfb_realloc_framebuffer(struct dlfb_data *dlfb, struct fb_info *info const void *old_fb = info->screen_buffer; unsigned char *new_fb; unsigned char *new_back = NULL; + unsigned char *old_back; new_len = PAGE_ALIGN(new_len); @@ -1235,11 +1248,6 @@ static int dlfb_realloc_framebuffer(struct dlfb_data *dlfb, struct fb_info *info dlfb_deferred_vfree(dlfb, info->screen_buffer); } - info->screen_buffer = new_fb; - info->fix.smem_len = new_len; - info->fix.smem_start = (unsigned long) new_fb; - info->flags = udlfb_info_flags; - /* * Second framebuffer copy to mirror the framebuffer state * on the physical USB device. We can function without this. @@ -1251,10 +1259,29 @@ static int dlfb_realloc_framebuffer(struct dlfb_data *dlfb, struct fb_info *info if (!new_back) dev_info(info->dev, "No shadow/backing buffer allocated\n"); - else { - dlfb_deferred_vfree(dlfb, dlfb->backing_buffer); - dlfb->backing_buffer = new_back; - } + + /* + * Damage rendering reads the buffers and the geometry under + * dlfb->render_mutex. Publish the new state under the same + * lock so that it never pairs the new framebuffer with the + * old shadow buffer. + */ + mutex_lock(&dlfb->render_mutex); + old_back = dlfb->backing_buffer; + dlfb->backing_buffer = new_back; + info->screen_buffer = new_fb; + info->fix.smem_len = new_len; + info->fix.smem_start = (unsigned long) new_fb; + info->flags = udlfb_info_flags; + mutex_unlock(&dlfb->render_mutex); + + /* + * The shadow buffer is only used by damage rendering, which + * no longer references the old one; it can be freed directly. + * The old framebuffer may still be touched by fbcon, so it + * stays on the deferred list. + */ + vfree(old_back); } return 0; } -- 2.34.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] fbdev: fbmem: don't fail registration when fbcon cannot take over 2026-12-04 16:08 ` [PATCH v2 1/2] fbdev: udlfb: fix shadow buffer handling when the framebuffer grows YuanZhe Liu @ 2026-12-04 16:08 ` YuanZhe Liu 2026-12-04 16:44 ` sashiko-bot 2026-12-04 16:28 ` [PATCH v2 1/2] fbdev: udlfb: fix shadow buffer handling when the framebuffer grows sashiko-bot 1 sibling, 1 reply; 5+ messages in thread From: YuanZhe Liu @ 2026-12-04 16:08 UTC (permalink / raw) To: Bernie Thompson, Simona Vetter Cc: Helge Deller, Thomas Zimmermann, linux-fbdev, dri-devel, linux-kernel, stable, Bin Yu, Cheng Wen do_register_framebuffer() installs the framebuffer in registered_fb[], sets its reference count and registers it with fbcon. It then returns the result of fbcon_fb_registered() to the caller, so a failed console takeover is reported as a registration failure even though the framebuffer itself is fully registered. A driver can reject fbcon's internal fb_open() call, which makes the takeover fail. The driver then frees the fb_info because it was told that registration failed, leaving a dangling entry in registered_fb[] and triggering the reference-count warning in framebuffer_release(). Console takeover is auxiliary. Report success once the framebuffer is registered and leave the console unbound if the takeover failed. Fixes: 97b67986f145 ("fbcon: call fbcon_fb_(un)registered directly") Cc: stable@vger.kernel.org Co-developed-by: Bin Yu <byu@xidian.edu.cn> Signed-off-by: Bin Yu <byu@xidian.edu.cn> Co-developed-by: Cheng Wen <wencheng@xidian.edu.cn> Signed-off-by: Cheng Wen <wencheng@xidian.edu.cn> Signed-off-by: YuanZhe Liu <25031212351@stu.xidian.edu.cn> --- drivers/video/fbdev/core/fbmem.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c index c8aa163b0ecf..2f6d6be673b4 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -535,7 +535,13 @@ static int do_register_framebuffer(struct fb_info *fb_info) } #endif - return fbcon_fb_registered(fb_info); + /* + * The framebuffer is registered now. A failed console takeover + * is not a registration failure; reporting it would make drivers + * free a live fb_info and leave registered_fb[] dangling. + */ + fbcon_fb_registered(fb_info); + return 0; } static void unbind_console(struct fb_info *fb_info) -- 2.34.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 2/2] fbdev: fbmem: don't fail registration when fbcon cannot take over 2026-12-04 16:08 ` [PATCH v2 2/2] fbdev: fbmem: don't fail registration when fbcon cannot take over YuanZhe Liu @ 2026-12-04 16:44 ` sashiko-bot 0 siblings, 0 replies; 5+ messages in thread From: sashiko-bot @ 2026-12-04 16:44 UTC (permalink / raw) To: YuanZhe Liu; +Cc: dri-devel Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] fbdev: fbcon_fb_registered() and do_fb_registered() have unused int return -- commit 9a79cb5d4a64251e588b11510f76e1464adc18ad Author: YuanZhe Liu <25031212351@stu.xidian.edu.cn> fbdev: fbmem: don't fail registration when fbcon cannot take over This commit ignores the return value of fbcon_fb_registered() in do_register_framebuffer() and returns 0 instead, so a failed console takeover no longer fails framebuffer registration. > diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c > index c8aa163b0ecfa..2f6d6be673b47 100644 > --- a/drivers/video/fbdev/core/fbmem.c > +++ b/drivers/video/fbdev/core/fbmem.c > @@ -535,7 +535,13 @@ static int do_register_framebuffer(struct fb_info *fb_info) > } > #endif > > - return fbcon_fb_registered(fb_info); > + /* > + * The framebuffer is registered now. A failed console takeover > + * is not a registration failure; reporting it would make drivers > + * free a live fb_info and leave registered_fb[] dangling. > + */ > + fbcon_fb_registered(fb_info); > + return 0; [Severity: Low] Should fbcon_fb_registered() and do_fb_registered() be changed to return void now that do_register_framebuffer() ignores the return value? do_register_framebuffer() is the sole caller of fbcon_fb_registered(), and the only other caller of do_fb_registered() (fbcon_register_existing_fbs()) already discards its return value. Converting both functions and the !CONFIG_FRAMEBUFFER_CONSOLE stub in drivers/video/fbdev/core/fbcon.h to void would remove the unused return-value plumbing and match the sibling fbcon_fb_unregistered() and fbcon_fb_unbind() hooks. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261204093601.9900-1-25031212351@stu.xidian.edu.cn?part=2 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] fbdev: udlfb: fix shadow buffer handling when the framebuffer grows 2026-12-04 16:08 ` [PATCH v2 1/2] fbdev: udlfb: fix shadow buffer handling when the framebuffer grows YuanZhe Liu 2026-12-04 16:08 ` [PATCH v2 2/2] fbdev: fbmem: don't fail registration when fbcon cannot take over YuanZhe Liu @ 2026-12-04 16:28 ` sashiko-bot 1 sibling, 0 replies; 5+ messages in thread From: sashiko-bot @ 2026-12-04 16:28 UTC (permalink / raw) To: YuanZhe Liu; +Cc: dri-devel Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] fbdev: udlfb: TOCTOU race on fix.line_length bypasses damage bounds check -- commit 6373d803390e810d07fa3293f989ab90570a3e4c Author: YuanZhe Liu <25031212351@stu.xidian.edu.cn> fbdev: udlfb: fix shadow buffer handling when the framebuffer grows This commit allocates the new shadow buffer before publishing the new framebuffer and geometry under dlfb->render_mutex, frees the old shadow buffer directly, and adds a bounds check against info->fix.smem_len in dlfb_handle_damage(). > diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c > index 8b7b4bdac4fbf..66d30cdfbe606 100644 > --- a/drivers/video/fbdev/udlfb.c > +++ b/drivers/video/fbdev/udlfb.c > @@ -646,6 +646,18 @@ static int dlfb_handle_damage(struct dlfb_data *dlfb, int x, int y, int width, i > goto unlock_ret; > } > > + /* > + * info->var can describe the new mode before dlfb_ops_set_par() > + * installs the matching framebuffer. Reject damage that does not > + * fit into the framebuffer that is currently installed. > + */ > + if (height > 0 && > + ((u64)y + height - 1) * dlfb->info->fix.line_length + > + (u64)(x + width) * BPP > dlfb->info->fix.smem_len) { > + ret = -EINVAL; > + goto unlock_ret; > + } [Severity: High] Can a concurrent update to info->fix.line_length bypass this bounds check? dlfb_ops_set_par() updates info->fix.line_length without holding dlfb->render_mutex, while dlfb_handle_damage() reloads dlfb->info->fix.line_length on every scanline iteration across sleepable dlfb_get_urb() calls: CPU0 (dlfb_damage_work) CPU1 (FBIOPUT_VSCREENINFO) dlfb_handle_damage() mutex_lock(&dlfb->render_mutex) bounds check (old line_length) dlfb_get_urb() (sleeps) dlfb_ops_set_par() dlfb_realloc_framebuffer() (new_len <= old_len, skips lock) info->fix.line_length = new_stride for (i = y; i < y + height; i++) line_offset = line_length * i dlfb_render_hline() dlfb_compress_hline() <-- out-of-bounds read/write When switching to a wider, shorter mode that fits in the existing allocation, dlfb_realloc_framebuffer() skips dlfb->render_mutex, and dlfb_damage_work() runs without info->lock. Once info->fix.line_length grows mid-loop, dlfb_compress_hline() reads past info->fix.smem_start and writes past dlfb->backing_buffer, which can oops or corrupt adjacent vmalloc allocations. Updating info->fix.line_length under dlfb->render_mutex in dlfb_ops_set_par() and snapshotting line_length locally in dlfb_handle_damage() would close this race. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261204093601.9900-1-25031212351@stu.xidian.edu.cn?part=1 ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-04 16:44 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-12-04 9:35 [PATCH v2 0/2] fbdev: fix udlfb shadow buffer and framebuffer registration YuanZhe Liu 2026-12-04 16:08 ` [PATCH v2 1/2] fbdev: udlfb: fix shadow buffer handling when the framebuffer grows YuanZhe Liu 2026-12-04 16:08 ` [PATCH v2 2/2] fbdev: fbmem: don't fail registration when fbcon cannot take over YuanZhe Liu 2026-12-04 16:44 ` sashiko-bot 2026-12-04 16:28 ` [PATCH v2 1/2] fbdev: udlfb: fix shadow buffer handling when the framebuffer grows sashiko-bot
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.