Skip to content

Commit 4001449

Browse files
Deftera186gregkh
authored andcommitted
vt: discard stale unicode buffer on alt screen exit after resize
When enter_alt_screen() saves vc_uni_lines into vc_saved_uni_lines and sets vc_uni_lines to NULL, a subsequent console resize via vc_do_resize() skips reallocating the unicode buffer because vc_uni_lines is NULL. However, vc_saved_uni_lines still points to the old buffer allocated for the original dimensions. When leave_alt_screen() later restores vc_saved_uni_lines, the buffer dimensions no longer match vc_rows/vc_cols. Any operation that iterates over the unicode buffer using the current dimensions (e.g. csi_J clearing the screen) will access memory out of bounds, causing a kernel oops: BUG: unable to handle page fault for address: 0x0000002000000020 RIP: 0010:csi_J+0x133/0x2d0 The faulting address 0x0000002000000020 is two adjacent u32 space characters (0x20) interpreted as a pointer, read from the row data area past the end of the 25-entry pointer array in a buffer allocated for 80x25 but accessed with 240x67 dimensions. Fix this by checking whether the console dimensions changed while in the alternate screen. If they did, free the stale saved buffer instead of restoring it. The unicode screen will be lazily rebuilt via vc_uniscr_check() when next needed. Fixes: 5eb6083 ("vt: save/restore unicode screen buffer for alternate screen") Cc: stable <stable@kernel.org> Tested-by: Liav Mordouch <liavmordouch@gmail.com> Signed-off-by: Liav Mordouch <liavmordouch@gmail.com> Reviewed-by: Nicolas Pitre <nico@fluxnic.net> Link: https://patch.msgid.link/20260327170204.29706-1-liavmordouch@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c369299 commit 4001449

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

drivers/tty/vt/vt.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1901,6 +1901,7 @@ static void leave_alt_screen(struct vc_data *vc)
19011901
unsigned int rows = min(vc->vc_saved_rows, vc->vc_rows);
19021902
unsigned int cols = min(vc->vc_saved_cols, vc->vc_cols);
19031903
u16 *src, *dest;
1904+
bool uni_lines_stale;
19041905

19051906
if (vc->vc_saved_screen == NULL)
19061907
return; /* Not inside an alt-screen */
@@ -1909,7 +1910,18 @@ static void leave_alt_screen(struct vc_data *vc)
19091910
dest = ((u16 *)vc->vc_origin) + r * vc->vc_cols;
19101911
memcpy(dest, src, 2 * cols);
19111912
}
1912-
vc_uniscr_set(vc, vc->vc_saved_uni_lines);
1913+
/*
1914+
* If the console was resized while in the alternate screen,
1915+
* vc_saved_uni_lines was allocated for the old dimensions.
1916+
* Restoring it would cause out-of-bounds accesses. Discard it
1917+
* and let the unicode screen be lazily rebuilt.
1918+
*/
1919+
uni_lines_stale = vc->vc_saved_rows != vc->vc_rows ||
1920+
vc->vc_saved_cols != vc->vc_cols;
1921+
if (uni_lines_stale)
1922+
vc_uniscr_free(vc->vc_saved_uni_lines);
1923+
else
1924+
vc_uniscr_set(vc, vc->vc_saved_uni_lines);
19131925
vc->vc_saved_uni_lines = NULL;
19141926
restore_cur(vc);
19151927
/* Update the entire screen */

0 commit comments

Comments
 (0)