diff options
author | Michael S. Tsirkin <mst@redhat.com> | 2011-11-07 11:37:05 -0500 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2011-11-13 19:46:26 -0500 |
commit | 72103bd1285211440621f2c46f4fce377584de54 (patch) | |
tree | 5bde795c7150c0802fb5a9c9e8603580e6febeae | |
parent | 1ea6b8f48918282bdca0b32a34095504ee65bab5 (diff) |
virtio-pci: fix use after free
Commit 31a3ddda166cda86d2b5111e09ba4bda5239fae6 introduced
a use after free in virtio-pci. The main issue is
that the release method signals removal of the virtio device,
while remove signals removal of the pci device.
For example, on driver removal or hot-unplug,
virtio_pci_release_dev is called before virtio_pci_remove.
We then might get a crash as virtio_pci_remove tries to use the
device freed by virtio_pci_release_dev.
We allocate/free all resources together with the
pci device, so we can leave the release method empty.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Cc: stable@kernel.org
-rw-r--r-- | drivers/virtio/virtio_pci.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci.c index 79a31e5b4b68..3d1bf41e8892 100644 --- a/drivers/virtio/virtio_pci.c +++ b/drivers/virtio/virtio_pci.c | |||
@@ -594,11 +594,11 @@ static struct virtio_config_ops virtio_pci_config_ops = { | |||
594 | 594 | ||
595 | static void virtio_pci_release_dev(struct device *_d) | 595 | static void virtio_pci_release_dev(struct device *_d) |
596 | { | 596 | { |
597 | struct virtio_device *dev = container_of(_d, struct virtio_device, | 597 | /* |
598 | dev); | 598 | * No need for a release method as we allocate/free |
599 | struct virtio_pci_device *vp_dev = to_vp_device(dev); | 599 | * all devices together with the pci devices. |
600 | 600 | * Provide an empty one to avoid getting a warning from core. | |
601 | kfree(vp_dev); | 601 | */ |
602 | } | 602 | } |
603 | 603 | ||
604 | /* the PCI probing function */ | 604 | /* the PCI probing function */ |
@@ -686,6 +686,7 @@ static void __devexit virtio_pci_remove(struct pci_dev *pci_dev) | |||
686 | pci_iounmap(pci_dev, vp_dev->ioaddr); | 686 | pci_iounmap(pci_dev, vp_dev->ioaddr); |
687 | pci_release_regions(pci_dev); | 687 | pci_release_regions(pci_dev); |
688 | pci_disable_device(pci_dev); | 688 | pci_disable_device(pci_dev); |
689 | kfree(vp_dev); | ||
689 | } | 690 | } |
690 | 691 | ||
691 | #ifdef CONFIG_PM | 692 | #ifdef CONFIG_PM |