Skip to contentSkip to conversation

fbcon: fix rotated font buffer handling on font

PATCH Superseded Yao Yiqi 4 participants 9 messages Oct 16 – Oct 19

Subsystems (4)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Yao Yiqi

author
#0 lore raw

v3 cover fbcon: fix rotated font buffer handling on font

This series fixes out-of-bounds reads of the rotated font buffer on consoles that use fbcon's software rotation (fbcon=rotate:N).

Changing the console font through KDFONTOP installs the new font geometry and then calls vc_resize(), whose redraw indexes par->rotated.buf with the new cell size while the buffer is still sized and laid out for the old font. KASAN reports, for example:

  BUG: KASAN: slab-out-of-bounds in soft_cursor
  Read of size 64 at addr ...
   memcpy
   soft_cursor
   cw_cursor
   fbcon_cursor
   hide_cursor
   redraw_screen
   vc_do_resize
   fbcon_do_set_font
   fbcon_set_font
   con_font_op
   vt_ioctl

Patch 2 adds the missing rebuild for the font-change path, and compensates in the error path of fbcon_do_set_font(): if vc_resize() fails, the font state is rolled back, and the rendering state has to be selected and the rotated cache rebuilt for the restored font as well. The rebuild itself cannot be undone, because font_data_rotate() has already reused or freed the old buffer.

The cache key in fbcon_rotate_font() compared only the fontdata pointer and the rotation. Raw font data does not store geometry, and fbcon_set_font() deduplicates uploads by byte equality, so re-uploading the same bytes with different dimensions keeps the pointer unchanged while the geometry changes; the early-out then skips the rebuild and the stale buffer is overrun during the resize redraw. Patch 1 adds the font geometry to the cache key. Patch 3 makes a failed buffer allocation retried on the next call, instead of blanking the console until a font or rotation with a different key is installed.

The unrotated-rendering fallback that fbcon_init(), fbcon_switch() and fbcon_modechanged() attempt when rotate_font() fails is ineffective:
set_blitting_type() immediately re-derives par->rotate from par->p->con_rotate and reinstalls the rotated bitops. This is a pre-existing issue that is independent of the font-change path, so it is deliberately not addressed here and will be sent separately.

Changes since v2:

- patch 2: also select the blitting type again in the error path of fbcon_do_set_font(). On tile-blitting hardware, set_blitting_type() uploads the font map to the text engine; without the second call, a failed vc_resize() left the engine with the rejected font (found by the Sashiko review)

Changes since v1 [1]:

- new patch 1 ("Include font geometry in the rotated font cache") in response to the review, which noted that the early-out relies on the fontdata pointer alone
- patch 2 (was patch 1): also rebuild in the error path of fbcon_do_set_font(), so a failed vc_resize() no longer leaves the cache describing the rejected font while the console renders with the restored one; and select the console's blitting state with set_blitting_type() before rebuilding, like the other rotate_font() callers, instead of writing par->p directly
- patch 3 (was patch 2): unchanged in essence; the retry now covers the geometry-aware key of patch 1

[1] https://lore.kernel.org/all/[email protected]/

Yao Yiqi (3):
fbcon: Include font geometry in the rotated font cache
fbcon: Rebuild rotated font buffer on font change
fbcon: Retry rotated font allocation after failure

 drivers/video/fbdev/core/fbcon.c        | 23 +++++++++++++++++++++++
 drivers/video/fbdev/core/fbcon.h        |  9 ++++++---
 drivers/video/fbdev/core/fbcon_rotate.c | 10 +++++++++-
 3 files changed, 38 insertions(+), 4 deletions(-)
Signature · 1 line
2.56.0
author
#1 lore raw

PATCH v3 1/3 fbcon: Include font geometry in the rotated font cache

From: Yao Yiqi <[email protected]>

fbcon_rotate_font() caches a rotated copy of the console font in par->rotated.buf and skips the rebuild when the cache appears to be up to date. The cache is keyed on the source font's data pointer and the rotation alone, on the assumption that an unchanged fontdata pointer implies an unchanged font.

