Skip to contentSkip to conversation

xen-netfront: properly destroy queues when removing device

PATCH Applied David Vrabel 3 participants 5 messages May 27, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen-netfront: properly destroy queues when removing device

xennet_remove() freed the queues before freeing the netdevice which results in a use-after-free when free_netdev() tries to delete the napi instances that have already been freed.

Fix this by fully destroy the queues (which includes deleting the napi instances) before freeing the netdevice.

---
 drivers/net/xen-netfront.c |   15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)
drivers/net/xen-netfront.c +2 -13
index 3f45afd..e031c94 100644
@@ -1698,6 +1698,7 @@ static void xennet_destroy_queues(struct netfront_info *info)
 
 		if (netif_running(info->netdev))
 			napi_disable(&queue->napi);
+		del_timer_sync(&queue->rx_refill_timer);
 		netif_napi_del(&queue->napi);
 	}
 
@@ -2102,9 +2103,6 @@ static const struct attribute_group xennet_dev_group = {
 static int xennet_remove(struct xenbus_device *dev)
 {
 	struct netfront_info *info = dev_get_drvdata(&dev->dev);
-	unsigned int num_queues = info->netdev->real_num_tx_queues;
-	struct netfront_queue *queue = NULL;
-	unsigned int i = 0;
 
 	dev_dbg(&dev->dev, "%s\n", dev->nodename);
 
@@ -2112,16 +2110,7 @@ static int xennet_remove(struct xenbus_device *dev)
 
 	unregister_netdev(info->netdev);
 
-	for (i = 0; i < num_queues; ++i) {
-		queue = &info->queues[i];
-		del_timer_sync(&queue->rx_refill_timer);
-	}
-
-	if (num_queues) {
-		kfree(info->queues);
-		info->queues = NULL;
-	}
-
+	xennet_destroy_queues(info);
 	xennet_free_netdev(info->netdev);
 
 	return 0;
Signature · 1 line
1.7.10.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · David Vrabel

xennet_remove() freed the queues before freeing the netdevice which results in a use-after-free when free_netdev() tries to delete the napi instances that have already been freed.

Fix this by fully destroy the queues (which includes deleting the napi instances) before freeing the netdevice.

Quoted 44 lines
---
  drivers/net/xen-netfront.c |   15 ++-------------
  1 file changed, 2 insertions(+), 13 deletions(-)
drivers/net/xen-netfront.c +2 -13
index 3f45afd..e031c94 100644
@@ -1698,6 +1698,7 @@ static void xennet_destroy_queues(struct netfront_info *info)
 
  		if (netif_running(info->netdev))
  			napi_disable(&queue->napi);
+		del_timer_sync(&queue->rx_refill_timer);
  		netif_napi_del(&queue->napi);
  	}
 
@@ -2102,9 +2103,6 @@ static const struct attribute_group xennet_dev_group = {
  static int xennet_remove(struct xenbus_device *dev)
  {
  	struct netfront_info *info = dev_get_drvdata(&dev->dev);
-	unsigned int num_queues = info->netdev->real_num_tx_queues;
-	struct netfront_queue *queue = NULL;
-	unsigned int i = 0;
 
  	dev_dbg(&dev->dev, "%s\n", dev->nodename);
 
@@ -2112,16 +2110,7 @@ static int xennet_remove(struct xenbus_device *dev)
 
  	unregister_netdev(info->netdev);
 
-	for (i = 0; i < num_queues; ++i) {
-		queue = &info->queues[i];
-		del_timer_sync(&queue->rx_refill_timer);
-	}
-
-	if (num_queues) {
-		kfree(info->queues);
-		info->queues = NULL;
-	}
-
+	xennet_destroy_queues(info);
  	xennet_free_netdev(info->netdev);
 
  	return 0;
Reviewed-by on v1 1/1
#2 lore raw
In reply to David Vrabel
Quoted 8 lines · David Vrabel

xennet_remove() freed the queues before freeing the netdevice which results in a use-after-free when free_netdev() tries to delete the napi instances that have already been freed.

Fix this by fully destroy the queues (which includes deleting the napi instances) before freeing the netdevice.

Quoted 44 lines
---
  drivers/net/xen-netfront.c |   15 ++-------------
  1 file changed, 2 insertions(+), 13 deletions(-)
drivers/net/xen-netfront.c +2 -13
index 3f45afd..e031c94 100644
@@ -1698,6 +1698,7 @@ static void xennet_destroy_queues(struct netfront_info *info)
 
  		if (netif_running(info->netdev))
  			napi_disable(&queue->napi);
+		del_timer_sync(&queue->rx_refill_timer);
  		netif_napi_del(&queue->napi);
  	}
 
@@ -2102,9 +2103,6 @@ static const struct attribute_group xennet_dev_group = {
  static int xennet_remove(struct xenbus_device *dev)
  {
  	struct netfront_info *info = dev_get_drvdata(&dev->dev);
-	unsigned int num_queues = info->netdev->real_num_tx_queues;
-	struct netfront_queue *queue = NULL;
-	unsigned int i = 0;
 
  	dev_dbg(&dev->dev, "%s\n", dev->nodename);
 
@@ -2112,16 +2110,7 @@ static int xennet_remove(struct xenbus_device *dev)
 
  	unregister_netdev(info->netdev);
 
-	for (i = 0; i < num_queues; ++i) {
-		queue = &info->queues[i];
-		del_timer_sync(&queue->rx_refill_timer);
-	}
-
-	if (num_queues) {
-		kfree(info->queues);
-		info->queues = NULL;
-	}
-
+	xennet_destroy_queues(info);
  	xennet_free_netdev(info->netdev);
 
  	return 0;
maintainer Applied
#3 lore raw
In reply to David Vrabel

From: David Vrabel <[email protected]>
Date: Wed, 27 May 2015 15:46:10 +0100

Quoted 8 lines

xennet_remove() freed the queues before freeing the netdevice which results in a use-after-free when free_netdev() tries to delete the napi instances that have already been freed.

Fix this by fully destroy the queues (which includes deleting the napi instances) before freeing the netdevice.

Applied, thanks David.

maintainer Applied
#4 lore raw
In reply to David Vrabel

From: David Vrabel <[email protected]>
Date: Wed, 27 May 2015 15:46:10 +0100

Quoted 8 lines

xennet_remove() freed the queues before freeing the netdevice which results in a use-after-free when free_netdev() tries to delete the napi instances that have already been freed.

Fix this by fully destroy the queues (which includes deleting the napi instances) before freeing the netdevice.

Applied, thanks David.