qemu/hw
Christian Schoenebeck 72ff530e95 9pfs: fix crash on 'Treaddir' request
A bad (broken or malicious) 9p client (guest) could cause QEMU host to
crash by sending a 9p 'Treaddir' request with a numeric file ID (FID) that
was previously opened for a file instead of an expected directory:

  #0  0x0000762aff8f4919 in __GI___rewinddir (dirp=0xf) at
    ../sysdeps/unix/sysv/linux/rewinddir.c:29
  #1  0x0000557b7625fb40 in do_readdir_many (pdu=0x557bb67d2eb0,
    fidp=0x557bb67955b0, entries=0x762afe9fff58, offset=0, maxsize=131072,
    dostat=<optimized out>) at ../hw/9pfs/codir.c:101
  #2  v9fs_co_readdir_many (pdu=pdu@entry=0x557bb67d2eb0,
    fidp=fidp@entry=0x557bb67955b0, entries=entries@entry=0x762afe9fff58,
    offset=0, maxsize=131072, dostat=false) at ../hw/9pfs/codir.c:226
  #3  0x0000557b7625c1f9 in v9fs_do_readdir (pdu=0x557bb67d2eb0,
    fidp=0x557bb67955b0, offset=<optimized out>,
    max_count=<optimized out>) at ../hw/9pfs/9p.c:2488
  #4  v9fs_readdir (opaque=0x557bb67d2eb0) at ../hw/9pfs/9p.c:2602

That's because V9fsFidOpenState was declared as union type. So the
same memory region is used for either an open POSIX file handle (int),
or a POSIX DIR* pointer, etc., so 9p server incorrectly used the
previously opened (valid) POSIX file handle (0xf) as DIR* pointer,
eventually causing a crash in glibc's rewinddir() function.

Root cause was therefore a missing check in 9p server's 'Treaddir'
request handler, which must ensure that the client supplied FID was
really opened as directory stream before trying to access the
aforementioned union and its DIR* member.

