Revision 513dc792d6060d5ef572e43852683097a8420f56 authored by Zhang Xiaoxu on 04 March 2020, 02:24:29 UTC, committed by Daniel Vetter on 06 March 2020, 20:06:34 UTC
When syzkaller tests, there is a UAF:
  BUG: KASan: use after free in vgacon_invert_region+0x9d/0x110 at addr
    ffff880000100000
  Read of size 2 by task syz-executor.1/16489
  page:ffffea0000004000 count:0 mapcount:-127 mapping:          (null)
  index:0x0
  page flags: 0xfffff00000000()
  page dumped because: kasan: bad access detected
  CPU: 1 PID: 16489 Comm: syz-executor.1 Not tainted
  Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS
  rel-1.9.3-0-ge2fc41e-prebuilt.qemu-project.org 04/01/2014
  Call Trace:
    [<ffffffffb119f309>] dump_stack+0x1e/0x20
    [<ffffffffb04af957>] kasan_report+0x577/0x950
    [<ffffffffb04ae652>] __asan_load2+0x62/0x80
    [<ffffffffb090f26d>] vgacon_invert_region+0x9d/0x110
    [<ffffffffb0a39d95>] invert_screen+0xe5/0x470
    [<ffffffffb0a21dcb>] set_selection+0x44b/0x12f0
    [<ffffffffb0a3bfae>] tioclinux+0xee/0x490
    [<ffffffffb0a1d114>] vt_ioctl+0xff4/0x2670
    [<ffffffffb0a0089a>] tty_ioctl+0x46a/0x1a10
    [<ffffffffb052db3d>] do_vfs_ioctl+0x5bd/0xc40
    [<ffffffffb052e2f2>] SyS_ioctl+0x132/0x170
    [<ffffffffb11c9b1b>] system_call_fastpath+0x22/0x27
    Memory state around the buggy address:
     ffff8800000fff00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00
     00 00
     ffff8800000fff80: 00 00 00 00 00 00 00 00 00 00 00 00 00
     00 00 00
    >ffff880000100000: ff ff ff ff ff ff ff ff ff ff ff ff ff
     ff ff ff

It can be reproduce in the linux mainline by the program:
  #include <stdio.h>
  #include <stdlib.h>
  #include <unistd.h>
  #include <fcntl.h>
  #include <sys/types.h>
  #include <sys/stat.h>
  #include <sys/ioctl.h>
  #include <linux/vt.h>

  struct tiocl_selection {
    unsigned short xs;      /* X start */
    unsigned short ys;      /* Y start */
    unsigned short xe;      /* X end */
    unsigned short ye;      /* Y end */
    unsigned short sel_mode; /* selection mode */
  };

  #define TIOCL_SETSEL    2
  struct tiocl {
    unsigned char type;
    unsigned char pad;
    struct tiocl_selection sel;
  };

  int main()
  {
    int fd = 0;
    const char *dev = "/dev/char/4:1";

    struct vt_consize v = {0};
    struct tiocl tioc = {0};

    fd = open(dev, O_RDWR, 0);

    v.v_rows = 3346;
    ioctl(fd, VT_RESIZEX, &v);

    tioc.type = TIOCL_SETSEL;
    ioctl(fd, TIOCLINUX, &tioc);

    return 0;
  }

When resize the screen, update the 'vc->vc_size_row' to the new_row_size,
but when 'set_origin' in 'vgacon_set_origin', vgacon use 'vga_vram_base'
for 'vc_origin' and 'vc_visible_origin', not 'vc_screenbuf'. It maybe
smaller than 'vc_screenbuf'. When TIOCLINUX, use the new_row_size to calc
the offset, it maybe larger than the vga_vram_size in vgacon driver, then
bad access.
Also, if set an larger screenbuf firstly, then set an more larger
screenbuf, when copy old_origin to new_origin, a bad access may happen.

So, If the screen size larger than vga_vram, resize screen should be
failed. This alse fix CVE-2020-8649 and CVE-2020-8647.

Linus pointed out that overflow checking seems absent. We're saved by
the existing bounds checks in vc_do_resize() with rather strict
limits:

	if (cols > VC_RESIZE_MAXCOL || lines > VC_RESIZE_MAXROW)
		return -EINVAL;