That assumption does not hold. Raw font data (font_data_t) stores no glyph geometry; width, height and charcount are tracked separately in vc->vc_font. When a font is uploaded, fbcon_set_font() deduplicates it against the fonts of all consoles with font_data_is_equal(), which compares only the byte count, the checksum and the raw bytes. Two uploads of the same data that declare different dimensions therefore end up sharing one font_data_t, and a console can install a new geometry while its fontdata pointer stays the same.

The early-out in fbcon_rotate_font() then skips the rebuild, and the rotated blitting routines index the stale buffer with cell sizes computed from the new geometry:

	src = par->rotated.buf + (scr_readw(s) & charmask) * cellsize;

Rotation swaps a glyph's width and height, so the size of the rotated cell depends on pitch rounding and differs between geometries. A 4x16 font whose 4096 bytes are re-uploaded as 16x8 on a CW-rotated console, for example, grows the rotated cell size from 8 to 16 bytes, and the largest character then reads past the end of the 2048-byte buffer that was built for the 4x16 geometry.

The key has never included the geometry. Its exposure was limited, but not eliminated, while the deduplication in fbcon_set_font() also compared the consoles' font widths and total byte counts: with the charcount restricted to 256 or 512, differing uploads could then only trade height against charcount (such as 4x18x256 against 4x9x512), and even those can change the rotated cell size. Commit 1e3c49aa03fb ("lib/fonts: Compare font data for equality with font_data_is_equal()") dropped the width comparison, so identical bytes now share font data across arbitrary dimensions.

Record the geometry that the buffer was built from and compare it in the early-out, so a geometry change always triggers a rebuild.

Fixes 6cc50e1c5b57 ("[PATCH] fbcon: Console Rotation - Add support to rotate font bitmap")
---
 drivers/video/fbdev/core/fbcon.h        | 9 ++++++---
 drivers/video/fbdev/core/fbcon_rotate.c | 9 ++++++++-
 2 files changed, 14 insertions(+), 4 deletions(-)
