From: Florian Westphal <fw@strlen.de>
To: Cong Wang <xiyou.wangcong@gmail.com>
Cc: netdev@vger.kernel.org, netfilter-devel@vger.kernel.org,
pabeni@redhat.com, Eric Dumazet <eric.dumazet@gmail.com>,
Pablo Neira Ayuso <pablo@netfilter.org>
Subject: Re: [Patch net] ipt_CLUSTERIP: fix a refcount bug in clusterip_config_find_get()
Date: Thu, 8 Feb 2018 09:01:30 +0100 [thread overview]
Message-ID: <20180208080130.GJ14261@breakpoint.cc> (raw)
In-Reply-To: <20180208055918.20411-2-xiyou.wangcong@gmail.com>
Cong Wang <xiyou.wangcong@gmail.com> wrote:
> In clusterip_config_find_get() we hold RCU read lock so it could
> run concurrently with clusterip_config_entry_put(), as a result,
> the refcnt could go back to 1 from 0, which leads to a double
> list_del()... Just replace refcount_inc() with
> refcount_inc_not_zero(), as for c->refcount.
>
> Fixes: d73f33b16883 ("netfilter: CLUSTERIP: RCU conversion")
> Cc: Eric Dumazet <eric.dumazet@gmail.com>
> Cc: Pablo Neira Ayuso <pablo@netfilter.org>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
> ---
> net/ipv4/netfilter/ipt_CLUSTERIP.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
> index 1ff72b87a066..4537b1686c7c 100644
> --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
> +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
> @@ -154,8 +154,10 @@ clusterip_config_find_get(struct net *net, __be32 clusterip, int entry)
> #endif
> if (unlikely(!refcount_inc_not_zero(&c->refcount)))
> c = NULL;
> - else if (entry)
> - refcount_inc(&c->entries);
> + else if (entry) {
> + if (unlikely(!refcount_inc_not_zero(&c->entries)))
this needs to call clusterip_config_put(c); too, else we leak one
reference.
Other than that this looks good.
next prev parent reply other threads:[~2018-02-08 8:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-08 5:59 [Patch net] ipt_CLUSTERIP: fix a race condition of proc file creation Cong Wang
2018-02-08 5:59 ` [Patch net] ipt_CLUSTERIP: fix a refcount bug in clusterip_config_find_get() Cong Wang
2018-02-08 8:01 ` Florian Westphal [this message]
2018-02-08 20:05 ` Cong Wang
2018-02-08 11:45 ` [Patch net] ipt_CLUSTERIP: fix a race condition of proc file creation Xin Long
2018-02-08 16:58 ` Pablo Neira Ayuso
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=20180208080130.GJ14261@breakpoint.cc \
--to=fw@strlen.de \
--cc=eric.dumazet@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pablo@netfilter.org \
--cc=xiyou.wangcong@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).