All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] fbcon: Fix segfault on re-orientation
@ 2026-11-26 16:23 Thomas Zimmermann
  2026-11-26 16:23 ` [PATCH 1/2] fbcon: Don't change shared blitting state for hidden consoles Thomas Zimmermann
  2026-11-26 16:23 ` [PATCH 2/2] fbcon: Provide a single implementation of fbcon_set_rotation() Thomas Zimmermann
  0 siblings, 2 replies; 5+ messages in thread
From: Thomas Zimmermann @ 2026-11-26 16:23 UTC (permalink / raw)
  To: deller, simona; +Cc: dri-devel, linux-fbdev, sashiko-reviews, Thomas Zimmermann

fbcon_init() re-rotates the console even when initializing a hidden
console. The rotated console then accesses its screen buffer with
regular bit ops. This results in a segmentation fault. Fix this by
resetting rotation only on new and visible consoles.

The problem can be reproduced by rotating the console on bochs and
shutting down the system. When plymouth opens the terminal, it
triggers the crash.

Patch 1 fixes the bug. I used an LLM to debug the issue and create
the fix. This goes first to simplify backporting.

Patch 2 slightly refactors the fix.

Thomas Zimmermann (2):
  fbcon: Don't change shared blitting state for hidden consoles
  fbcon: Provide a single implementation of fbcon_set_rotation()

 drivers/video/fbdev/core/fbcon.c | 43 ++++++++++++++++++++------------
 1 file changed, 27 insertions(+), 16 deletions(-)

-- 
2.56.1


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

* [PATCH 1/2] fbcon: Don't change shared blitting state for hidden consoles
  2026-11-26 16:23 [PATCH 0/2] fbcon: Fix segfault on re-orientation Thomas Zimmermann
