netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick McHardy <kaber@trash.net>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Pablo Neira Ayuso <pablo@netfilter.org>,
	netfilter-devel@vger.kernel.org,
	Stephen Hemminger <shemminger@vyatta.com>
Subject: Re: [PATCH] netfilter: ctnetlink: fix (really) race condition between dump_table and destroy
Date: Mon, 24 Jan 2011 18:53:24 +0100	[thread overview]
Message-ID: <4D3DBC94.3090505@trash.net> (raw)
In-Reply-To: <1295877971.2755.30.camel@edumazet-laptop>

Am 24.01.2011 15:06, schrieb Eric Dumazet:
> Le lundi 24 janvier 2011 à 14:37 +0100, Patrick McHardy a écrit :
>> On 24.01.2011 14:25, Pablo Neira Ayuso wrote:
>>> On 24/01/11 14:12, Eric Dumazet wrote:
>>>> Le lundi 24 janvier 2011 à 14:06 +0100, Pablo Neira Ayuso a écrit :
>>>>
>>>>> Yes, we can use nf_conntrack_get (which does atomic_inc) instead. New
>>>>> patch attached.
>>>>
>>>> I feel now a bit uncomfortable, sorry ;)
>>>>
>>>> Are we sure the refcount cannot reach 0 while we hold
>>>> nf_conntrack_lock ?
>>>
>>> the ct deletion from the hash list is protected by spin lock, so
>>> whatever deletion would wait until we have left the dump section.
>>>
>>> with this patch, the code looks like it was in 2.6.24 before the rcu stuff.
>>
>> Yeah, we definitely have a reference while the conntrack is contained
>> in the hash table, and removal requires taking nf_conntrack_lock,
>> therefor using the conntrack entry while holding the lock is valid.
> 
> Yes, but to clarify my question, is the following possible ?
> 
> CPU 0                                           CPU1
> dump()
> spin_lock()
> ....
>     if (not enough room in skb)
> 						decrement last refcount
>       increment_ref_count()
> spin_unlock();
> 						since refcount hit 0,
> 						spin_lock(nf_conntrack)
> 						remove ct from hashes
> 

No, that can't happen. Before the last refcount is released, the entry
is removed from the hash, which requires to take the lock. Each entry
contained in the hash table has a refcount of at least 1.

If there are no futher concerns, I'm going to apply Pablo's patch.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2011-01-24 17:53 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-23 23:16 [PATCH] netfilter: ctnetlink: fix (really) race condition between dump_table and destroy Pablo Neira Ayuso
2011-01-24  6:41 ` Eric Dumazet
2011-01-24  7:04   ` Eric Dumazet
2011-01-24 11:57   ` Pablo Neira Ayuso
2011-01-24 12:46     ` Patrick McHardy
2011-01-24 12:54       ` Eric Dumazet
2011-01-24 13:06         ` Pablo Neira Ayuso
2011-01-24 13:12           ` Eric Dumazet
2011-01-24 13:25             ` Pablo Neira Ayuso
2011-01-24 13:37               ` Patrick McHardy
2011-01-24 14:06                 ` Eric Dumazet
2011-01-24 17:53                   ` Patrick McHardy [this message]
2011-01-24 18:01                     ` Eric Dumazet
2011-01-24 18:16                       ` Patrick McHardy
2011-02-20 20:48 ` Stephen Hemminger
2011-02-20 20:51   ` [PATCH 1/2] netfilter: fix race in conntrack " Stephen Hemminger
2011-02-20 20:51   ` [PATCH 2/2] netfilter: ctnetlink: fix missing refcount increment during dumps Stephen Hemminger

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=4D3DBC94.3090505@trash.net \
    --to=kaber@trash.net \
    --cc=eric.dumazet@gmail.com \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    --cc=shemminger@vyatta.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).