All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] fbdev: fix udlfb shadow buffer and framebuffer registration
@ 2026-12-04  9:04 YuanZhe Liu
  2026-12-04  9:04 ` [PATCH 1/2] fbdev: udlfb: drop stale shadow buffer when the framebuffer grows YuanZhe Liu
  2026-12-04  9:04 ` [PATCH 2/2] fbdev: fbmem: don't fail registration when fbcon cannot take over YuanZhe Liu
  0 siblings, 2 replies; 4+ messages in thread
From: YuanZhe Liu @ 2026-12-04  9:04 UTC (permalink / raw)
  To: Bernie Thompson, Simona Vetter
  Cc: Helge Deller, Thomas Zimmermann, linux-fbdev, dri-devel,
	linux-kernel, stable, Bin Yu, Cheng Wen

These patches fix 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.

Based on v7.3.5.

YuanZhe Liu (2):
  fbdev: udlfb: drop stale shadow buffer 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      | 12 ++++++++++--
 2 files changed, 17 insertions(+), 3 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] fbdev: udlfb: drop stale shadow buffer when the framebuffer grows
  2026-12-04  9:04 [PATCH 0/2] fbdev: fix udlfb shadow buffer and framebuffer registration YuanZhe Liu
@ 2026-12-04  9:04 ` YuanZhe Liu
  2026-12-04  9:22   ` sashiko-bot
  2026-12-04  9:04 ` [PATCH 2/2] fbdev: fbmem: don't fail registration when fbcon cannot take over YuanZhe Liu
  1 sibling, 1 reply; 4+ messages in thread
From: YuanZhe Liu @ 2026-12-04  9:04 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 logs a message but keeps the previous, smaller shadow buffer.

dlfb_render_hline() then compares lines of the new framebuffer against
the old shadow buffer at offsets derived from the new geometry, reading
beyond the end of the smaller allocation.

Drop the old shadow buffer when a new one cannot be created, so that
damage rendering falls back to sending the full line as intended.

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>
---
 drivers/video/fbdev/udlfb.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
index 8b7b4bdac4fb..917bcef4bb69 100644
--- a/drivers/video/fbdev/udlfb.c
+++ b/drivers/video/fbdev/udlfb.c
@@ -1248,10 +1248,18 @@ static int dlfb_realloc_framebuffer(struct dlfb_data *dlfb, struct fb_info *info
 		 */
 		if (shadow)
 			new_back = vzalloc(new_len);
-		if (!new_back)
+		if (!new_back) {
 			dev_info(info->dev,
 				 "No shadow/backing buffer allocated\n");
-		else {
+			/*
+			 * The old shadow buffer is smaller than the new
+			 * framebuffer and can no longer be used for comparing.
+			 */
+			if (dlfb->backing_buffer) {
+				dlfb_deferred_vfree(dlfb, dlfb->backing_buffer);
+				dlfb->backing_buffer = NULL;
+			}
+		} else {
 			dlfb_deferred_vfree(dlfb, dlfb->backing_buffer);
 			dlfb->backing_buffer = new_back;
 		}
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] fbdev: fbmem: don't fail registration when fbcon cannot take over
  2026-12-04  9:04 [PATCH 0/2] fbdev: fix udlfb shadow buffer and framebuffer registration YuanZhe Liu
  2026-12-04  9:04 ` [PATCH 1/2] fbdev: udlfb: drop stale shadow buffer when the framebuffer grows YuanZhe Liu
@ 2026-12-04  9:04 ` YuanZhe Liu
  1 sibling, 0 replies; 4+ messages in thread
From: YuanZhe Liu @ 2026-12-04  9:04 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] 4+ messages in thread

* Re: [PATCH 1/2] fbdev: udlfb: drop stale shadow buffer when the framebuffer grows
  2026-12-04  9:04 ` [PATCH 1/2] fbdev: udlfb: drop stale shadow buffer when the framebuffer grows YuanZhe Liu