@ 2026-11-26 16:23 ` Thomas Zimmermann
  2026-11-26 16:53   ` sashiko-bot
  2026-11-26 16:23 ` [PATCH 2/2] fbcon: Provide a single implementation of fbcon_set_rotation() Thomas Zimmermann
  1 sibling, 1 reply; 5+ messages in thread
From: Thomas Zimmermann @ 2026-11-26 16:23 UTC (permalink / raw)
  To: deller, simona; +Cc: dri-devel, linux-fbdev, sashiko-reviews, Thomas Zimmermann

All consoles on a framebuffer share par->rotate and par->bitops.
fbcon_init() calls set_blitting_type() for each new console, which
resets both to the new console's rotation. If the visible console is
rotated, it then keeps its rotated rows and columns but draws with
unrotated bitops. The next cursor update or scroll writes beyond the
framebuffer and oopses, e.g. at shutdown when plymouthd opens a new
VT:

  BUG: unable to handle page fault for address: ffffd2ce80bd5000
  RIP: 0010:sys_imageblit+0x707/0x7e0
   soft_cursor+0x1a4/0x250
   bit_cursor+0x3ab/0x550
   hide_cursor+0x27/0xb0

Only call set_blitting_type() from fbcon_init() for the visible console
or when the fbcon state was just created. Compute a new console's rows
and columns from its own rotation instead of par->rotate, so that it
doesn't inherit the visible console's geometry.

Tested on QEMU with console 0 rotated by 90 degrees. Other rotations
and rotate_all are untested.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/core/fbcon.c | 38 +++++++++++++++++++++++---------
 1 file changed, 28 insertions(+), 10 deletions(-)

diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c
index d7890e119dc7..7e39c40abe88 100644
--- a/drivers/video/fbdev/core/fbcon.c
+++ b/drivers/video/fbdev/core/fbcon.c
@@ -197,15 +197,20 @@ static void fbcon_set_all_vcs(struct fb_info *info);
 static struct device *fbcon_device;
 
 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
+/* Returns the rotation that a console uses when it is displayed. */
+static int fbcon_display_rotation(const struct fb_info *info, const struct fbcon_display *p)
+{
+	if (!(info->flags & FBINFO_MISC_TILEBLITTING) && p->con_rotate < 4)
+		return p->con_rotate;
+
+	return FB_ROTATE_UR;
+}
+
 static inline void fbcon_set_rotation(struct fb_info *info)
 {
 	struct fbcon_par *par = info->fbcon_par;
 
-	if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
-	    par->p->con_rotate < 4)
-		par->rotate = par->p->con_rotate;
-	else
-		par->rotate = 0;
+	par->rotate = fbcon_display_rotation(info, par->p);
 }
 
 static void fbcon_rotate(struct fb_info *info, u32 rotate)
@@ -253,6 +258,11 @@ static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
 	fbcon_set_all_vcs(info);
 }
 #else
+static int fbcon_display_rotation(const struct fb_info *info, const struct fbcon_display *p)
+{
+	return FB_ROTATE_UR;
+}
+
 static inline void fbcon_set_rotation(struct fb_info *info)
 {
 	struct fbcon_par *par = info->fbcon_par;
@@ -1105,6 +1115,8 @@ static void fbcon_init(struct vc_data *vc, bool init)
 	struct vc_data *svc = *default_mode;
 	struct fbcon_display *t, *p = &fb_display[vc->vc_num];
 	int logo = 1, new_rows, new_cols, rows, cols;
+	bool new_par = false;
+	int rotate;
 	int ret;
 
 	if (WARN_ON(info_idx == -1))
@@ -1125,9 +1137,11 @@ static void fbcon_init(struct vc_data *vc, bool init)
 	if (var_to_display(p, &info->var, info))
 		return;
 
-	if (!info->fbcon_par)
+	if (!info->fbcon_par) {
 		if (con2fb_acquire_newinfo(vc, info, vc->vc_num))
 			return;
+		new_par = true;
+	}
 
 	/* If we are not the first console on this
 	   fb, copy the font from that console */
@@ -1185,12 +1199,15 @@ static void fbcon_init(struct vc_data *vc, bool init)
 	if (p->con_rotate == -1)
 		p->con_rotate = FB_ROTATE_UR;
 
-	set_blitting_type(vc, info);
+	if (new_par || con_is_visible(vc))
+		set_blitting_type(vc, info);
 
 	cols = vc->vc_cols;
 	rows = vc->vc_rows;
-	new_cols = FBCON_SWAP(par->rotate, info->var.xres, info->var.yres);
-	new_rows = FBCON_SWAP(par->rotate, info->var.yres, info->var.xres);
+	/* Use the console's own rotation; par->rotate belongs to the visible one. */
+	rotate = fbcon_display_rotation(info, p);
+	new_cols = FBCON_SWAP(rotate, info->var.xres, info->var.yres);
+	new_rows = FBCON_SWAP(rotate, info->var.yres, info->var.xres);
 	new_cols /= vc->vc_font.width;
 	new_rows /= vc->vc_font.height;
 
@@ -1238,7 +1255,8 @@ static void fbcon_init(struct vc_data *vc, bool init)
 	if (logo)
 		fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
 
-	if (par->bitops->rotate_font && par->bitops->rotate_font(info, vc)) {
+	if ((new_par || con_is_visible(vc)) &&
+	    par->bitops->rotate_font && par->bitops->rotate_font(info, vc)) {
 		par->rotate = FB_ROTATE_UR;
 		set_blitting_type(vc, info);
 	}
-- 
2.56.1


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

* [PATCH 2/2] fbcon: Provide a single implementation of fbcon_set_rotation()
  2026-11-26 16:23 [PATCH 0/2] fbcon: Fix segfault on re-orientation Thomas Zimmermann
  2026-11-26 16:23 ` [PATCH 1/2] fbcon: Don't change shared blitting state for hidden consoles Thomas Zimmermann
@ 2026-11-26 16:23 ` Thomas Zimmermann
  2026-11-26 16:36   ` sashiko-bot
  1 sibling, 1 reply; 5+ messages in thread
From: Thomas Zimmermann @ 2026-11-26 16:23 UTC (permalink / raw)
  To: deller, simona; +Cc: dri-devel, linux-fbdev, sashiko-reviews, Thomas Zimmermann

