All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Thomas Zimmermann" <tzimmermann@suse.de>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 1/2] fbcon: Don't change shared blitting state for hidden consoles
Date: Thu, 26 Nov 2026 16:53:31 +0000	[thread overview]
Message-ID: <sashiko-outbox-235947@kernel.org> (raw)
In-Reply-To: <20261126163150.91355-2-tzimmermann@suse.de>

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

  reply	other threads:[~2026-11-26 16:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-235947@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.