From: Wei Yongjun <weiyj.lk@gmail.com>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org
Subject: [PATCH] packet: fix dev refcnt leak when bind fail
Date: Mon, 26 Dec 2011 17:02:59 +0800 [thread overview]
Message-ID: <CAPgLHd9KNN81cPYv3bGzoBwUtnJSAoX4NN0Fh+wNgoHE_t7d=w@mail.gmail.com> (raw)
From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
If bind is fail such as 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 | 7 ++++++-
1 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 3891702..b6ac234 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -2501,8 +2501,11 @@ static int packet_bind_spkt(struct socket *sock, struct sockaddr *uaddr,
strlcpy(name, uaddr->sa_data, sizeof(name));
dev = dev_get_by_name(sock_net(sk), name);
- if (dev)
+ if (dev) {
err = packet_do_bind(sk, dev, pkt_sk(sk)->num);
+ if (err)
+ dev_put(dev);
+ }
return err;
}
@@ -2530,6 +2533,8 @@ static int packet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len
goto out;
}
err = packet_do_bind(sk, dev, sll->sll_protocol ? : pkt_sk(sk)->num);
+ if (err && dev)
+ dev_put(dev);
out:
return err;
--
1.7.7
next reply other threads:[~2011-12-26 9:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-26 9:02 Wei Yongjun [this message]
2011-12-26 20:15 ` [PATCH] packet: fix dev refcnt leak when bind fail David Miller
[not found] ` <CAPgLHd8ZX6eh+SOoE7CXJXTAsq3F8biQYSKcN-owfj_jBsZ_tg@mail.gmail.com>
2011-12-27 4:28 ` Fwd: " Wei Yongjun
2011-12-27 18:15 ` David Miller
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='CAPgLHd9KNN81cPYv3bGzoBwUtnJSAoX4NN0Fh+wNgoHE_t7d=w@mail.gmail.com' \
--to=weiyj.lk@gmail.com \
--cc=davem@davemloft.net \
--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).