Merge both implmentations of fbcon_set_rotation() into one. In the
case of CONFIG_FRAMEBUFFER_CONSOLE_ROTATION=n, fbcon_display_rotation()
returns FB_ROTATE_UR. So the new code is equivalent to the existing
code.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/core/fbcon.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c
index 7e39c40abe88..08712611e333 100644
--- a/drivers/video/fbdev/core/fbcon.c
+++ b/drivers/video/fbdev/core/fbcon.c
@@ -206,13 +206,6 @@ static int fbcon_display_rotation(const struct fb_info *info, const struct fbcon
 	return FB_ROTATE_UR;
 }
 
-static inline void fbcon_set_rotation(struct fb_info *info)
-{
-	struct fbcon_par *par = info->fbcon_par;
-
-	par->rotate = fbcon_display_rotation(info, par->p);
-}
-
 static void fbcon_rotate(struct fb_info *info, u32 rotate)
 {
 	struct fbcon_par *par = info->fbcon_par;
@@ -263,13 +256,6 @@ static int fbcon_display_rotation(const struct fb_info *info, const struct fbcon
 	return FB_ROTATE_UR;
 }
 
-static inline void fbcon_set_rotation(struct fb_info *info)
-{
-	struct fbcon_par *par = info->fbcon_par;
-
-	par->rotate = FB_ROTATE_UR;
-}
-
 static void fbcon_rotate(struct fb_info *info, u32 rotate)
 {
 	return;
@@ -281,6 +267,13 @@ static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
 }
 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
 
+static void fbcon_set_rotation(struct fb_info *info)
+{
+	struct fbcon_par *par = info->fbcon_par;
+
+	par->rotate = fbcon_display_rotation(info, par->p);
+}
+
 static void fbcon_set_bitops(struct fbcon_par *par)
 {
 	switch (par->rotate) {
-- 
2.56.1


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

* Re: [PATCH 2/2] fbcon: Provide a single implementation of fbcon_set_rotation()
  2026-11-26 16:23 ` [PATCH 2/2] fbcon: Provide a single implementation of fbcon_set_rotation() Thomas Zimmermann
@ 2026-11-26 16:36   ` sashiko-bot
  0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-26 16:36 UTC (permalink / raw)
  To: Thomas Zimmermann; +Cc: dri-devel

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] fbcon: unrotated mode fallback clobbered by set_blitting_type()
  [1]
--

commit b31c406a9ea618e6fff12f41e21bd7c311a16303
Author: Thomas Zimmermann <tzimmermann@suse.de>

fbcon: Provide a single implementation of fbcon_set_rotation()

This commit merges the CONFIG_FRAMEBUFFER_CONSOLE_ROTATION=y and =n
implementations of fbcon_set_rotation() into a single function calling
fbcon_display_rotation().

> diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c
> index 7bd51b9f4fe13..fd89465b0754e 100644
> --- a/drivers/video/fbdev/core/fbcon.c
> +++ b/drivers/video/fbdev/core/fbcon.c
[ ... ]
> @@ -281,6 +267,13 @@ static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
>  }
>  #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
>  
> +static void fbcon_set_rotation(struct fb_info *info)
> +{
> +	struct fbcon_par *par = info->fbcon_par;
> +
> +	par->rotate = fbcon_display_rotation(info, par->p);
> +}
> +

[Severity: High]
This problem wasn't introduced by this patch, but doesn't
fbcon_set_rotation() clobber the unrotated fallback when font rotation
allocation fails [1]?

When par->bitops->rotate_font() fails in fbcon_switch(), fbcon_init() or
fbcon_modechanged(), the caller falls back to unrotated mode by setting
par->rotate = FB_ROTATE_UR and calling set_blitting_type():

drivers/video/fbdev/core/fbcon.c:fbcon_switch() {
    ...
	if (par->bitops->rotate_font && par->bitops->rotate_font(info, vc)) {
		par->rotate = FB_ROTATE_UR;
		set_blitting_type(vc, info);
	}
    ...
}

set_blitting_type() then calls fbcon_set_rotation(info) followed by
fbcon_set_bitops(par), which overwrites par->rotate with
fbcon_display_rotation(info, par->p) (derived from par->p->con_rotate)
and reinstalls the rotated bitops without an allocated rotated font
buffer, leaving the console blank.

[1] https://sashiko.dev/#/bug/linux-752875af-5863-44fb-8a6c-f76bb439e2f3

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126163150.91355-1-tzimmermann@suse.de?part=2

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

* Re: [PATCH 1/2] fbcon: Don't change shared blitting state for hidden consoles
  2026-11-26 16:23 ` [PATCH 1/2] fbcon: Don't change shared blitting state for hidden consoles Thomas Zimmermann
@ 2026-11-26 16:53   ` sashiko-bot
  0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-26 16:53 UTC (permalink / raw)
  To: Thomas Zimmermann; +Cc: dri-devel

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] fbcon: use of shared par->rotate for hidden consoles in resize
  and font paths