Cc: qemu-stable@nongnu.org
Fixes: d62dbb51f7 ("virtio-9p: Add fidtype so that we can do type ...")
Reported-by: Akihiro Suda <suda.kyoto@gmail.com>
Tested-by: Akihiro Suda <suda.kyoto@gmail.com>
Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Reviewed-by: Greg Kurz <groug@kaod.org>
Message-Id: <E1t8GnN-002RS8-E2@kylie.crudebyte.com>
(cherry picked from commit 042b4ebfd2)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
2024-11-08 20:42:08 +03:00
..
9pfs 9pfs: fix crash on 'Treaddir' request 2024-11-08 20:42:08 +03:00
acpi hw/acpi: Fix ordering of BDF in Generic Initiator PCI Device Handle. 2024-11-08 13:02:58 +03:00
adc
alpha hw/alpha/dp264: use pci_init_nic_devices() 2024-02-02 16:23:47 +00:00
arm hw/arm/mps2-tz.c: fix RX/TX interrupts order 2024-08-28 08:37:28 +03:00
audio hw/audio/hda: free timer on exit 2024-10-16 11:14:04 +03:00
avr
block hw/pflash: fix block write start 2024-05-27 07:37:34 +03:00
char hw/char/bcm2835_aux: Fix assert when receive FIFO fills up 2024-08-28 08:37:28 +03:00
core hw/core/ptimer: fix timer zero period condition for freq > 1GHz 2024-08-28 08:37:29 +03:00
cpu
cris hw/net/etraxfs-eth: use qemu_configure_nic_device() 2024-02-02 16:23:47 +00:00
cxl hw/cxl/cxl-host: Fix segmentation fault when getting cxl-fmw property 2024-07-24 07:31:09 +03:00
display ui/win32: fix potential use-after-free with dbus shared memory 2024-11-08 13:02:57 +03:00
dma hw/dmax/xlnx_dpdma: fix handling of address_extension descriptor fields 2024-05-02 13:16:29 +03:00
fsi
gpio * Fix timeouts in Travis-CI jobs 2024-03-25 14:19:42 +00:00
hppa hw/hppa: do not require CONFIG_USB 2024-02-27 09:37:13 +01:00
hyperv vmbus: Print a warning when enabled without the recommended set of features 2024-03-08 14:18:56 +01:00
i2c hw/i2c: Implement Broadcom Serial Controller (BSC) 2024-03-05 13:22:55 +00:00
i386 hw/i386/amd_iommu: Don't leak memory in amdvi_update_iotlb() 2024-08-28 08:37:28 +03:00
ide hw/ide/ahci: Rename ahci_internal.h to ahci-internal.h 2024-03-11 22:09:42 +01:00
input hw/input/pckbd: Open-code i8042_setup_a20_line() wrapper 2024-02-22 12:47:35 +01:00
intc ppc/xive: Fix ESB length overflow on 32-bit hosts 2024-11-08 13:02:58 +03:00
ipack
ipmi
isa hw/isa/vt82c686: Keep track of PIRQ/PINT pins separately 2024-04-15 13:07:11 +02:00
loongarch hw/loongarch/virt: Fix FDT memory node address width 2024-05-27 07:50:35 +03:00
m68k virt: set the CPU type in BOOTINFO 2024-03-11 09:38:08 +01:00
mem hw/mem/cxl_type3: Fix missing ERRP_GUARD() in ct3_realize() 2024-03-12 17:56:55 -04:00
microblaze hw/microblaze: Do not allow xlnx-zynqmp-pmu-soc to be created by the user 2024-03-25 09:57:43 +01:00
mips hw/mips/jazz: fix typo in in-built NIC alias 2024-09-28 07:35:33 +03:00
misc hw/misc/bcm2835_property: Fix handling of FRAMEBUFFER_SET_PALETTE 2024-08-28 08:37:28 +03:00
net virtio-net: Fix network stall at the host side waiting for kick 2024-08-28 08:37:28 +03:00
nios2
nubus hw/nubus: add nubus-virtio-mmio device 2024-02-27 09:36:39 +01:00
nvme hw/nvme: fix handling of over-committed queues 2024-11-08 20:41:36 +03:00
nvram hw/nvram/mac_nvram: Report failure to write data 2024-03-25 10:41:01 +00:00
openrisc hw/openrisc/openrisc_sim: use qemu_create_nic_device() 2024-02-02 16:23:47 +00:00
pci virtio,pc,pci: features, cleanups, fixes 2024-03-13 15:11:53 +00:00
pci-bridge virtio,pc,pci: features, cleanups, fixes 2024-03-13 15:11:53 +00:00
pci-host hw/pci-host/ppc440_pcix: Do not expose a bridge device on PCI bus 2024-04-15 13:07:15 +02:00
pcmcia
ppc hw/ppc/spapr: Include missing 'sysemu/tcg.h' header 2024-03-30 18:50:23 +10:00
rdma
remote hw/remote/vfio-user: Fix config space access byte order 2024-05-10 13:20:20 +03:00
riscv target/riscv/kvm: fix timebase-frequency when using KVM acceleration 2024-03-22 15:41:01 +10:00
rtc hw/rtc/sun4v-rtc: Relicense to GPLv2-or-later 2024-03-07 12:54:56 +00:00
rx hw/rx/rx62n: Only call qdev_get_gpio_in() when necessary 2024-02-15 16:58:46 +01:00
s390x hw/core: Declare CPUArchId::cpu as CPUState instead of Object 2024-03-12 11:46:16 +01:00
scsi scsi: fix regression and honor bootindex again for legacy drives 2024-07-19 19:43:05 +03:00
sd hw/sd/sdhci: Reset @data_count index on invalid ADMA transfers 2024-08-28 08:37:28 +03:00
sensor
sh4 Revert "hw/sh4/r2d: Realize IDE controller before accessing it" 2024-11-08 13:02:57 +03:00
smbios hw/smbios: add stub for smbios_get_table_legacy() 2024-03-26 14:32:54 +01:00
sparc hw/sparc/leon3: Fix wrong usage of DO_UPCAST macro 2024-02-22 12:47:40 +01:00
sparc64 sun4u: remap ebus BAR0 to use unassigned_io_ops instead of alias to PCI IO space 2024-03-11 22:10:18 +01:00
ssi aspeed/smc: Only wire flash devices at reset 2024-03-19 11:58:15 +01:00
timer misc: pxa2xx_timer: replace qemu_system_reset_request() call with watchdog_perform_action() 2024-02-27 13:01:41 +00:00
tpm hw/tpm: Remove HOST_PAGE_ALIGN from tpm_ppi_init 2024-02-29 11:35:36 -10:00
tricore hw/tricore/testboard: Use qdev_new() instead of QOM basic API 2024-02-22 12:47:40 +01:00
ufs hw/ufs: Fix buffer overflow bug 2024-05-02 13:03:05 +03:00
usb usb-storage: Fix BlockConf defaults 2024-04-16 11:50:52 +01:00
vfio vfio/migration: Report only stop-copy size in vfio_state_pending_exact() 2024-11-08 13:02:57 +03:00
virtio virtio-pci: Fix the use of an uninitialized irqfd 2024-08-28 08:37:29 +03:00
watchdog
xen Xen queue: 2024-03-12 21:32:31 +00:00
xenpv hw/xen: use qemu_create_nic_bus_devices() to instantiate Xen NICs 2024-02-02 16:23:47 +00:00
xtensa hw/xtensa/xtfpga: use qemu_create_nic_device() 2024-02-02 16:23:47 +00:00
Kconfig
meson.build