drivers/video/fbdev/core/fbcon.h +6 -3
index 407d207b14f1..bfbd70f8b1cd 100644
@@ -89,10 +89,13 @@ struct fbcon_par {
 	char  *cursor_data;
 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
 	struct {
-		font_data_t *fontdata;  /* source font */
-		u8 *buf;                /* rotated glyphs */
+		font_data_t *fontdata;       /* source font */
+		u8 *buf;                     /* rotated glyphs */
 		size_t bufsize;
-		int buf_rotate;         /* rotation of buf */
+		int buf_rotate;              /* rotation of buf */
+		unsigned int buf_width;      /* geometry of source font */
+		unsigned int buf_height;
+		unsigned int buf_charcount;
 	} rotated;
 #endif
 	u8    *cursor_src;
drivers/video/fbdev/core/fbcon_rotate.c +8 -1
index 6cdbc96eeca6..660a3fa81bae 100644
@@ -21,11 +21,18 @@ int fbcon_rotate_font(struct fb_info *info, struct vc_data *vc)
 	unsigned char *buf;
 	int ret;
 
-	if (par->p->fontdata == par->rotated.fontdata && par->rotate == par->rotated.buf_rotate)
+	if (par->p->fontdata == par->rotated.fontdata &&
+	    par->rotate == par->rotated.buf_rotate &&
+	    vc->vc_font.width == par->rotated.buf_width &&
+	    vc->vc_font.height == par->rotated.buf_height &&
+	    vc->vc_font.charcount == par->rotated.buf_charcount)
 		return 0;
 
 	par->rotated.fontdata = par->p->fontdata;
 	par->rotated.buf_rotate = par->rotate;
+	par->rotated.buf_width = vc->vc_font.width;
+	par->rotated.buf_height = vc->vc_font.height;
+	par->rotated.buf_charcount = vc->vc_font.charcount;
 
 	if (info->fbops->fb_sync)
 		info->fbops->fb_sync(info);
Signature · 1 line
2.56.0
maintainer
#2 lore raw

Re: [PATCH v3 1/3] fbcon: Include font geometry in the rotated font cache

Quoted 43 lines · Yao Yiqi

From: Yao Yiqi <[email protected]>

fbcon_rotate_font() caches a rotated copy of the console font in par->rotated.buf and skips the rebuild when the cache appears to be up to date. The cache is keyed on the source font's data pointer and the rotation alone, on the assumption that an unchanged fontdata pointer implies an unchanged font.

That assumption does not hold. Raw font data (font_data_t) stores no glyph geometry; width, height and charcount are tracked separately in vc->vc_font. When a font is uploaded, fbcon_set_font() deduplicates it against the fonts of all consoles with font_data_is_equal(), which compares only the byte count, the checksum and the raw bytes. Two uploads of the same data that declare different dimensions therefore end up sharing one font_data_t, and a console can install a new geometry while its fontdata pointer stays the same.

The early-out in fbcon_rotate_font() then skips the rebuild, and the rotated blitting routines index the stale buffer with cell sizes computed from the new geometry:

	src = par->rotated.buf + (scr_readw(s) & charmask) * cellsize;

Rotation swaps a glyph's width and height, so the size of the rotated cell depends on pitch rounding and differs between geometries. A 4x16 font whose 4096 bytes are re-uploaded as 16x8 on a CW-rotated console, for example, grows the rotated cell size from 8 to 16 bytes, and the largest character then reads past the end of the 2048-byte buffer that was built for the 4x16 geometry.

The key has never included the geometry. Its exposure was limited, but not eliminated, while the deduplication in fbcon_set_font() also compared the consoles' font widths and total byte counts: with the charcount restricted to 256 or 512, differing uploads could then only trade height against charcount (such as 4x18x256 against 4x9x512), and even those can change the rotated cell size. Commit 1e3c49aa03fb ("lib/fonts: Compare font data for equality with font_data_is_equal()") dropped the width comparison, so identical bytes now share font data across arbitrary dimensions.

Record the geometry that the buffer was built from and compare it in the early-out, so a geometry change always triggers a rebuild.

Quoted 7 lines
Fixes 6cc50e1c5b57 ("[PATCH] fbcon: Console Rotation - Add support to rotate font bitmap")
---
  drivers/video/fbdev/core/fbcon.h        | 9 ++++++---
  drivers/video/fbdev/core/fbcon_rotate.c | 9 ++++++++-
  2 files changed, 14 insertions(+), 4 deletions(-)

I've replaced the v1 version of this series with this v3 version in fbdev/for-next git tree for further testing.

Thanks!
Helge

#3 lore raw

Re: [PATCH v3 1/3] fbcon: Include font geometry in the rotated font cache

Quoted 2 lines · Helge Deller

I've replaced the v1 version of this series with this v3 version in fbdev/for-next git tree for further testing.

Sorry, the patch was not good enough, Zimmermann reviewed the code and I did some modification after that. So we might need to switch to v4 version, sadly. Anyway, appreciate your continuous work for testing.

Thanks,
Yao Yiqi

author
#4 lore raw

PATCH v3 2/3 fbcon: Rebuild rotated font buffer on font change

In reply to Yao Yiqi

From: Yao Yiqi <[email protected]>

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().

When the console font is changed through KDFONTOP/KD_FONT_OP_SET, the new font data and geometry are installed and vc_resize() is called. The redraw that follows reaches the rotated bitops while the buffer still holds the old font: the rotated putcs/cursor ops index par->rotated.buf with the new cell size and character codes, so a stale, too-small buffer is read out of bounds.

KASAN reports, for example:

  BUG: KASAN: slab-out-of-bounds in soft_cursor
  Read of size 64 at addr ...
   memcpy
   soft_cursor
   cw_cursor
   fbcon_cursor
   hide_cursor
   redraw_screen
   vc_do_resize
   fbcon_do_set_font
   fbcon_set_font
   con_font_op
   vt_ioctl

Rebuild the buffer for the visible console right after the new font geometry has been installed and before any redraw. Select the console's blitting state with set_blitting_type() first, as fbcon_init(), fbcon_switch() and fbcon_modechanged() do before their rotate_font() calls: fbcon_rotate_font() reads the source font through par->p, which may otherwise still refer to another console of this framebuffer. On tile-blitting hardware, the same call uploads the new font's map to the text engine, which previously happened only when the console was switched. Background consoles keep their rebuild at fbcon_switch() time, as the buffer is shared per framebuffer and must not be rebuilt for a console that is not being displayed.

If vc_resize() fails, err_out restores the previous font. The rotated buffer that was rebuilt for the new font earlier in the function cannot be restored with it: font_data_rotate() has already reused or freed the buffer that belonged to the old font. Select the blitting type and rebuild the buffer again after the restore: the upload to tile-blitting hardware and the rotated cache would otherwise keep describing the rejected font, and par->rotated.fontdata would keep referencing the font data whose last reference the error path drops. A failing rebuild leaves par->rotated.buf NULL, so the rotated ops skip drawing instead of reading a mismatched buffer; the next patch retries the allocation on the following call.

Unlike the other callers, this one does not fall back to unrotated rendering on failure. The "par->rotate = FB_ROTATE_UR; set_blitting_type(vc, info);" fallback they use does not actually switch to unrotated rendering: set_blitting_type() calls fbcon_set_rotation(), which immediately re-derives par->rotate from par->p->con_rotate. Replicating that pattern here would not change the outcome; repairing the fallback is left to separate work.

Fixes 6cc50e1c5b57 ("[PATCH] fbcon: Console Rotation - Add support to rotate font bitmap")

---
Changes in v3:

- Also select the blitting type again in the error path of fbcon_do_set_font(). On tile-blitting hardware, set_blitting_type() uploads the font map to the text engine; without the second call, a failed vc_resize() left the engine with the rejected font (found by the Sashiko review).

Changes in v2:

- Rebuild the buffer again in the error path of fbcon_do_set_font(). Without this, a failed vc_resize() left the rotated cache describing the rejected font while the console rendered with the restored one, and par->rotated.fontdata referenced freed font data (found by the Sashiko review).
- Select the console's blitting state with set_blitting_type() before rebuilding, like the other rotate_font() callers, instead of writing par->p directly.
- Reworded the note about the unrotated-rendering fallback, which is now left to separate work.

---
 drivers/video/fbdev/core/fbcon.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
drivers/video/fbdev/core/fbcon.c +23 -0
index 01715873ea49..d90a2ad45053 100644
@@ -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);
+	}
+
 	if (resize) {
 		int cols, rows;
 
@@ -2466,6 +2477,18 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h, int charcount,
 	else if (!old_hi_font_mask && vc->vc_hi_font_mask)
 		set_vc_hi_font(vc, false);
 
+	/*
+	 * Restore the rendering state for the old font: re-select the
+	 * blitting type, which re-uploads the font map on tile-blitting
+	 * hardware, and overwrite par->rotated with the restored font's
+	 * state.
+	 */
+	if (con_is_visible(vc)) {
+		set_blitting_type(vc, info);
+		if (par->bitops->rotate_font)
+			par->bitops->rotate_font(info, vc);
+	}
+
 	font_data_put(data);
 
 	return ret;
Signature · 1 line
2.56.0
#5 lore raw

Re: [PATCH v3 2/3] fbcon: Rebuild rotated font buffer on font change

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 --

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 <[email protected]>

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().

Quoted 7 lines
drivers/video/fbdev/core/fbcon.c +0 -0
index 01715873ea49b..d90a2ad45053c 100644
@@ -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);

