]> git.proxmox.com Git - mirror_qemu.git/commitdiff
hw/vfio/pci: fix double free in vfio_msi_disable
authorEvgeny Yakovlev <wrfsh@yandex-team.ru>
Thu, 10 Oct 2019 17:07:28 +0000 (11:07 -0600)
committerAlex Williamson <alex.williamson@redhat.com>
Thu, 10 Oct 2019 17:07:28 +0000 (11:07 -0600)
The following guest behaviour patter leads to double free in VFIO PCI:

1. Guest enables MSI interrupts
vfio_msi_enable is called, but fails in vfio_enable_vectors.
In our case this was because VFIO GPU device was in D3 state.
Unhappy path in vfio_msi_enable will g_free(vdev->msi_vectors) but not
set this pointer to NULL

2. Guest still sees MSI an enabled after that because emulated config
write is done in vfio_pci_write_config unconditionally before calling
vfio_msi_enable

3. Guest disables MSI interrupts
vfio_msi_disable is called and tries to g_free(vdev->msi_vectors)
in vfio_msi_disable_common => double free

Signed-off-by: Evgeny Yakovlev <wrfsh@yandex-team.ru>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
hw/vfio/pci.c

index c5e6fe61cb3e5dab0093f751a49cadd018b5da0b..12fac3980465b643ad15f34748e12235eb43eb04 100644 (file)
@@ -651,6 +651,7 @@ retry:
         }
 
         g_free(vdev->msi_vectors);
+        vdev->msi_vectors = NULL;
 
         if (ret > 0 && ret != vdev->nr_vectors) {
             vdev->nr_vectors = ret;