Skip to contentSkip to conversation

fbcon: Don't drop last logo line if logo is same size as screen

PATCH New Helge Deller 2 participants 2 messages Nov 25

Subsystems (4)
lore
Share & tools
lore

Helge Deller

author maintainer
#0 lore raw

PATCH v4 1/1 fbcon: Don't drop last logo line if logo is same size as screen

Henri reported a regression that when a custom bootlogo is exactly as big as the screen, a white bar with the size of the font height is displayed at the bottom of the display.

This patch fixes this off-by-one bug, but now -as sashiko-bot noticed- since the logo covers the whole screen there is no area left in which the text can be scrolled. To avoid accesses outside the screen memory simply keep the text area covering the full screen (and possibly overwriting) the full-screen logo.

Fixes 94e6a058b168 ("fbcon: Fix KASAN slab-out-of-bounds Read in fbcon_prepare_logo")
---
 drivers/video/fbdev/core/fbcon.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
drivers/video/fbdev/core/fbcon.c +13 -4
index c632a3c82e16..4f51f6262eac 100644
@@ -665,13 +665,15 @@ static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
 		erase &= ~0x400;
 	logo_height = fb_prepare_logo(info, par->rotate);
 	logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
-	logo_lines = min(logo_lines, rows);
-	logo_lines = min(logo_lines, new_rows - 1);
+	logo_lines = min(logo_lines, new_rows);
 	if (logo_lines <= 0) {
 		logo_lines = 0;
 		logo_shown = FBCON_LOGO_DONTSHOW;
 		return;
 	}
+	if (logo_lines >= vc->vc_bottom)
+		goto logo_fullscreen;
+
 	q = (unsigned short *) (vc->vc_origin +
 				vc->vc_size_row * rows);
 	step = logo_lines * cols;
@@ -729,12 +731,17 @@ static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
 	if (logo_shown == FBCON_LOGO_DONTSHOW)
 		return;
 
+logo_fullscreen:
 	if (logo_lines > vc->vc_bottom) {
 		logo_shown = FBCON_LOGO_CANSHOW;
 		pr_info("fbcon: disable boot-logo (boot-logo bigger than screen).\n");
 	} else {
 		logo_shown = FBCON_LOGO_DRAW;
-		vc->vc_top = logo_lines;
+		/* keep vc_top if logo covers whole screen */
+		if (logo_lines < vc->vc_bottom)
+			vc->vc_top = logo_lines;
+		else
+			vc->vc_top = 0;
 	}
 }
 #endif /* MODULE */
@@ -2270,7 +2277,9 @@ static bool fbcon_switch(struct vc_data *vc)
 
 		logo_shown = fg_console;
 		fb_show_logo(info, par->rotate);
-		update_region(vc,
+		/* avoid screen update on full screen sized logo */
+		if (vc->vc_top)
+			update_region(vc,
 			      vc->vc_origin + vc->vc_size_row * vc->vc_top,
 			      vc->vc_size_row * (vc->vc_bottom -
 						 vc->vc_top) / 2);
Signature · 1 line
2.56.1
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] fbcon: slab-out-of-bounds read in fbcon_prepare_logo() when rows < logo_lines --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] fbcon: slab-out-of-bounds read in fbcon_prepare_logo() when rows < logo_lines
--

commit c7b7e4b07b9a1354bf2bc5159428ad41f71350a8
Author: Helge Deller <[email protected]>

fbcon: Don't drop last logo line if logo is same size as screen

This commit allows full-screen boot logos to use all screen rows while keeping vc_top at 0 so console text can still scroll across the full screen.

Quoted 12 lines
drivers/video/fbdev/core/fbcon.c +1 -2
index d7890e119dc7d..289e6ce37f96d 100644
@@ -665,13 +665,15 @@ static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
 		erase &= ~0x400;
 	logo_height = fb_prepare_logo(info, par->rotate);
 	logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
-	logo_lines = min(logo_lines, rows);
-	logo_lines = min(logo_lines, new_rows - 1);
+	logo_lines = min(logo_lines, new_rows);
 	if (logo_lines <= 0) {

drivers/video/fbdev/core/fbcon.c static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info, · line 679

Quoted 10 lines
drivers/video/fbdev/core/fbcon.c +3 -0
 		logo_lines = 0;
 		logo_shown = FBCON_LOGO_DONTSHOW;
 		return;
 	}
+	if (logo_lines >= vc->vc_bottom)
+		goto logo_fullscreen;
+
 	q = (unsigned short *) (vc->vc_origin +
 				vc->vc_size_row * rows);
 	step = logo_lines * cols;

[Severity: High]
Does dropping logo_lines = min(logo_lines, rows) reintroduce the out-of-bounds read before vc->vc_origin that 94e6a058b168 ("fbcon: Fix KASAN slab-out-of-bounds Read in fbcon_prepare_logo") fixed?

In fbcon_init(), rows holds the pre-resize row count while vc_resize() has already updated vc->vc_bottom to new_rows. When the console grows (for example during vgacon-to-fbcon takeover) and rows < logo_lines < new_rows, the logo_lines >= vc->vc_bottom check is not taken, so
r = q - logo_lines * cols underflows before vc->vc_origin (the start of vc->vc_screenbuf):

drivers/video/fbdev/core/fbcon.c:fbcon_prepare_logo() {
	...
	q = (unsigned short *) (vc->vc_origin +
				vc->vc_size_row * rows);
	step = logo_lines * cols;
	for (r = q - logo_lines * cols; r < q; r++)
		if (scr_readw(r) != vc->vc_video_erase_char)
			break;
	if (r != q && new_rows >= rows + logo_lines) {
		...
			r = q - step;
			for (cnt = 0; cnt < logo_lines; cnt++, r += i)
				scr_memcpyw(save + cnt * new_cols, r, 2 * i);
	...
}

scr_readw(r) then reads slab memory before vc->vc_screenbuf, and if new_rows >= rows + logo_lines, scr_memcpyw() copies that out-of-bounds heap data into save and then into the visible screen buffer.

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