drivers/video/fbdev/core/fbcon.c static int fbcon_do_set_font(struct vc_data *vc, int w, int h, int charcount, · line 2443

Quoted 10 lines
drivers/video/fbdev/core/fbcon.c +9 -0
 
+	/*
+	 * 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.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#6 lore raw

Re: [PATCH v3 2/3] fbcon: Rebuild rotated font buffer on font change

In reply to Yao Yiqi

Hi

Am 16.10.26 um 09:30 schrieb Yao Yiqi:

Quoted 54 lines

From: Yao Yiqi <[email protected]>

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().

When the console font is changed through KDFONTOP/KD_FONT_OP_SET, the new font data and geometry are installed and vc_resize() is called. The redraw that follows reaches the rotated bitops while the buffer still holds the old font: the rotated putcs/cursor ops index par->rotated.buf with the new cell size and character codes, so a stale, too-small buffer is read out of bounds.

KASAN reports, for example:

   BUG: KASAN: slab-out-of-bounds in soft_cursor
   Read of size 64 at addr ...
    memcpy
    soft_cursor
    cw_cursor
    fbcon_cursor
    hide_cursor
    redraw_screen
    vc_do_resize
    fbcon_do_set_font
    fbcon_set_font
    con_font_op
    vt_ioctl

Rebuild the buffer for the visible console right after the new font geometry has been installed and before any redraw. Select the console's blitting state with set_blitting_type() first, as fbcon_init(), fbcon_switch() and fbcon_modechanged() do before their rotate_font() calls: fbcon_rotate_font() reads the source font through par->p, which may otherwise still refer to another console of this framebuffer. On tile-blitting hardware, the same call uploads the new font's map to the text engine, which previously happened only when the console was switched. Background consoles keep their rebuild at fbcon_switch() time, as the buffer is shared per framebuffer and must not be rebuilt for a console that is not being displayed.

If vc_resize() fails, err_out restores the previous font. The rotated buffer that was rebuilt for the new font earlier in the function cannot be restored with it: font_data_rotate() has already reused or freed the buffer that belonged to the old font. Select the blitting type and rebuild the buffer again after the restore: the upload to tile-blitting hardware and the rotated cache would otherwise keep describing the rejected font, and par->rotated.fontdata would keep referencing the font data whose last reference the error path drops. A failing rebuild leaves par->rotated.buf NULL, so the rotated ops skip drawing instead of reading a mismatched buffer; the next patch retries the allocation on the following call.

Quoted 7 lines

Unlike the other callers, this one does not fall back to unrotated rendering on failure. The "par->rotate = FB_ROTATE_UR; set_blitting_type(vc, info);" fallback they use does not actually switch to unrotated rendering: set_blitting_type() calls fbcon_set_rotation(), which immediately re-derives par->rotate from par->p->con_rotate. Replicating that pattern here would not change the outcome; repairing the fallback is left to separate work.

It's way too long and boring to read. Can you please try to shorten the AI-generated commit description?

Quoted 4 lines
Fixes 6cc50e1c5b57 ("[PATCH] fbcon: Console Rotation - Add support to rotate font bitmap")
Quoted 8 lines

---
Changes in v3:

- Also select the blitting type again in the error path of fbcon_do_set_font(). On tile-blitting hardware, set_blitting_type() uploads the font map to the text engine; without the second call, a failed vc_resize() left the engine with the rejected font (found by the Sashiko review).

The problem is that rotate_font can fail as well. Handling that in the error path is not possible; hence results might be worse than keeping the rejected font.  Can you try to keep the original rotated font and reinstall that directly?

Best regards
Thomas

Quoted 58 lines

Changes in v2:

- Rebuild the buffer again in the error path of fbcon_do_set_font(). Without this, a failed vc_resize() left the rotated cache describing the rejected font while the console rendered with the restored one, and par->rotated.fontdata referenced freed font data (found by the Sashiko review).
- Select the console's blitting state with set_blitting_type() before rebuilding, like the other rotate_font() callers, instead of writing par->p directly.
- Reworded the note about the unrotated-rendering fallback, which is now left to separate work.

---
  drivers/video/fbdev/core/fbcon.c | 23 +++++++++++++++++++++++
  1 file changed, 23 insertions(+)
drivers/video/fbdev/core/fbcon.c +23 -0
index 01715873ea49..d90a2ad45053 100644
@@ -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);
+	}
+
  	if (resize) {
  		int cols, rows;
 
@@ -2466,6 +2477,18 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h, int charcount,
  	else if (!old_hi_font_mask && vc->vc_hi_font_mask)
  		set_vc_hi_font(vc, false);
 
+	/*
+	 * Restore the rendering state for the old font: re-select the
+	 * blitting type, which re-uploads the font map on tile-blitting
+	 * hardware, and overwrite par->rotated with the restored font's
+	 * state.
+	 */
+	if (con_is_visible(vc)) {
+		set_blitting_type(vc, info);
+		if (par->bitops->rotate_font)
+			par->bitops->rotate_font(info, vc);
+	}
+
  	font_data_put(data);
 
  	return ret;
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Stefan Gaiser, Jochen Jaser, Abhinav Puri, (HRB 36809, AG Nürnberg)
#7 lore raw

Re: [PATCH v3 2/3] fbcon: Rebuild rotated font buffer on font change

Quoted 5 lines · Thomas Zimmermann

It's way too long and boring to read. Can you please try to shorten the AI-generated commit description?

Sorry for that, I was a bit lazy to think commit desc by myself. I am new to kernel and a little afraid that my message does not cover all things.

Quoted 11 lines
Quoted 5 lines

- Also select the blitting type again in the error path of fbcon_do_set_font(). On tile-blitting hardware, set_blitting_type() uploads the font map to the text engine; without the second call, a failed vc_resize() left the engine with the rejected font (found by the Sashiko review).

The problem is that rotate_font can fail as well. Handling that in the error path is not possible; hence results might be worse than keeping the rejected font.  Can you try to keep the original rotated font and reinstall that directly?

Good advice, I will fix this in V4.

Thanks for your review,
Yao Yiqi

author
#8 lore raw

PATCH v3 3/3 fbcon: Retry rotated font allocation after failure

In reply to Yao Yiqi

From: Yao Yiqi <[email protected]>

fbcon_rotate_font() records the font, its geometry and the rotation it is about to handle in par->rotated before calling font_data_rotate(). If the allocation fails, the error path clears par->rotated.buf, but the recorded font, geometry and rotation already look up to date, so the next call takes the early-out and never retries. The rotated putcs/cursor ops keep returning early on the NULL buffer and the console stays blank until a font or rotation with a different key is installed, even once memory is available again.

Also test par->rotated.buf in the early-out, so a failed allocation is retried the next time fbcon_rotate_font() runs: at the next fbcon_switch(), fbcon_modechanged() or font change.

Fixes e4ef723d8975 ("fbcon: Avoid OOB font access if console rotation fails")

---
Changes in v2:

- The early-out now also compares the font geometry (previous patch in this series); the retry covers the combined key.

---
 drivers/video/fbdev/core/fbcon_rotate.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/video/fbdev/core/fbcon_rotate.c +2 -1
index 660a3fa81bae..7afd63dcee7b 100644
@@ -25,7 +25,8 @@ int fbcon_rotate_font(struct fb_info *info, struct vc_data *vc)
 	    par->rotate == par->rotated.buf_rotate &&
 	    vc->vc_font.width == par->rotated.buf_width &&
 	    vc->vc_font.height == par->rotated.buf_height &&
-	    vc->vc_font.charcount == par->rotated.buf_charcount)
+	    vc->vc_font.charcount == par->rotated.buf_charcount &&
+	    par->rotated.buf)
 		return 0;
 
 	par->rotated.fontdata = par->p->fontdata;
Signature · 1 line
2.56.0