* [PATCHv1] xen-netfront: properly destroy queues when removing device
@ 2015-05-27 14:46 David Vrabel
2015-05-27 15:20 ` Boris Ostrovsky
2015-05-27 18:03 ` David Miller
0 siblings, 2 replies; 3+ messages in thread
From: David Vrabel @ 2015-05-27 14:46 UTC (permalink / raw)
To: netdev; +Cc: David Vrabel, xen-devel, Konrad Rzeszutek Wilk, Boris Ostrovsky
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>
---
drivers/net/xen-netfront.c | 15 ++-------------
1 file changed, 2 insertions(+), 13 deletions(-)
diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index 3f45afd..e031c94 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -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;
--
1.7.10.4
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCHv1] xen-netfront: properly destroy queues when removing device
2015-05-27 14:46 [PATCHv1] xen-netfront: properly destroy queues when removing device David Vrabel
@ 2015-05-27 15:20 ` Boris Ostrovsky
2015-05-27 18:03 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: Boris Ostrovsky @ 2015-05-27 15:20 UTC (permalink / raw)
To: David Vrabel, netdev; +Cc: xen-devel, Konrad Rzeszutek Wilk
On 05/27/2015 10:46 AM, David Vrabel wrote:
> 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>
> ---
> drivers/net/xen-netfront.c | 15 ++-------------
> 1 file changed, 2 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
> index 3f45afd..e031c94 100644
> --- a/drivers/net/xen-netfront.c
> +++ b/drivers/net/xen-netfront.c
> @@ -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;
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCHv1] xen-netfront: properly destroy queues when removing device
2015-05-27 14:46 [PATCHv1] xen-netfront: properly destroy queues when removing device David Vrabel
2015-05-27 15:20 ` Boris Ostrovsky
@ 2015-05-27 18:03 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2015-05-27 18:03 UTC (permalink / raw)
To: david.vrabel; +Cc: netdev, xen-devel, konrad.wilk, boris.ostrovsky
From: David Vrabel <david.vrabel@citrix.com>
Date: Wed, 27 May 2015 15:46:10 +0100
> 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>
Applied, thanks David.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-05-27 18:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-27 14:46 [PATCHv1] xen-netfront: properly destroy queues when removing device David Vrabel
2015-05-27 15:20 ` Boris Ostrovsky
2015-05-27 18:03 ` David Miller
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).