Skip to content

Commit 114f0c6

Browse files
herbertxgregkh
authored andcommitted
macvlan: Fix device ref leak when purging bc_queue
[ Upstream commit f6478218e6edc2a587b8f132f66373baa7b2497c ] 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> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent bdeb026 commit 114f0c6

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

drivers/net/macvlan.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,7 @@ static int macvlan_port_create(struct net_device *dev)
11101110
static void macvlan_port_destroy(struct net_device *dev)
11111111
{
11121112
struct macvlan_port *port = macvlan_port_get_rtnl(dev);
1113+
struct sk_buff *skb;
11131114

11141115
dev->priv_flags &= ~IFF_MACVLAN_PORT;
11151116
netdev_rx_handler_unregister(dev);
@@ -1118,7 +1119,15 @@ static void macvlan_port_destroy(struct net_device *dev)
11181119
* but we need to cancel it and purge left skbs if any.
11191120
*/
11201121
cancel_work_sync(&port->bc_work);
1121-
__skb_queue_purge(&port->bc_queue);
1122+
1123+
while ((skb = __skb_dequeue(&port->bc_queue))) {
1124+
const struct macvlan_dev *src = MACVLAN_SKB_CB(skb)->src;
1125+
1126+
if (src)
1127+
dev_put(src->dev);
1128+
1129+
kfree_skb(skb);
1130+
}
11221131

11231132
kfree_rcu(port, rcu);
11241133
}

0 commit comments

Comments
 (0)