Skip to contentSkip to conversation

bus/pci: fix use after free on unplug

PATCH In review David Marchand 2 participants 3 messages Nov 3, 2021 – Nov 4, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bus/pci: fix use after free on unplug

rte_pci_unmap_device() needs intr_handle objects to unregister callbacks.

Bugzilla ID: 845

Fixes d61138d4f0e2 ("drivers: remove direct access to interrupt handle")
---
 drivers/bus/pci/pci_common.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/bus/pci/pci_common.c +9 -8
index f8fff2c98e..4a3a87f24f 100644
@@ -271,10 +271,6 @@ rte_pci_probe_one_driver(struct rte_pci_driver *dr,
 		return ret; /* no rollback if already succeeded earlier */
 	if (ret) {
 		dev->driver = NULL;
-		rte_intr_instance_free(dev->vfio_req_intr_handle);
-		dev->vfio_req_intr_handle = NULL;
-		rte_intr_instance_free(dev->intr_handle);
-		dev->intr_handle = NULL;
 		if ((dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) &&
 			/* Don't unmap if device is unsupported and
 			 * driver needs mapped resources.
@@ -282,6 +278,10 @@ rte_pci_probe_one_driver(struct rte_pci_driver *dr,
 			!(ret > 0 &&
 				(dr->drv_flags & RTE_PCI_DRV_KEEP_MAPPED_RES)))
 			rte_pci_unmap_device(dev);
+		rte_intr_instance_free(dev->vfio_req_intr_handle);
+		dev->vfio_req_intr_handle = NULL;
+		rte_intr_instance_free(dev->intr_handle);
+		dev->intr_handle = NULL;
 	} else {
 		dev->device.driver = &dr->driver;
 	}
@@ -322,15 +322,16 @@ rte_pci_detach_dev(struct rte_pci_device *dev)
 	/* clear driver structure */
 	dev->driver = NULL;
 	dev->device.driver = NULL;
-	rte_intr_instance_free(dev->intr_handle);
-	dev->intr_handle = NULL;
-	rte_intr_instance_free(dev->vfio_req_intr_handle);
-	dev->vfio_req_intr_handle = NULL;
 
 	if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING)
 		/* unmap resources for devices that use igb_uio */
 		rte_pci_unmap_device(dev);
 
+	rte_intr_instance_free(dev->intr_handle);
+	dev->intr_handle = NULL;
+	rte_intr_instance_free(dev->vfio_req_intr_handle);
+	dev->vfio_req_intr_handle = NULL;
+
 	return 0;
 }
 
Signature · 1 line
2.23.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 49 lines · David Marchand

rte_pci_unmap_device() needs intr_handle objects to unregister callbacks.

Bugzilla ID: 845

Fixes d61138d4f0e2 ("drivers: remove direct access to interrupt handle")
---
  drivers/bus/pci/pci_common.c | 17 +++++++++--------
  1 file changed, 9 insertions(+), 8 deletions(-)
drivers/bus/pci/pci_common.c +4 -8
index f8fff2c98e..4a3a87f24f 100644
@@ -271,10 +271,6 @@ rte_pci_probe_one_driver(struct rte_pci_driver *dr,
  		return ret; /* no rollback if already succeeded earlier */
  	if (ret) {
  		dev->driver = NULL;
-		rte_intr_instance_free(dev->vfio_req_intr_handle);
-		dev->vfio_req_intr_handle = NULL;
-		rte_intr_instance_free(dev->intr_handle);
-		dev->intr_handle = NULL;
  		if ((dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) &&
  			/* Don't unmap if device is unsupported and
  			 * driver needs mapped resources.
@@ -282,6 +278,10 @@ rte_pci_probe_one_driver(struct rte_pci_driver *dr,
  			!(ret > 0 &&
  				(dr->drv_flags & RTE_PCI_DRV_KEEP_MAPPED_RES)))
  			rte_pci_unmap_device(dev);
+		rte_intr_instance_free(dev->vfio_req_intr_handle);
+		dev->vfio_req_intr_handle = NULL;
+		rte_intr_instance_free(dev->intr_handle);
+		dev->intr_handle = NULL;
  	} else {
  		dev->device.driver = &dr->driver;
  	}
@@ -322,15 +322,16 @@ rte_pci_detach_dev(struct rte_pci_device *dev)
  	/* clear driver structure */
  	dev->driver = NULL;
  	dev->device.driver = NULL;
-	rte_intr_instance_free(dev->intr_handle);
-	dev->intr_handle = NULL;
-	rte_intr_instance_free(dev->vfio_req_intr_handle);
-	dev->vfio_req_intr_handle = NULL;
 
  	if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING)
  		/* unmap resources for devices that use igb_uio */

drivers/bus/pci/pci_common.c rte_pci_detach_dev(struct rte_pci_device *dev) · line 337

Quoted 10 lines
drivers/bus/pci/pci_common.c +5 -0
  		rte_pci_unmap_device(dev);
 
+	rte_intr_instance_free(dev->intr_handle);
+	dev->intr_handle = NULL;
+	rte_intr_instance_free(dev->vfio_req_intr_handle);
+	dev->vfio_req_intr_handle = NULL;
+
  	return 0;
  }
 

Thanks,
Maxime

author Tested-by Yan Xia Applied
#2 lore raw
Quoted 8 lines · Maxime Coquelin
Quoted 7 lines · David Marchand

rte_pci_unmap_device() needs intr_handle objects to unregister callbacks.

Bugzilla ID: 845

Fixes d61138d4f0e2 ("drivers: remove direct access to interrupt handle")
Quoted 1 line

Applied, thanks.

Signature · 1 line
David Marchand