Skip to content

Commit ad06811

Browse files
David Vrabeldavem330
David Vrabel
authored andcommitted
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. Signed-off-by: David Vrabel <david.vrabel@citrix.com> Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f4ecf29 commit ad06811

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

drivers/net/xen-netfront.c

+2-13
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,7 @@ static void xennet_destroy_queues(struct netfront_info *info)
16981698

16991699
if (netif_running(info->netdev))
17001700
napi_disable(&queue->napi);
1701+
del_timer_sync(&queue->rx_refill_timer);
17011702
netif_napi_del(&queue->napi);
17021703
}
17031704

@@ -2102,26 +2103,14 @@ static const struct attribute_group xennet_dev_group = {
21022103
static int xennet_remove(struct xenbus_device *dev)
21032104
{
21042105
struct netfront_info *info = dev_get_drvdata(&dev->dev);
2105-
unsigned int num_queues = info->netdev->real_num_tx_queues;
2106-
struct netfront_queue *queue = NULL;
2107-
unsigned int i = 0;
21082106

21092107
dev_dbg(&dev->dev, "%s\n", dev->nodename);
21102108

21112109
xennet_disconnect_backend(info);
21122110

21132111
unregister_netdev(info->netdev);
21142112

2115-
for (i = 0; i < num_queues; ++i) {
2116-
queue = &info->queues[i];
2117-
del_timer_sync(&queue->rx_refill_timer);
2118-
}
2119-
2120-
if (num_queues) {
2121-
kfree(info->queues);
2122-
info->queues = NULL;
2123-
}
2124-
2113+
xennet_destroy_queues(info);
21252114
xennet_free_netdev(info->netdev);
21262115

21272116
return 0;

0 commit comments

Comments
 (0)