diff options
author | Michael S. Tsirkin <mst@redhat.com> | 2016-01-14 09:00:41 -0500 |
---|---|---|
committer | Michael S. Tsirkin <mst@redhat.com> | 2016-01-26 03:18:28 -0500 |
commit | 2989be09a8a9d62a785137586ad941f916e08f83 (patch) | |
tree | 91fc1b8002e4c9868d0e692dd6b4039e965c9a36 /drivers/virtio | |
parent | 92e963f50fc74041b5e9e744c330dca48e04f08d (diff) |
virtio_pci: fix use after free on release
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: 63bd62a08ca4 ("virtio_pci: defer kfree until release callback")
Reported-by: Jerome Marchand <jmarchan@redhat.com>
Cc: stable@vger.kernel.org
Cc: Sasha Levin <sasha.levin@oracle.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Tested-by: Jerome Marchand <jmarchan@redhat.com>
Diffstat (limited to 'drivers/virtio')
-rw-r--r-- | drivers/virtio/virtio_pci_common.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c index 36205c27c4d0..f6bed86c17f9 100644 --- a/drivers/virtio/virtio_pci_common.c +++ b/drivers/virtio/virtio_pci_common.c | |||
@@ -545,6 +545,7 @@ err_enable_device: | |||
545 | static void virtio_pci_remove(struct pci_dev *pci_dev) | 545 | static void virtio_pci_remove(struct pci_dev *pci_dev) |
546 | { | 546 | { |
547 | struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev); | 547 | struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev); |
548 | struct device *dev = get_device(&vp_dev->vdev.dev); | ||
548 | 549 | ||
549 | unregister_virtio_device(&vp_dev->vdev); | 550 | unregister_virtio_device(&vp_dev->vdev); |
550 | 551 | ||
@@ -554,6 +555,7 @@ static void virtio_pci_remove(struct pci_dev *pci_dev) | |||
554 | virtio_pci_modern_remove(vp_dev); | 555 | virtio_pci_modern_remove(vp_dev); |
555 | 556 | ||
556 | pci_disable_device(pci_dev); | 557 | pci_disable_device(pci_dev); |
558 | put_device(dev); | ||
557 | } | 559 | } |
558 | 560 | ||
559 | static struct pci_driver virtio_pci_driver = { | 561 | static struct pci_driver virtio_pci_driver = { |