- [High] fbcon: NULL par->bitops in fbcon_init() after set_con2fb_map()
  pre-allocation
- [High] fbcon: out-of-bounds write in fbcon_cursor() when called on a
  hidden console
- [Low] fbcon: missing Fixes trailer for console rotation bug in
  fbcon_init()
--

commit a2ce0347bbf7ab81f5e250720e0cef883fe6a77b
Author: Thomas Zimmermann <tzimmermann@suse.de>

> fbcon: Don't change shared blitting state for hidden consoles
>
> All consoles on a framebuffer share par->rotate and par->bitops.
> fbcon_init() calls set_blitting_type() for each new console, which
> resets both to the new console's rotation. If the visible console is
> rotated, it then keeps its rotated rows and columns but draws with
> unrotated bitops. The next cursor update or scroll writes beyond the
> framebuffer and oopses, e.g. at shutdown when plymouthd opens a new
> VT:
>
>   BUG: unable to handle page fault for address: ffffd2ce80bd5000
>   RIP: 0010:sys_imageblit+0x707/0x7e0
>    soft_cursor+0x1a4/0x250
>    bit_cursor+0x3ab/0x550
>    hide_cursor+0x27/0xb0
>
> Only call set_blitting_type() from fbcon_init() for the visible console
> or when the fbcon state was just created. Compute a new console's rows
> and columns from its own rotation instead of par->rotate, so that it
> doesn't inherit the visible console's geometry.
>
> Tested on QEMU with console 0 rotated by 90 degrees. Other rotations
> and rotate_all are untested.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>

[Severity: Low]
Should this bug fix include a Fixes tag?

  Fixes: e4fc27618b75 ("[PATCH] fbcon: Console Rotation - Prepare fbcon for console rotation")

> diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c
> index 21527d8496e33..7bd51b9f4fe13 100644
> --- a/drivers/video/fbdev/core/fbcon.c
> +++ b/drivers/video/fbdev/core/fbcon.c

[ ... ]

> @@ -1128,9 +1140,11 @@ static void fbcon_init(struct vc_data *vc, bool init)
>  	if (var_to_display(p, &info->var, info))
>  		return;
>  
> -	if (!info->fbcon_par)
> +	if (!info->fbcon_par) {
>  		if (con2fb_acquire_newinfo(vc, info, vc->vc_num))
>  			return;
> +		new_par = true;
> +	}

[Severity: High]
Can par->bitops remain NULL here if an unallocated console was first
mapped to a secondary framebuffer via set_con2fb_map()?

When set_con2fb_map() maps an unallocated VT (vc == NULL) to a new
framebuffer, con2fb_acquire_newinfo() allocates info->fbcon_par via
fbcon_open() without calling set_blitting_type().  When that background
VT is later allocated while another console is visible, fbcon_init() sees
info->fbcon_par != NULL (so new_par is false) and !con_is_visible(vc),
skipping set_blitting_type() and leaving par->bitops NULL.  A subsequent
hide_cursor() on that hidden console (for example via KDFONTOP) then
dereferences NULL at par->bitops->cursor in fbcon_cursor().

Checking !par->bitops instead of tracking new_par would ensure the
blitting state is initialized whenever par->bitops has not been set yet.

