netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: <Joe.Ghalam@dell.com>
To: <herbert@gondor.apana.org.au>
Cc: <davem@davemloft.net>, <Clifford.Wichmann@dell.com>,
	<netdev@vger.kernel.org>
Subject: Re: macvlan: Fix device ref leak when purging bc_queue
Date: Thu, 20 Apr 2017 16:09:56 +0000	[thread overview]
Message-ID: <1492704599476.84165@Dell.com> (raw)
In-Reply-To: <20170420125512.GA9113@gondor.apana.org.au>

Hi Herbert,
I agree with this change, but the same purge would be needed for the macvlan_dellink() call also. 
Thanks,
Joe

________________________________________
From: Herbert Xu <herbert@gondor.apana.org.au>
Sent: Thursday, April 20, 2017 5:55 AM
To: Ghalam, Joe
Cc: davem@davemloft.net; Wichmann, Clifford; netdev@vger.kernel.org
Subject: macvlan: Fix device ref leak when purging bc_queue

When a parent macvlan device is destroyed we end up purging its
broadcast queue without dropping the device reference count on
the packet source device.  This causes the source device to linger.

This patch drops that reference count.

Fixes: 260916dfb48c ("macvlan: Fix potential use-after free for...")
Reported-by: Joe Ghalam <Joe.Ghalam@dell.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
index 9261722..b34eaaa 100644
--- a/drivers/net/macvlan.c
+++ b/drivers/net/macvlan.c
@@ -1139,6 +1139,7 @@ static int macvlan_port_create(struct net_device *dev)
 static void macvlan_port_destroy(struct net_device *dev)
 {
        struct macvlan_port *port = macvlan_port_get_rtnl(dev);
+       struct sk_buff *skb;

        dev->priv_flags &= ~IFF_MACVLAN_PORT;
        netdev_rx_handler_unregister(dev);
@@ -1147,7 +1148,15 @@ static void macvlan_port_destroy(struct net_device *dev)
         * but we need to cancel it and purge left skbs if any.
         */
        cancel_work_sync(&port->bc_work);
-       __skb_queue_purge(&port->bc_queue);
+
+       while ((skb = __skb_dequeue(&port->bc_queue))) {
+               const struct macvlan_dev *src = MACVLAN_SKB_CB(skb)->src;
+
+               if (src)
+                       dev_put(src->dev);
+
+               kfree_skb(skb);
+       }

        kfree(port);
 }
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

  reply	other threads:[~2017-04-20 16:23 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1492618528011.11322@Dell.com>
2017-04-20 12:55 ` macvlan: Fix device ref leak when purging bc_queue Herbert Xu
2017-04-20 16:09   ` Joe.Ghalam [this message]
2017-04-21  4:40     ` Herbert Xu
2017-04-21 14:40       ` Joe.Ghalam
2017-04-21 15:02         ` David Miller
2017-04-21 19:23         ` Mahesh Bandewar (महेश बंडेवार)
2017-04-21 20:37           ` Joe.Ghalam
2017-04-24  7:56         ` Herbert Xu
2017-04-24 15:01           ` Joe.Ghalam
2017-04-24 15:10             ` David Miller
2017-04-24 15:30               ` Joe.Ghalam
2017-04-25 14:42   ` David Miller
2017-04-25 15:19     ` Joe.Ghalam

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1492704599476.84165@Dell.com \
    --to=joe.ghalam@dell.com \
    --cc=Clifford.Wichmann@dell.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).