Commit eb057b44 authored by Zhang Min's avatar Zhang Min Committed by Michael S. Tsirkin

vdpa: fix use-after-free on vp_vdpa_remove

When vp_vdpa driver is unbind, vp_vdpa is freed in vdpa_unregister_device
and then vp_vdpa->mdev.pci_dev is dereferenced in vp_modern_remove,
triggering use-after-free.

Call Trace of unbinding driver free vp_vdpa :
do_syscall_64
  vfs_write
    kernfs_fop_write_iter
      device_release_driver_internal
        pci_device_remove
          vp_vdpa_remove
            vdpa_unregister_device
              kobject_release
                device_release
                  kfree

Call Trace of dereference vp_vdpa->mdev.pci_dev:
vp_modern_remove
  pci_release_selected_regions
    pci_release_region
      pci_resource_len
        pci_resource_end
          (dev)->resource[(bar)].end
Signed-off-by: default avatarZhang Min <zhang.min9@zte.com.cn>
Signed-off-by: default avatarYi Wang <wang.yi59@zte.com.cn>
Link: https://lore.kernel.org/r/20220301091059.46869-1-wang.yi59@zte.com.cnSigned-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
Fixes: 64b9f64f ("vdpa: introduce virtio pci driver")
Reviewed-by: default avatarStefano Garzarella <sgarzare@redhat.com>
parent e030759a
...@@ -533,8 +533,8 @@ static void vp_vdpa_remove(struct pci_dev *pdev) ...@@ -533,8 +533,8 @@ static void vp_vdpa_remove(struct pci_dev *pdev)
{ {
struct vp_vdpa *vp_vdpa = pci_get_drvdata(pdev); struct vp_vdpa *vp_vdpa = pci_get_drvdata(pdev);
vdpa_unregister_device(&vp_vdpa->vdpa);
vp_modern_remove(&vp_vdpa->mdev); vp_modern_remove(&vp_vdpa->mdev);
vdpa_unregister_device(&vp_vdpa->vdpa);
} }
static struct pci_driver vp_vdpa_driver = { static struct pci_driver vp_vdpa_driver = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment