dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yao Yiqi" <yyaqia@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v3 2/3] fbcon: Rebuild rotated font buffer on font change
Date: Fri, 16 Oct 2026 07:43:37 +0000	[thread overview]
Message-ID: <sashiko-outbox-173957@kernel.org> (raw)
In-Reply-To: <20261016073023.490430-3-yyaqia@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] fbcon: UAF in panic handler due to dangling par->rotated.buf
--

commit e32477b2f73cd204764bac2654d00076bb8bd3ba
Author: Yao Yiqi <yaoyiqi3@huawei.com>

    fbcon: Rebuild rotated font buffer on font change
    
    fbcon_rotate_font() caches a rotated copy of the console font in
    par->rotated.buf. The buffer is sized from the font's width, height
    and charcount, and is rebuilt in fbcon_init(), fbcon_switch() and
    fbcon_modechanged(), but not in fbcon_do_set_font().

> diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c
> index 01715873ea49b..d90a2ad45053c 100644
> --- a/drivers/video/fbdev/core/fbcon.c
> +++ b/drivers/video/fbdev/core/fbcon.c
> @@ -2432,6 +2432,17 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h, int charcount,
>  	else if (!vc->vc_hi_font_mask && charcount == 512)
>  		set_vc_hi_font(vc, true);
>  
> +	/*
> +	 * Select the console's blitting state and update par->rotated to
> +	 * match the new font, so that the rendering below does not use a
> +	 * cache that was built for the old font.
> +	 */
> +	if (con_is_visible(vc)) {
> +		set_blitting_type(vc, info);
> +		if (par->bitops->rotate_font)
> +			par->bitops->rotate_font(info, vc);

[Severity: High]
Does this code expose a race condition with console_flush_on_panic() that could
lead to a use-after-free?

When fbcon_rotate_font() is called, it passes par->rotated.buf to
font_data_rotate():

drivers/video/fbdev/core/fbcon_rotate.c:fbcon_rotate_font() {
    ...
	buf = font_data_rotate(par->rotated.fontdata, vc->vc_font.width,
			       vc->vc_font.height, vc->vc_font.charcount,
			       par->rotated.buf_rotate, par->rotated.buf,
			       &par->rotated.bufsize);
    ...
}

If a reallocation is needed, font_data_rotate() frees the old buffer before
returning the new one:

lib/fonts/font_rotate.c:font_data_rotate() {
    ...
		kfree(buf);
		buf = dst;
    ...
}

During this time, the global par->rotated.buf pointer remains dangling.
If a kernel panic occurs in this window, console_flush_on_panic() could
bypass the console lock and invoke fbcon write operations.

Rendering operations like ccw_putcs() check the pointer:

drivers/video/fbdev/core/fbcon_ccw.c:ccw_putcs() {
    ...
	if (!par->rotated.buf)
		return;
    ...
}

Because par->rotated.buf hasn't been set to NULL or updated to the new
buffer yet, this check would evaluate to false, leading to a read from freed
memory which could abort the panic handler and lose important debug logs.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261016073023.490430-1-yyaqia@gmail.com?part=2

  reply	other threads:[~2026-10-16  7:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-16  7:30 [PATCH v3 0/3] fbcon: fix rotated font buffer handling on font Yao Yiqi
2026-10-16  7:30 ` [PATCH v3 1/3] fbcon: Include font geometry in the rotated font cache Yao Yiqi
2026-10-16  7:30 ` [PATCH v3 2/3] fbcon: Rebuild rotated font buffer on font change Yao Yiqi
2026-10-16  7:43   ` sashiko-bot [this message]
2026-10-16  7:59   ` Thomas Zimmermann
2026-10-16  7:30 ` [PATCH v3 3/3] fbcon: Retry rotated font allocation after failure Yao Yiqi

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-173957@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=yyaqia@gmail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox