[PATCH] vt: hide cursor prior to font changes to avoid out-of-bound reads
From: Helge Deller
Date: Fri Aug 21 2026 - 04:01:22 EST
When changing the size of a sceen font, the amount of columns and rows
on a screen may change and thus the current position of the cursor and
the selection may suddenly lay outside of the current screen limits.
This may lead to slab-out-of-bounds errors as reported by KASAN.
Reported-by: Jaeyoung Chung <jjy600901@xxxxxxxxx>
Signed-off-by: Helge Deller <deller@xxxxxx>
Link: https://lore.kernel.org/all/20260819163440.3702924-1-jjy600901@xxxxxxxxx/
diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 8f467b22b799..30c6ea48c338 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -4986,8 +4986,8 @@ static int con_font_set(struct vc_data *vc, const struct console_font_op *op)
if (!vc->vc_sw->con_font_set)
return -ENOSYS;
- if (vc_is_sel(vc))
- clear_selection();
+ /* hide selection and cursor - due to font size change they might be outside of screen afterwards */
+ hide_cursor(vc);
return vc->vc_sw->con_font_set(vc, &font, vpitch, op->flags);
}
@@ -5011,8 +5011,9 @@ static int con_font_default(struct vc_data *vc, struct console_font_op *op)
if (!vc->vc_sw->con_font_default)
return -ENOSYS;
- if (vc_is_sel(vc))
- clear_selection();
+ /* hide selection and cursor - due to font size change they might be outside of screen afterwards */
+ hide_cursor(vc);
+
int ret = vc->vc_sw->con_font_default(vc, &font, s);
if (ret)
return ret;