[ ... ]

> @@ -1188,12 +1202,15 @@ static void fbcon_init(struct vc_data *vc, bool init)
>  	if (p->con_rotate == -1)
>  		p->con_rotate = FB_ROTATE_UR;
>  
> -	set_blitting_type(vc, info);
> +	if (new_par || con_is_visible(vc))
> +		set_blitting_type(vc, info);
>  
>  	cols = vc->vc_cols;
>  	rows = vc->vc_rows;
> -	new_cols = FBCON_SWAP(par->rotate, info->var.xres, info->var.yres);
> -	new_rows = FBCON_SWAP(par->rotate, info->var.yres, info->var.xres);
> +	/* Use the console's own rotation; par->rotate belongs to the visible one. */
> +	rotate = fbcon_display_rotation(info, p);
> +	new_cols = FBCON_SWAP(rotate, info->var.xres, info->var.yres);
> +	new_rows = FBCON_SWAP(rotate, info->var.yres, info->var.xres);
>  	new_cols /= vc->vc_font.width;
>  	new_rows /= vc->vc_font.height;

[Severity: High]
What happens in the resize and font paths for a hidden console now that
par->rotate stays set to the visible console's rotation?

When fbcon_init() is called with init == false and runs
vc_resize(vc, new_cols, new_rows) (or when TIOCSWINSZ resizes a hidden
console), fbcon_resize() and updatescrollmode() still use
FBCON_SWAP(par->rotate, ...) instead of fbcon_display_rotation(info, p).
If the visible console is rotated 90 or 270 degrees relative to the
hidden console on a non-square display, fbcon_resize() checks new_cols
and new_rows against swapped axes and fails with -EINVAL.

Similarly, changing font dimensions on a hidden console in
fbcon_do_set_font() skips set_blitting_type() when !con_is_visible(vc)
but computes cols and rows from FBCON_SWAP(par->rotate, ...):

drivers/video/fbdev/core/fbcon.c:fbcon_do_set_font() {
    ...
	if (resize) {
		int cols, rows;

		cols = FBCON_SWAP(par->rotate, info->var.xres, info->var.yres);
		rows = FBCON_SWAP(par->rotate, info->var.yres, info->var.xres);
		cols /= w;
		rows /= h;
		ret = vc_resize(vc, cols, rows);
    ...
}

That resizes the hidden console to the visible console's rotated geometry
while its own p->con_rotate stays unrotated.  Switching to that console
later calls set_blitting_type() in fbcon_switch() without resizing
vc_cols/vc_rows, leaving rotated dimensions with unrotated bitops and
causing sys_imageblit() to write past info->screen_base.

[Severity: High]
Can calling hide_cursor() on a hidden console also write out of bounds in
fbcon_cursor()?

With this change, a hidden console has vc_cols and vc_rows sized for its
own rotation while par->bitops holds the visible console's rotated
bitops.  Because neither hide_cursor() nor fbcon_cursor() checks
con_is_visible(vc), operations on a background VT that call
hide_cursor(vc) (such as con_font_set() or writing cursor coordinates to
/dev/vcsaN) invoke par->bitops->cursor() with the hidden console's
vc->state.x and vc->state.y.  When the visible console is rotated 90 or
270 degrees and the hidden console's cursor position exceeds the rotated
axis limit, cw_cursor() or ccw_cursor() computes an out-of-bounds (or
wrapped negative) dy and calls soft_cursor() -> sys_imageblit(), writing
past info->screen_base.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126163150.91355-1-tzimmermann@suse.de?part=1

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

end of thread, other threads:[~2026-11-26 16:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 16:23 [PATCH 0/2] fbcon: Fix segfault on re-orientation Thomas Zimmermann
2026-11-26 16:23 ` [PATCH 1/2] fbcon: Don't change shared blitting state for hidden consoles Thomas Zimmermann
2026-11-26 16:53   ` sashiko-bot
2026-11-26 16:23 ` [PATCH 2/2] fbcon: Provide a single implementation of fbcon_set_rotation() Thomas Zimmermann
2026-11-26 16:36   ` 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.