* [PATCH] virtio_pci: fix use after free on release
@ 2016-01-14 14:04 Michael S. Tsirkin
2016-01-14 14:55 ` Jerome Marchand
0 siblings, 1 reply; 2+ messages in thread
From: Michael S. Tsirkin @ 2016-01-14 14:04 UTC (permalink / raw)
To: linux-kernel; +Cc: Jerome Marchand, stable, Sasha Levin, virtualization
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>
---
drivers/virtio/virtio_pci_common.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
index 36205c2..f6bed86 100644
--- a/drivers/virtio/virtio_pci_common.c
+++ b/drivers/virtio/virtio_pci_common.c
@@ -545,6 +545,7 @@ err_enable_device:
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);
@@ -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 = {
--
MST
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] virtio_pci: fix use after free on release
2016-01-14 14:04 [PATCH] virtio_pci: fix use after free on release Michael S. Tsirkin
@ 2016-01-14 14:55 ` Jerome Marchand
0 siblings, 0 replies; 2+ messages in thread
From: Jerome Marchand @ 2016-01-14 14:55 UTC (permalink / raw)
To: Michael S. Tsirkin, linux-kernel; +Cc: stable, Sasha Levin, virtualization
[-- Attachment #1: Type: text/plain, Size: 1525 bytes --]
On 01/14/2016 03:04 PM, Michael S. Tsirkin wrote:
> 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.
That does make KASan happy.
>
> 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>
Thanks,
Jerome
> ---
> drivers/virtio/virtio_pci_common.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
> index 36205c2..f6bed86 100644
> --- a/drivers/virtio/virtio_pci_common.c
> +++ b/drivers/virtio/virtio_pci_common.c
> @@ -545,6 +545,7 @@ err_enable_device:
> 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);
>
> @@ -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 = {
>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-01-14 14:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-14 14:04 [PATCH] virtio_pci: fix use after free on release Michael S. Tsirkin
2016-01-14 14:55 ` Jerome Marchand
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).