diff mbox

[v2] packet: fix possible dev refcnt leak when bind fail

Message ID CAPgLHd98WPb3ieuka-qT50Va+Fx+YBroF92AfuAmKGW9a8-AKQ@mail.gmail.com
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

Wei Yongjun Dec. 28, 2011, 2:53 a.m. UTC
From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>

If bind is fail when bind is called after set PACKET_FANOUT
sock option, the dev refcnt will leak.

Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
---
 net/packet/af_packet.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

Comments

David Miller Dec. 28, 2011, 3:33 a.m. UTC | #1
From: Wei Yongjun <weiyj.lk@gmail.com>
Date: Wed, 28 Dec 2011 10:53:05 +0800

> From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
> 
> If bind is fail when bind is called after set PACKET_FANOUT
> sock option, the dev refcnt will leak.
> 
> Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>

Applied, thanks a lot.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 3891702..d9d4970 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -2448,8 +2448,12 @@  static int packet_do_bind(struct sock *sk, struct net_device *dev, __be16 protoc
 {
 	struct packet_sock *po = pkt_sk(sk);
 
-	if (po->fanout)
+	if (po->fanout) {
+		if (dev)
+			dev_put(dev);
+
 		return -EINVAL;
+	}
 
 	lock_sock(sk);