qemu-e2k/hw/display
Philippe Mathieu-Daudé ba28e0ff4d hw/display/virtio-gpu: Protect from DMA re-entrancy bugs
Replace qemu_bh_new_guarded() by virtio_bh_new_guarded()
so the bus and device use the same guard. Otherwise the
DMA-reentrancy protection can be bypassed:

  $ cat << EOF | qemu-system-i386 -display none -nodefaults \
                                  -machine q35,accel=qtest \
                                  -m 512M \
                                  -device virtio-gpu \
                                  -qtest stdio
  outl 0xcf8 0x80000820
  outl 0xcfc 0xe0004000
  outl 0xcf8 0x80000804
  outw 0xcfc 0x06
  write 0xe0004030 0x4 0x024000e0
  write 0xe0004028 0x1 0xff
  write 0xe0004020 0x4 0x00009300
  write 0xe000401c 0x1 0x01
  write 0x101 0x1 0x04
  write 0x103 0x1 0x1c
  write 0x9301c8 0x1 0x18
  write 0x105 0x1 0x1c
  write 0x107 0x1 0x1c
  write 0x109 0x1 0x1c
  write 0x10b 0x1 0x00
  write 0x10d 0x1 0x00
  write 0x10f 0x1 0x00
  write 0x111 0x1 0x00
  write 0x113 0x1 0x00
  write 0x115 0x1 0x00
  write 0x117 0x1 0x00
  write 0x119 0x1 0x00
  write 0x11b 0x1 0x00
  write 0x11d 0x1 0x00
  write 0x11f 0x1 0x00
  write 0x121 0x1 0x00
  write 0x123 0x1 0x00
  write 0x125 0x1 0x00
  write 0x127 0x1 0x00
  write 0x129 0x1 0x00
  write 0x12b 0x1 0x00
  write 0x12d 0x1 0x00
  write 0x12f 0x1 0x00
  write 0x131 0x1 0x00
  write 0x133 0x1 0x00
  write 0x135 0x1 0x00
  write 0x137 0x1 0x00
  write 0x139 0x1 0x00
  write 0xe0007003 0x1 0x00
  EOF
  ...
  =================================================================
  ==276099==ERROR: AddressSanitizer: heap-use-after-free on address 0x60d000011178
  at pc 0x562cc3b736c7 bp 0x7ffed49dee60 sp 0x7ffed49dee58
  READ of size 8 at 0x60d000011178 thread T0
      #0 0x562cc3b736c6 in virtio_gpu_ctrl_response hw/display/virtio-gpu.c:180:42
      #1 0x562cc3b7c40b in virtio_gpu_ctrl_response_nodata hw/display/virtio-gpu.c:192:5
      #2 0x562cc3b7c40b in virtio_gpu_simple_process_cmd hw/display/virtio-gpu.c:1015:13
      #3 0x562cc3b82873 in virtio_gpu_process_cmdq hw/display/virtio-gpu.c:1050:9
      #4 0x562cc4a85514 in aio_bh_call util/async.c:169:5
      #5 0x562cc4a85c52 in aio_bh_poll util/async.c:216:13
      #6 0x562cc4a1a79b in aio_dispatch util/aio-posix.c:423:5
      #7 0x562cc4a8a2da in aio_ctx_dispatch util/async.c:358:5
      #8 0x7f36840547a8 in g_main_context_dispatch (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x547a8)
      #9 0x562cc4a8b753 in glib_pollfds_poll util/main-loop.c:290:9
      #10 0x562cc4a8b753 in os_host_main_loop_wait util/main-loop.c:313:5
      #11 0x562cc4a8b753 in main_loop_wait util/main-loop.c:592:11
      #12 0x562cc3938186 in qemu_main_loop system/runstate.c:782:9
      #13 0x562cc43b7af5 in qemu_default_main system/main.c:37:14
      #14 0x7f3683a6c189 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
      #15 0x7f3683a6c244 in __libc_start_main csu/../csu/libc-start.c:381:3
      #16 0x562cc2a58ac0 in _start (qemu-system-i386+0x231bac0)

  0x60d000011178 is located 56 bytes inside of 136-byte region [0x60d000011140,0x60d0000111c8)
  freed by thread T0 here:
      #0 0x562cc2adb662 in __interceptor_free (qemu-system-i386+0x239e662)
      #1 0x562cc3b86b21 in virtio_gpu_reset hw/display/virtio-gpu.c:1524:9
      #2 0x562cc416e20e in virtio_reset hw/virtio/virtio.c:2145:9
      #3 0x562cc37c5644 in virtio_pci_reset hw/virtio/virtio-pci.c:2249:5
      #4 0x562cc4233758 in memory_region_write_accessor system/memory.c:497:5
      #5 0x562cc4232eea in access_with_adjusted_size system/memory.c:573:18

  previously allocated by thread T0 here:
      #0 0x562cc2adb90e in malloc (qemu-system-i386+0x239e90e)
      #1 0x7f368405a678 in g_malloc (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x5a678)
      #2 0x562cc4163ffc in virtqueue_split_pop hw/virtio/virtio.c:1612:12
      #3 0x562cc4163ffc in virtqueue_pop hw/virtio/virtio.c:1783:16
      #4 0x562cc3b91a95 in virtio_gpu_handle_ctrl hw/display/virtio-gpu.c:1112:15
      #5 0x562cc4a85514 in aio_bh_call util/async.c:169:5
      #6 0x562cc4a85c52 in aio_bh_poll util/async.c:216:13
      #7 0x562cc4a1a79b in aio_dispatch util/aio-posix.c:423:5

  SUMMARY: AddressSanitizer: heap-use-after-free hw/display/virtio-gpu.c:180:42 in virtio_gpu_ctrl_response

With this change, the same reproducer triggers:

  qemu-system-i386: warning: Blocked re-entrant IO on MemoryRegion: virtio-pci-common-virtio-gpu at addr: 0x6

Fixes: CVE-2024-3446
Cc: qemu-stable@nongnu.org
Reported-by: Alexander Bulekov <alxndr@bu.edu>
Reported-by: Yongkang Jia <kangel@zju.edu.cn>
Reported-by: Xiao Lei <nop.leixiao@gmail.com>
Reported-by: Yiming Tao <taoym@zju.edu.cn>
Buglink: https://bugs.launchpad.net/qemu/+bug/1888606
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Message-Id: <20240409105537.18308-3-philmd@linaro.org>
2024-04-10 09:09:33 +02:00
..
acpi-vga-stub.c acpi: pc: vga: use AcpiDevAmlIf interface to build VGA device descriptors 2022-11-07 14:00:29 -05:00
acpi-vga.c acpi: pc: vga: use AcpiDevAmlIf interface to build VGA device descriptors 2022-11-07 14:00:29 -05:00
artist.c hw/display: Constify VMState 2023-12-29 11:17:30 +11:00
ati_2d.c hw/display/ati: allow compiling without PIXMAN 2023-11-07 14:04:25 +04:00
ati_dbg.c ati-vga: Add 30 bit palette access register 2023-11-06 15:58:43 +04:00
ati_int.h ati-vga: Implement fallback for pixman routines 2023-11-06 15:58:45 +04:00
ati_regs.h ati-vga: Add 30 bit palette access register 2023-11-06 15:58:43 +04:00
ati.c bulk: Access existing variables initialized to &S->F when available 2024-03-12 11:46:16 +01:00
bcm2835_fb.c hw/display: Constify VMState 2023-12-29 11:17:30 +11:00
blizzard.c hw/display: fix tab indentation 2022-11-08 10:23:32 +01:00
bochs-display.c hw/display: Constify VMState 2023-12-29 11:17:30 +11:00
cg3.c hw/display: Constify VMState 2023-12-29 11:17:30 +11:00
cirrus_vga_internal.h
cirrus_vga_isa.c display: include dependencies explicitly 2022-11-10 10:17:18 -05:00
cirrus_vga_rop2.h
cirrus_vga_rop.h
cirrus_vga.c vga: implement horizontal pel panning in graphics modes 2024-01-18 10:43:13 +01:00
dpcd.c hw/display: Constify VMState 2023-12-29 11:17:30 +11:00
edid-generate.c edid: Fix clock of Detailed Timing Descriptor 2022-03-04 11:31:46 +01:00
edid-region.c
exynos4210_fimd.c hw/display/exynos4210_fimd: Pass frame buffer memory region as link 2024-02-26 18:40:09 +01:00
framebuffer.c
framebuffer.h
g364fb.c hw/display: Constify VMState 2023-12-29 11:17:30 +11:00
i2c-ddc.c hw/display: Constify VMState 2023-12-29 11:17:30 +11:00
jazz_led.c hw/display: Constify VMState 2023-12-29 11:17:30 +11:00
Kconfig mips: do not list individual devices from configs/ 2024-03-08 15:51:22 +01:00
macfb.c hw/display/macfb: Fix missing ERRP_GUARD() in macfb_nubus_realize() 2024-03-12 11:45:33 +01:00
meson.build configure, meson: rename targetos to host_os 2023-12-31 09:11:29 +01:00
next-fb.c hw/display/next-fb: Fix comment typo 2022-12-03 22:07:07 +01:00
omap_dss.c hw/arm/omap: Drop useless casts from void * to pointer 2023-01-12 17:15:09 +00:00
omap_lcdc.c hw/arm/omap: Drop useless casts from void * to pointer 2023-01-12 17:15:09 +00:00
pl110_template.h Replace config-time define HOST_WORDS_BIGENDIAN 2022-04-06 10:50:37 +02:00
pl110.c hw/display/pl110: Pass frame buffer memory region as link property 2024-02-26 18:39:58 +01:00
pxa2xx_lcd.c hw/display: Constify VMState 2023-12-29 11:17:30 +11:00
qxl-logger.c hw/display/qxl: Pass requested buffer size to qxl_phys2virt() 2022-11-29 18:15:26 -05:00
qxl-render.c ui: rename cursor_{put->unref} 2023-03-13 22:57:39 +04:00
qxl.c hw/display: Constify VMState 2023-12-29 11:17:30 +11:00
qxl.h Replace "iothread lock" with "BQL" in comments 2024-01-08 10:45:43 -05:00
ramfb-standalone.c hw/display: Constify VMState 2023-12-29 11:17:30 +11:00
ramfb.c hw/display: Constify VMState 2023-12-29 11:17:30 +11:00
sii9022.c hw/display: Constify VMState 2023-12-29 11:17:30 +11:00
sm501.c hw/display: Constify VMState 2023-12-29 11:17:30 +11:00
ssd0303.c hw/display: Constify VMState 2023-12-29 11:17:30 +11:00
ssd0323.c hw/display: Constify VMState 2023-12-29 11:17:30 +11:00
tc6393xb.c Use g_new() & friends where that makes obvious sense 2022-03-21 15:44:44 +01:00
tcx.c hw/display: Constify VMState 2023-12-29 11:17:30 +11:00
trace-events ui/spice: QXLInterface method set_mm_time() is now dead, drop 2023-01-19 13:30:01 +01:00
trace.h
vga_int.h vga: implement horizontal pel panning in graphics modes 2024-01-18 10:43:13 +01:00
vga_regs.h vga: sort-of implement word and double-word access modes 2024-01-18 10:43:14 +01:00
vga-access.h
vga-helpers.h vga: optimize horizontal pel panning in 256-color modes 2024-01-18 10:43:14 +01:00
vga-isa.c docs/specs/standard-vga: Convert to rST 2023-11-02 12:52:06 +00:00
vga-mmio.c display: include dependencies explicitly 2022-11-10 10:17:18 -05:00
vga-pci.c hw/display: Constify VMState 2023-12-29 11:17:30 +11:00
vga.c vga: do not treat horiz pel panning value of 8 as "enabled" 2024-04-02 18:08:59 +02:00
vhost-user-gpu-pci.c modules: introduces module_kconfig directive 2022-06-06 09:26:53 +02:00
vhost-user-gpu.c vhost-user-gpu: skip VHOST_USER_GPU_UPDATE when !PIXMAN 2023-11-07 14:04:25 +04:00
vhost-user-vga.c modules: introduces module_kconfig directive 2022-06-06 09:26:53 +02:00
virtio-dmabuf.c hw/display: fix memleak from virtio_add_resource 2023-10-22 05:18:16 -04:00
virtio-gpu-base.c Fix bugs when VM shutdown with virtio-gpu unplugged 2023-12-26 04:51:07 -05:00
virtio-gpu-gl.c modules: introduces module_kconfig directive 2022-06-06 09:26:53 +02:00
virtio-gpu-pci-gl.c modules: introduces module_kconfig directive 2022-06-06 09:26:53 +02:00
virtio-gpu-pci-rutabaga.c virtio-gpu-rutabaga: Add empty interface to fix arm64 crash 2023-11-06 14:25:30 +04:00
virtio-gpu-pci.c virtio-gpu: hostmem 2023-10-16 11:29:56 +04:00
virtio-gpu-rutabaga.c virtio-gpu-rutabaga.c: override resource_destroy method 2024-02-14 06:17:44 -05:00
virtio-gpu-udmabuf-stubs.c virtio-gpu: splitting one extended mode guest fb into n-scanouts 2021-11-05 12:29:19 +01:00
virtio-gpu-udmabuf.c virtio-gpu-udmabuf: correct naming of QemuDmaBuf size properties 2023-07-17 15:22:28 +04:00
virtio-gpu-virgl.c virtio-gpu: Correct virgl_renderer_resource_get_info() error check 2024-02-14 06:09:33 -05:00
virtio-gpu.c hw/display/virtio-gpu: Protect from DMA re-entrancy bugs 2024-04-10 09:09:33 +02:00
virtio-vga-gl.c modules: introduces module_kconfig directive 2022-06-06 09:26:53 +02:00
virtio-vga-rutabaga.c gfxstream + rutabaga: add initial support for gfxstream 2023-10-16 11:29:56 +04:00
virtio-vga.c hw/display: Constify VMState 2023-12-29 11:17:30 +11:00
virtio-vga.h hw/display/virtio-vga: Convert TYPE_VIRTIO_VGA_BASE to 3-phase reset 2022-12-16 15:59:07 +00:00
vmware_vga.c hw/display: Constify VMState 2023-12-29 11:17:30 +11:00
xenfb.c ui/input: Constify QemuInputHandler structure 2023-10-19 23:13:28 +02:00
xlnx_dp.c hw/display: Constify VMState 2023-12-29 11:17:30 +11:00