Fixes: 0aec4867dca14 ("[PATCH] SVGATextMode fix")
Reference: CVE-2020-8647 and CVE-2020-8649
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>
[danvet: augment commit message to point out overflow safety]
Cc: stable@vger.kernel.org
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20200304022429.37738-1-zhangxiaoxu5@huawei.com
1 parent 2ac4853
History
File Mode Size
partitions
Kconfig -rw-r--r-- 6.3 KB
Kconfig.iosched -rw-r--r-- 1.4 KB
Makefile -rw-r--r-- 1.6 KB
badblocks.c -rw-r--r-- 14.1 KB
bfq-cgroup.c -rw-r--r-- 37.7 KB
bfq-iosched.c -rw-r--r-- 236.5 KB
bfq-iosched.h -rw-r--r-- 36.7 KB
bfq-wf2q.c -rw-r--r-- 52.6 KB
bio-integrity.c -rw-r--r-- 12.3 KB
bio.c -rw-r--r-- 55.3 KB
blk-cgroup-rwstat.c -rw-r--r-- 3.4 KB
blk-cgroup-rwstat.h -rw-r--r-- 3.9 KB
blk-cgroup.c -rw-r--r-- 44.3 KB
blk-core.c -rw-r--r-- 48.7 KB
blk-exec.c -rw-r--r-- 2.6 KB
blk-flush.c -rw-r--r-- 15.0 KB
blk-integrity.c -rw-r--r-- 11.6 KB
blk-ioc.c -rw-r--r-- 10.2 KB
blk-iocost.c -rw-r--r-- 67.1 KB
blk-iolatency.c -rw-r--r-- 28.0 KB
blk-lib.c -rw-r--r-- 10.2 KB
blk-map.c -rw-r--r-- 6.0 KB
blk-merge.c -rw-r--r-- 24.6 KB
blk-mq-cpumap.c -rw-r--r-- 2.2 KB
blk-mq-debugfs-zoned.c -rw-r--r-- 435 bytes
blk-mq-debugfs.c -rw-r--r-- 24.4 KB
blk-mq-debugfs.h -rw-r--r-- 2.7 KB
blk-mq-pci.c -rw-r--r-- 1.3 KB
blk-mq-rdma.c -rw-r--r-- 1.3 KB
blk-mq-sched.c -rw-r--r-- 14.6 KB
blk-mq-sched.h -rw-r--r-- 2.5 KB
blk-mq-sysfs.c -rw-r--r-- 8.4 KB
blk-mq-tag.c -rw-r--r-- 14.9 KB
blk-mq-tag.h -rw-r--r-- 2.2 KB
blk-mq-virtio.c -rw-r--r-- 1.3 KB
blk-mq.c -rw-r--r-- 88.4 KB
blk-mq.h -rw-r--r-- 7.6 KB
blk-pm.c -rw-r--r-- 6.6 KB
blk-pm.h -rw-r--r-- 1.4 KB
blk-rq-qos.c -rw-r--r-- 7.1 KB
blk-rq-qos.h -rw-r--r-- 5.0 KB
blk-settings.c -rw-r--r-- 28.0 KB
blk-softirq.c -rw-r--r-- 3.7 KB
blk-stat.c -rw-r--r-- 4.6 KB
blk-stat.h -rw-r--r-- 4.6 KB
blk-sysfs.c -rw-r--r-- 26.3 KB
blk-throttle.c -rw-r--r-- 69.2 KB
blk-timeout.c -rw-r--r-- 3.8 KB
blk-wbt.c -rw-r--r-- 19.9 KB
blk-wbt.h -rw-r--r-- 2.9 KB
blk-zoned.c -rw-r--r-- 12.3 KB
blk.h -rw-r--r-- 10.7 KB
bounce.c -rw-r--r-- 9.3 KB
bsg-lib.c -rw-r--r-- 9.8 KB
bsg.c -rw-r--r-- 11.1 KB
cmdline-parser.c -rw-r--r-- 4.9 KB
elevator.c -rw-r--r-- 18.9 KB
genhd.c -rw-r--r-- 50.7 KB
ioctl.c -rw-r--r-- 19.5 KB
ioprio.c -rw-r--r-- 5.1 KB
kyber-iosched.c -rw-r--r-- 27.8 KB
mq-deadline.c -rw-r--r-- 20.6 KB
opal_proto.h -rw-r--r-- 9.3 KB
partition-generic.c -rw-r--r-- 15.9 KB
scsi_ioctl.c -rw-r--r-- 22.7 KB
sed-opal.c -rw-r--r-- 62.4 KB
t10-pi.c -rw-r--r-- 7.8 KB

back to top