@ 2026-12-04  9:22   ` sashiko-bot
  0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-12-04  9:22 UTC (permalink / raw)
  To: YuanZhe Liu; +Cc: dri-devel

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] fbdev: udlfb: unsynchronized backing_buffer clear races with
  render_hline()
- [Medium] fbdev: udlfb: dlfb_deferred_vfree() on OOM path leaks or pins
  shadow buffer
--

commit 8f1d574fcc8d77dc56b4c4144bf3b2dcaee63c24
Author: YuanZhe Liu <25031212351@stu.xidian.edu.cn>

fbdev: udlfb: drop stale shadow buffer when the framebuffer grows

This commit drops dlfb->backing_buffer via dlfb_deferred_vfree() and clears
it to NULL in dlfb_realloc_framebuffer() when a new shadow buffer is not
allocated.

> diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
> index 8b7b4bdac4fbf..917bcef4bb695 100644
> --- a/drivers/video/fbdev/udlfb.c
> +++ b/drivers/video/fbdev/udlfb.c
> @@ -1248,10 +1248,18 @@ static int dlfb_realloc_framebuffer(struct dlfb_data *dlfb, struct fb_info *info
>  		 */
>  		if (shadow)
>  			new_back = vzalloc(new_len);
> -		if (!new_back)
> +		if (!new_back) {
>  			dev_info(info->dev,
>  				 "No shadow/backing buffer allocated\n");
> -		else {
> +			/*
> +			 * The old shadow buffer is smaller than the new
> +			 * framebuffer and can no longer be used for comparing.
> +			 */
> +			if (dlfb->backing_buffer) {
> +				dlfb_deferred_vfree(dlfb, dlfb->backing_buffer);
> +				dlfb->backing_buffer = NULL;
> +			}

[Severity: High]
Can clearing dlfb->backing_buffer without holding dlfb->render_mutex race
with dlfb_render_hline() and cause a NULL pointer dereference?

dlfb_realloc_framebuffer() runs without dlfb->render_mutex, while
dlfb_damage_work() -> dlfb_handle_damage() -> dlfb_render_hline() runs
under dlfb->render_mutex without info->lock.  dlfb_render_hline() reads
dlfb->backing_buffer twice without caching it:

CPU0                            CPU1
fb_set_var()
  dlfb_ops_set_par()
    dlfb_realloc_framebuffer()
                                dlfb_damage_work()
                                  dlfb_handle_damage()
                                    mutex_lock(&dlfb->render_mutex)
                                    dlfb_render_hline()
                                      if (dlfb->backing_buffer)
      dlfb->backing_buffer = NULL
                                      back_start = dlfb->backing_buffer
                                                   + byte_offset
                                      dlfb_trim_hline(back_start, ...)
                                        <-- NULL+offset dereference

There is also an out-of-bounds window before dlfb->backing_buffer is
updated: fb_set_var() publishes the larger info->var and
dlfb_realloc_framebuffer() updates info->fix.smem_len before sleeping in
vzalloc(), so concurrent rendering can still index past the smaller buffer.

Updating the buffer pointers under dlfb->render_mutex (nested inside
info->lock, matching dlfb_ops_set_par()) would close both races.

[Severity: Medium]
Can calling dlfb_deferred_vfree() here leak the old dlfb->backing_buffer
under memory pressure?

dlfb_deferred_vfree() allocates a tracking struct with kmalloc_obj() and
returns silently on failure.  When !new_back is reached because vzalloc()
failed under memory pressure, kmalloc_obj() can fail too, permanently
leaking the old shadow buffer once dlfb->backing_buffer is cleared.

Even when kmalloc_obj() succeeds, deferring vfree() keeps the unused
shadow buffer pinned until device teardown.  Unlike info->screen_buffer,
dlfb->backing_buffer is driver-internal, so synchronizing the swap with
dlfb->render_mutex allows freeing it directly with vfree() after unlocking.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204090457.7130-1-25031212351@stu.xidian.edu.cn?part=1

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-12-04  9:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04  9:04 [PATCH 0/2] fbdev: fix udlfb shadow buffer and framebuffer registration YuanZhe Liu
2026-12-04  9:04 ` [PATCH 1/2] fbdev: udlfb: drop stale shadow buffer when the framebuffer grows YuanZhe Liu
2026-12-04  9:22   ` sashiko-bot
2026-12-04  9:04 ` [PATCH 2/2] fbdev: fbmem: don't fail registration when fbcon cannot take over YuanZhe Liu

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.