Commit 158cd4af authored by Lars Westerhoff's avatar Lars Westerhoff Committed by David S. Miller
Browse files

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: 902fefb8

 ('packet: improve socket create/bind latency in some cases')
Signed-off-by: default avatarLars Westerhoff <>
Signed-off-by: default avatarDan Carpenter <>
Reviewed-by: default avatarDaniel Borkmann <>
Signed-off-by: default avatarDavid S. Miller <>
parent c5c62f1b
......@@ -2784,7 +2784,7 @@ static int packet_release(struct socket *sock)
static int packet_do_bind(struct sock *sk, struct net_device *dev, __be16 proto)
struct packet_sock *po = pkt_sk(sk);
const struct net_device *dev_curr;
struct net_device *dev_curr;
__be16 proto_curr;
bool need_rehook;
......@@ -2808,15 +2808,13 @@ static int packet_do_bind(struct sock *sk, struct net_device *dev, __be16 proto)
po->num = proto;
po->prot_hook.type = proto;
if (po->
po-> = dev;
po->ifindex = dev ? dev->ifindex : 0;
packet_cached_dev_assign(po, dev);
if (dev_curr)
if (proto == 0 || !need_rehook)
goto out_unlock;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment