Skip to content

Commit

Permalink
virtio_pci: fix use after free on release
Browse files Browse the repository at this point in the history
KASan detected a use-after-free error in virtio-pci remove code. In
virtio_pci_remove(), vp_dev is still used after being freed in
unregister_virtio_device() (in virtio_pci_release_dev() more
precisely).

To fix, keep a reference until cleanup is done.

Fixes: 63bd62a ("virtio_pci: defer kfree until release callback")
Reported-by: Jerome Marchand <[email protected]>
Cc: [email protected]
Cc: Sasha Levin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
Tested-by: Jerome Marchand <[email protected]>
  • Loading branch information
mstsirkin committed Jan 26, 2016
1 parent 92e963f commit 2989be0
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions drivers/virtio/virtio_pci_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ static int virtio_pci_probe(struct pci_dev *pci_dev,
static void virtio_pci_remove(struct pci_dev *pci_dev)
{
struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
struct device *dev = get_device(&vp_dev->vdev.dev);

unregister_virtio_device(&vp_dev->vdev);

Expand All @@ -554,6 +555,7 @@ static void virtio_pci_remove(struct pci_dev *pci_dev)
virtio_pci_modern_remove(vp_dev);

pci_disable_device(pci_dev);
put_device(dev);
}

static struct pci_driver virtio_pci_driver = {
Expand Down

0 comments on commit 2989be0

Please sign in to comment.