Skip to content

Commit b36b3c5

Browse files
Yunhai ZhangSomasundaram Krishnasamy
authored andcommitted
vgacon: Fix for missing check in scrollback handling
vgacon_scrollback_update() always leaves enbough room in the scrollback buffer for the next call, but if the console size changed that room might not actually be enough, and so we need to re-check. The check should be in the loop since vgacon_scrollback_cur->tail is updated in the loop and count may be more than 1 when triggered by CSI M, as Jiri's PoC: int main(int argc, char** argv) { int fd = open("/dev/tty1", O_RDWR); unsigned short size[3] = {25, 200, 0}; ioctl(fd, 0x5609, size); // VT_RESIZE write(fd, "\e[1;1H", 6); for (int i = 0; i < 30; i++) write(fd, "\e[10M", 5); } It leads to various crashes as vgacon_scrollback_update writes out of the buffer: BUG: unable to handle page fault for address: ffffc900001752a0 #PF: supervisor write access in kernel mode #PF: error_code(0x0002) - not-present page RIP: 0010:mutex_unlock+0x13/0x30 ... Call Trace: n_tty_write+0x1a0/0x4d0 tty_write+0x1a0/0x2e0 Or to KASAN reports: BUG: KASAN: slab-out-of-bounds in vgacon_scroll+0x57a/0x8ed This fixes CVE-2020-14331. Reported-by: 张云海 <[email protected]> Reported-by: Yang Yingliang <[email protected]> Reported-by: Kyungtae Kim <[email protected]> Fixes: 15bdab9 ([PATCH] vgacon: Add support for soft scrollback) Cc: [email protected] Cc: [email protected] Cc: Linus Torvalds <[email protected]> Cc: Solar Designer <[email protected]> Cc: "Srivatsa S. Bhat" <[email protected]> Cc: Anthony Liguori <[email protected]> Cc: Yang Yingliang <[email protected]> Cc: Bartlomiej Zolnierkiewicz <[email protected]> Cc: Jiri Slaby <[email protected]> Signed-off-by: Yunhai Zhang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit ebfdfee) Orabug: 31705119 CVE: CVE-2020-14331 Signed-off-by: Saeed Mirzamohammadi <[email protected]> Reviewed-by: Jack Vogel <[email protected]> Signed-off-by: Somasundaram Krishnasamy <[email protected]>
1 parent fce1243 commit b36b3c5

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/video/console/vgacon.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,10 @@ static void vgacon_scrollback_update(struct vc_data *c, int t, int count)
246246
p = (void *) (c->vc_origin + t * c->vc_size_row);
247247

248248
while (count--) {
249+
if ((vgacon_scrollback_cur->tail + c->vc_size_row) >
250+
vgacon_scrollback_cur->size)
251+
vgacon_scrollback_cur->tail = 0;
252+
249253
scr_memcpyw(vgacon_scrollback_cur->data +
250254
vgacon_scrollback_cur->tail,
251255
p, c->vc_size_row);

0 commit comments

Comments
 (0)