From: David Miller <davem@davemloft.net>
To: weiyj.lk@gmail.com
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH] packet: fix dev refcnt leak when bind fail
Date: Tue, 27 Dec 2011 13:15:59 -0500 (EST) [thread overview]
Message-ID: <20111227.131559.2197088758418537543.davem@davemloft.net> (raw)
In-Reply-To: <CAPgLHd9DPsxBnhH_xvuApjy32X--jxYiDn4DmxmR-Uqq8wJP+A@mail.gmail.com>
From: Wei Yongjun <weiyj.lk@gmail.com>
Date: Tue, 27 Dec 2011 12:28:31 +0800
> cc netdev@vger.kernel.org
>
>> From: Wei Yongjun <weiyj.lk@gmail.com>
>> Date: Mon, 26 Dec 2011 17:02:59 +0800
>>
>>> 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>
>>
>> The device pointer is stored in ->prot_hook.dev
>>
>> Therefore, it will be released at the latest in packet_release() or
>> earlier if another bind() attempt is done on the socket.
>>
>> There is no leak here as far as I can see.
>
> Hi David,
>
> In packet_do_bind(), if po->fanout is set, the device pointer may not be
> stored in ->prot_hook.dev, see the following code:
>
> static int packet_do_bind(struct sock *sk, struct net_device *dev, ...)
> {
> struct packet_sock *po = pkt_sk(sk);
>
> if (po->fanout)
> return -EINVAL;
> ...
> po->prot_hook.dev = dev;
> ...
> }
>
> The leak is exists only if po->fanout is set.
Then it sounds a lot simpler for packet_do_bind() (one location) to
manage this reference drop, rather than every single call site of
packet_do_bind().
Look how complicated you had to make the tests in those call sites
to get the logic right, it's must easier to just add the dev_put()
right at that po->fanout test.
prev parent reply other threads:[~2011-12-27 18:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-26 9:02 [PATCH] packet: fix dev refcnt leak when bind fail Wei Yongjun
2011-12-26 20:15 ` 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 [this message]
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=20111227.131559.2197088758418537543.davem@davemloft.net \
--to=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=weiyj.lk@gmail.com \
/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).