android_kernel_samsung_a7y1.../drivers
Zhang Xiaoxu 5b3bfd68ee vgacon: Fix a UAF in vgacon_invert_region
commit 513dc792d6060d5ef572e43852683097a8420f56 upstream.

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
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-04-07 14:10:20 +02:00
..
accessibility
acpi ACPICA: Disassembler: create buffer fields in ACPI_PARSE_LOAD_PASS1 2020-04-07 13:56:22 +02:00
amba
android ANDROID: binder: synchronize_rcu() when using POLLFREE. 2020-04-07 08:06:59 +02:00
ata ahci: Do not export local variable ahci_em_messages 2020-04-07 13:43:01 +02:00
atm atm: eni: fix uninitialized variable warning 2020-04-07 13:45:54 +02:00
auxdisplay
base driver core: Print device when resources present in really_probe() 2020-04-07 13:56:48 +02:00
battery
battery_v2
bcma bcma: fix incorrect update of BCMA_CORE_PCI_MDIO_DATA 2020-04-07 13:43:09 +02:00
block floppy: check FDC index for errors before assigning it 2020-04-07 14:01:14 +02:00
bluetooth Bluetooth: btusb: fix PM leak in error case of setup 2020-04-07 13:24:51 +02:00
bts
bus
ccic
cdrom cdrom: respect device capabilities during opening action 2020-04-07 13:23:35 +02:00
char ipmi:ssif: Handle a possible NULL pointer reference 2020-04-07 14:04:14 +02:00
clk clk: qcom: rcg2: Don't crash if our parent can't be found; return an error 2020-04-07 13:56:02 +02:00
clocksource clocksource/drivers/sun5i: Fail gracefully when clock rate is unavailable 2020-04-07 13:40:44 +02:00
connector
cpufreq cpufreq: Register drivers only after CPU devices have been registered 2020-04-07 13:21:35 +02:00
cpuidle cpuidle: Do not unset the driver if it is there already 2020-04-07 13:07:18 +02:00
crypto crypto: picoxcell - adjust the position of tasklet_init and fix missed tasklet_kill 2020-04-07 13:50:08 +02:00
dca
devfreq PM / devfreq: Don't fail devfreq_dev_release if not in list 2020-04-07 13:24:09 +02:00
dio
dma dmaengine: ti: edma: fix missed failure handling 2020-04-07 13:43:56 +02:00
dma-buf
edac EDAC/ghes: Fix grain calculation 2020-04-07 13:21:28 +02:00
eisa
extcon extcon: sm5502: Reset registers during initialization 2020-04-07 13:20:38 +02:00
fingerprint
firewire net: add annotations on hh->hh_len lockless accesses 2020-04-07 13:25:04 +02:00
firmware gsmi: Fix bug in append_to_eventlog sysfs handler 2020-04-07 12:34:33 +02:00
five
fmc
fpga
gator
gpio gpio: Fix error message on out-of-range GPIO in lookup table 2020-04-07 13:36:46 +02:00
gps
gpu drm/msm/dsi: save pll state before dsi host is powered off 2020-04-07 14:09:59 +02:00
gud
hid HID: hiddev: Fix race in in hiddev_disconnect() 2020-04-07 14:04:49 +02:00
hsi
hv
hwmon hwmon: (pmbus/ltc2978) Fix PMBus polling of MFR_COMMON definitions. 2020-04-07 13:55:21 +02:00
hwspinlock
hwtracing stm class: Fix a double free of stm_source_device 2020-04-06 21:33:50 +02:00
i2c i2c: jz4780: silence log flood on txabrt 2020-04-07 14:04:52 +02:00
ide ide: serverworks: potential overflow in svwks_set_pio_mode() 2020-04-07 13:56:59 +02:00
idle
iio iio: buffer: align the size of scan bytes to size of the largest element 2020-04-07 13:45:04 +02:00
infiniband scsi: Revert "RDMA/isert: Fix a recently introduced regression related to logout" 2020-04-07 14:03:52 +02:00
input Input: edt-ft5x06 - work around first register access error 2020-04-07 13:56:40 +02:00
iommu iommu/arm-smmu-v3: Use WRITE_ONCE() when changing validity of an STE 2020-04-07 13:56:53 +02:00
ipack
irqchip irqchip/gic-v3-its: Reference to its_invall_cmd descriptor when building INVALL 2020-04-07 13:57:27 +02:00
isdn staging: gigaset: add endpoint-type sanity check 2020-04-07 13:06:29 +02:00
leds leds: leds-lp5562 allow firmware files up to the maximum length 2020-04-07 07:37:48 +02:00
lguest
lightnvm
macintosh macintosh/windfarm_smu_sat: Fix debug output 2020-04-07 12:35:02 +02:00
mailbox
mcb
md bcache: explicity type cast in bset_bkey_last() 2020-04-07 13:57:25 +02:00
media media: sti: bdisp: fix a possible sleep-in-atomic-context bug in bdisp_device_run() 2020-04-07 13:55:42 +02:00
memory
memstick memstick: jmb38x_ms: Fix an error handling path in 'jmb38x_ms_probe()' 2020-04-07 09:27:02 +02:00
message scsi: mptfusion: Fix double fetch bug in ioctl 2020-04-07 13:37:43 +02:00
mfd mfd: rn5t618: Mark ADC control register volatile 2020-04-07 13:51:00 +02:00
misc mic: avoid statically declaring a 'struct device'. 2020-04-07 13:42:37 +02:00
mmc mmc: spi: Toggle SPI polarity, do not hardcode it 2020-04-07 13:49:49 +02:00
motor
mtd mtd: spear_smi: Fix Write Burst mode 2020-04-07 13:06:47 +02:00
muic
net net: ks8851-ml: Fix 16-bit IO operation 2020-04-07 14:10:05 +02:00
nfc nfc: pn544: Fix occasional HW initialization failure 2020-04-07 14:04:37 +02:00
ntb ntb: intel: fix return value for ndev_vec_mask() 2020-04-07 12:36:03 +02:00
nubus
nvdimm
nvme
nvmem nvmem: core: return error code instead of NULL from nvmem_device_get 2020-04-07 12:27:36 +02:00
of of: Add OF_DMA_DEFAULT_COHERENT & select it on powerpc 2020-04-07 13:50:01 +02:00
oprofile
parisc parisc: Disable HP HSC-PCI Cards to prevent kernel crash 2020-04-07 07:39:52 +02:00
parport parport: load lowlevel driver if ports not found 2020-04-07 13:21:33 +02:00
pci PCI: Don't disable bridge BARs when assigning bus resources 2020-04-07 13:56:46 +02:00
pcmcia
perf
phy
pinctrl pinctrl: sh-pfc: sh7269: Fix CAN function GPIOs 2020-04-07 13:56:29 +02:00
platform MIPS: Loongson: Fix return value of loongson_hwmon_init 2020-04-07 13:43:51 +02:00
pnp
power power: supply: ltc2941-battery-gauge: fix use-after-free 2020-04-07 13:49:57 +02:00
powercap
pps drivers/pps/pps.c: clear offset flags in PPS_SETPARAMS ioctl 2020-04-06 20:26:27 +02:00
ps3
ptp
pwm pwm: Clear chip_data in pwm_put() 2020-04-07 12:43:26 +02:00
rapidio
ras
regulator regulator: rk808: Lower log level on optional GPIOs being not available 2020-04-07 13:56:05 +02:00
remoteproc remoteproc: Initialize rproc_class before use 2020-04-07 13:57:01 +02:00
reset
rpmsg
rtc rtc: hym8563: Return -EINVAL if the time is known to be invalid 2020-04-07 13:54:35 +02:00
s390 s390/cio: cio_ignore_proc_seq_next should increase position index 2020-04-07 14:10:08 +02:00
sbus
scsi scsi: iscsi: Don't destroy session if there are outstanding connections 2020-04-07 13:56:55 +02:00
security/samsung/icdrv
sensorhub
sensors
sfi
sh
sn
soc soc/tegra: fuse: Correct straps' address for older Tegra124 device trees 2020-04-07 13:56:37 +02:00
spi spi: spi-fsl-spi: call spi_finalize_current_message() at the end 2020-04-07 13:42:01 +02:00
spmi
ssb
staging staging: rtl8188eu: Fix potential overuse of kernel memory 2020-04-07 14:03:24 +02:00
switch
target scsi: Revert "target: iscsi: Wait for all commands to finish before freeing a session" 2020-04-07 14:03:54 +02:00
tc
tee
thermal thermal: cpu_cooling: Actually trace CPU load in thermal_power_cpu_get_power 2020-04-07 13:41:59 +02:00
thunderbolt thunderbolt: Use 32-bit writes when writing ring producer/consumer 2020-04-07 09:27:58 +02:00
trace
tty serial: ar933x_uart: set UART_CS_{RX,TX}_READY_ORIDE 2020-04-07 14:09:52 +02:00
uh
uio uio: fix a sleep-in-atomic-context bug in uio_dmem_genirq_irqcontrol() 2020-04-07 13:55:48 +02:00
usb usb: core: port: do error out if usb_autopm_get_interface() fails 2020-04-07 14:10:18 +02:00
uwb
vfio vfio_pci: Enable memory accesses before calling pci_map_rom 2020-04-07 13:40:33 +02:00
vhost vhost: make sure log_num < in_num 2020-04-06 21:35:05 +02:00
video vgacon: Fix a UAF in vgacon_invert_region 2020-04-07 14:10:20 +02:00
virt
virtio virtio-balloon: fix managed page counts when migrating pages between zones 2020-04-07 13:06:49 +02:00
vision
vlynq
vme
w1
watchdog watchdog: da9062: do not ping the hw during stop() 2020-04-07 14:10:06 +02:00
xen xen: Enable interrupts when calling _cond_resched() 2020-04-07 14:04:03 +02:00
zorro
Kconfig
Makefile