aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Westerhoff <lars.westerhoff@newtec.eu>2015-07-27 18:32:21 -0400
committerDavid S. Miller <davem@davemloft.net>2015-07-27 18:38:58 -0400
commit158cd4af8dedbda0d612d448c724c715d0dda649 (patch)
tree6bccf1b8da44cf06707413aed948e81032987c81
parentc5c62f1bb0e1fc94ab77ec01e92ccab5cb249742 (diff)
packet: missing dev_put() in packet_do_bind()
When binding a PF_PACKET socket, the use count of the bound interface is always increased with dev_hold in dev_get_by_{index,name}. However, when rebound with the same protocol and device as in the previous bind the use count of the interface was not decreased. Ultimately, this caused the deletion of the interface to fail with the following message: unregister_netdevice: waiting for dummy0 to become free. Usage count = 1 This patch moves the dev_put out of the conditional part that was only executed when either the protocol or device changed on a bind. Fixes: 902fefb82ef7 ('packet: improve socket create/bind latency in some cases') Signed-off-by: Lars Westerhoff <lars.westerhoff@newtec.eu> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Reviewed-by: Daniel Borkmann <dborkman@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/packet/af_packet.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index c9e8741226c6..c7c42eb617ef 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -2784,7 +2784,7 @@ static int packet_release(struct socket *sock)
2784static int packet_do_bind(struct sock *sk, struct net_device *dev, __be16 proto) 2784static int packet_do_bind(struct sock *sk, struct net_device *dev, __be16 proto)
2785{ 2785{
2786 struct packet_sock *po = pkt_sk(sk); 2786 struct packet_sock *po = pkt_sk(sk);
2787 const struct net_device *dev_curr; 2787 struct net_device *dev_curr;
2788 __be16 proto_curr; 2788 __be16 proto_curr;
2789 bool need_rehook; 2789 bool need_rehook;
2790 2790
@@ -2808,15 +2808,13 @@ static int packet_do_bind(struct sock *sk, struct net_device *dev, __be16 proto)
2808 2808
2809 po->num = proto; 2809 po->num = proto;
2810 po->prot_hook.type = proto; 2810 po->prot_hook.type = proto;
2811
2812 if (po->prot_hook.dev)
2813 dev_put(po->prot_hook.dev);
2814
2815 po->prot_hook.dev = dev; 2811 po->prot_hook.dev = dev;
2816 2812
2817 po->ifindex = dev ? dev->ifindex : 0; 2813 po->ifindex = dev ? dev->ifindex : 0;
2818 packet_cached_dev_assign(po, dev); 2814 packet_cached_dev_assign(po, dev);
2819 } 2815 }
2816 if (dev_curr)
2817 dev_put(dev_curr);
2820 2818
2821 if (proto == 0 || !need_rehook) 2819 if (proto == 0 || !need_rehook)
2822 goto out_unlock; 2820 goto out_unlock;