Re: [PATCH] netfilter: nf_conntrack: fix RCU race in nf_conntrack_find_get (v3)

2014-01-29 Thread Pablo Neira Ayuso
On Sun, Jan 12, 2014 at 12:21:14PM -0800, Eric Dumazet wrote: > On Sun, 2014-01-12 at 21:50 +0400, Andrey Vagin wrote: > > Lets look at destroy_conntrack: > > > > hlist_nulls_del_rcu(&ct->tuplehash[IP_CT_DIR_ORIGINAL].hnnode); > > ... > > nf_conntrack_free(ct) > > kmem_cache_free(net->ct.nf_co

Re: [PATCH] netfilter: nf_conntrack: fix RCU race in nf_conntrack_find_get (v3)

2014-01-14 Thread Eric Dumazet
On Tue, 2014-01-14 at 14:51 +0400, Andrew Vagin wrote: > I think __nf_conntrack_alloc must use atomic_inc instead of > atomic_set. And we must be sure, that the first object from a new page is > zeroized. No you can not do that, and we do not need. If a new page is allocated, then you have the g

Re: [PATCH] netfilter: nf_conntrack: fix RCU race in nf_conntrack_find_get (v3)

2014-01-14 Thread Andrey Wagin
> > Eh, looks like this path is incomplete too:( > > I think we can't set a reference counter for objects which is allocated > from a SLAB_DESTROY_BY_RCU cache. Look at the following backtrace. > > cpu1cpu2 > ct = nf_conntrack_find() >

Re: [PATCH] netfilter: nf_conntrack: fix RCU race in nf_conntrack_find_get (v3)

2014-01-14 Thread Andrew Vagin
On Sun, Jan 12, 2014 at 12:21:14PM -0800, Eric Dumazet wrote: > On Sun, 2014-01-12 at 21:50 +0400, Andrey Vagin wrote: > > Lets look at destroy_conntrack: > > > > hlist_nulls_del_rcu(&ct->tuplehash[IP_CT_DIR_ORIGINAL].hnnode); > > ... > > nf_conntrack_free(ct) > > kmem_cache_free(net->ct.nf_co

Re: [PATCH] netfilter: nf_conntrack: fix RCU race in nf_conntrack_find_get (v3)

2014-01-12 Thread Eric Dumazet
On Sun, 2014-01-12 at 21:50 +0400, Andrey Vagin wrote: > Lets look at destroy_conntrack: > > hlist_nulls_del_rcu(&ct->tuplehash[IP_CT_DIR_ORIGINAL].hnnode); > ... > nf_conntrack_free(ct) > kmem_cache_free(net->ct.nf_conntrack_cachep, ct); > > net->ct.nf_conntrack_cachep is created with SLAB

[PATCH] netfilter: nf_conntrack: fix RCU race in nf_conntrack_find_get (v3)

2014-01-12 Thread Andrey Vagin
Lets look at destroy_conntrack: hlist_nulls_del_rcu(&ct->tuplehash[IP_CT_DIR_ORIGINAL].hnnode); ... nf_conntrack_free(ct) kmem_cache_free(net->ct.nf_conntrack_cachep, ct); net->ct.nf_conntrack_cachep is created with SLAB_DESTROY_BY_RCU. The hash is protected by rcu, so readers look up co

Re: [PATCH] netfilter: nf_conntrack: fix RCU race in nf_conntrack_find_get

2014-01-09 Thread Andrey Wagin
2014/1/9 Eric Dumazet : > On Thu, 2014-01-09 at 09:24 +0400, Andrew Vagin wrote: > >> I have one more question. Looks like I found another problem. >> >> init_conntrack: >> hlist_nulls_add_head_rcu(&ct->tuplehash[IP_CT_DIR_ORIGINAL].hnnode, >> &net->ct.unconfirmed); >>

Re: [PATCH] netfilter: nf_conntrack: fix RCU race in nf_conntrack_find_get

2014-01-09 Thread Florian Westphal
Andrew Vagin wrote: > On Thu, Jan 09, 2014 at 09:56:22PM +0100, Florian Westphal wrote: > > Andrew Vagin wrote: > > > Can we allocate conntrack with zero ct_general.use and increment it at > > > the first time before inserting the conntrack into the hash table? > > > When conntrack is allocated i

Re: [PATCH] netfilter: nf_conntrack: fix RCU race in nf_conntrack_find_get

2014-01-09 Thread Andrew Vagin
On Thu, Jan 09, 2014 at 09:56:22PM +0100, Florian Westphal wrote: > Andrew Vagin wrote: > > Can we allocate conntrack with zero ct_general.use and increment it at > > the first time before inserting the conntrack into the hash table? > > When conntrack is allocated it is attached exclusively to on

Re: [PATCH] netfilter: nf_conntrack: fix RCU race in nf_conntrack_find_get

2014-01-09 Thread Florian Westphal
Andrew Vagin wrote: > Can we allocate conntrack with zero ct_general.use and increment it at > the first time before inserting the conntrack into the hash table? > When conntrack is allocated it is attached exclusively to one skb. > It must be destroyed with skb, if it has not been confirmed, so w

Re: [PATCH] netfilter: nf_conntrack: fix RCU race in nf_conntrack_find_get

2014-01-09 Thread Andrew Vagin
On Tue, Jan 07, 2014 at 04:25:20PM +0100, Florian Westphal wrote: > Eric Dumazet wrote: > > > diff --git a/net/netfilter/nf_conntrack_core.c > > > b/net/netfilter/nf_conntrack_core.c > > > index 43549eb..7a34bb2 100644 > > > --- a/net/netfilter/nf_conntrack_core.c > > > +++ b/net/netfilter/nf_con

Re: [PATCH] netfilter: nf_conntrack: fix RCU race in nf_conntrack_find_get

2014-01-09 Thread Eric Dumazet
On Thu, 2014-01-09 at 09:24 +0400, Andrew Vagin wrote: > I have one more question. Looks like I found another problem. > > init_conntrack: > hlist_nulls_add_head_rcu(&ct->tuplehash[IP_CT_DIR_ORIGINAL].hnnode, > &net->ct.unconfirmed); > > __nf_conntrack_hash_insert:

Re: [PATCH] netfilter: nf_conntrack: fix RCU race in nf_conntrack_find_get

2014-01-08 Thread Andrew Vagin
On Tue, Jan 07, 2014 at 07:08:25AM -0800, Eric Dumazet wrote: > On Tue, 2014-01-07 at 14:31 +0400, Andrey Vagin wrote: > > Lets look at destroy_conntrack: > > > > hlist_nulls_del_rcu(&ct->tuplehash[IP_CT_DIR_ORIGINAL].hnnode); > > ... > > nf_conntrack_free(ct) > > kmem_cache_free(net->ct.nf_co

Re: [PATCH] netfilter: nf_conntrack: fix RCU race in nf_conntrack_find_get

2014-01-08 Thread Florian Westphal
Florian Westphal wrote: > Eric Dumazet wrote: > > > The confirmed bit should always be set here. > > > > So why are you testing it ? > > To detect ct object recycling when tuple is identical. > > This is my understanding of how we can end up with two > cpus thinking they have exclusive ownersh

Re: [PATCH] netfilter: nf_conntrack: fix RCU race in nf_conntrack_find_get

2014-01-08 Thread Florian Westphal
Eric Dumazet wrote: > > The confirmed bit should always be set here. > > So why are you testing it ? To detect ct object recycling when tuple is identical. This is my understanding of how we can end up with two cpus thinking they have exclusive ownership of the same ct: A cpu0: starts lookup:

Re: [PATCH] netfilter: nf_conntrack: fix RCU race in nf_conntrack_find_get

2014-01-08 Thread Eric Dumazet
On Wed, 2014-01-08 at 15:04 +0100, Florian Westphal wrote: > Eric Dumazet wrote: > > > This will also set up a null-binding when no matching SNAT/DNAT/MASQERUADE > > > rule existed. > > > > > > The manipulations of the skb->nfct->ext nat area are performed without > > > a lock. Concurrent access

Re: [PATCH] netfilter: nf_conntrack: fix RCU race in nf_conntrack_find_get

2014-01-08 Thread Florian Westphal
Eric Dumazet wrote: > > This will also set up a null-binding when no matching SNAT/DNAT/MASQERUADE > > rule existed. > > > > The manipulations of the skb->nfct->ext nat area are performed without > > a lock. Concurrent access is supposedly impossible as the conntrack > > should not (yet) be in t

Re: [PATCH] netfilter: nf_conntrack: fix RCU race in nf_conntrack_find_get (v2)

2014-01-08 Thread Eric Dumazet
On Wed, 2014-01-08 at 17:17 +0400, Andrey Vagin wrote: > Lets look at destroy_conntrack: > > hlist_nulls_del_rcu(&ct->tuplehash[IP_CT_DIR_ORIGINAL].hnnode); > ... > nf_conntrack_free(ct) > kmem_cache_free(net->ct.nf_conntrack_cachep, ct); > > net->ct.nf_conntrack_cachep is created with SLAB

Re: [PATCH] netfilter: nf_conntrack: fix RCU race in nf_conntrack_find_get

2014-01-08 Thread Eric Dumazet
On Tue, 2014-01-07 at 16:25 +0100, Florian Westphal wrote: > Eric Dumazet wrote: > > > diff --git a/net/netfilter/nf_conntrack_core.c > > > b/net/netfilter/nf_conntrack_core.c > > > index 43549eb..7a34bb2 100644 > > > --- a/net/netfilter/nf_conntrack_core.c > > > +++ b/net/netfilter/nf_conntrack_

[PATCH] netfilter: nf_conntrack: fix RCU race in nf_conntrack_find_get (v2)

2014-01-08 Thread Andrey Vagin
Lets look at destroy_conntrack: hlist_nulls_del_rcu(&ct->tuplehash[IP_CT_DIR_ORIGINAL].hnnode); ... nf_conntrack_free(ct) kmem_cache_free(net->ct.nf_conntrack_cachep, ct); net->ct.nf_conntrack_cachep is created with SLAB_DESTROY_BY_RCU. The hash is protected by rcu, so readers look up co

Re: [PATCH] netfilter: nf_conntrack: fix RCU race in nf_conntrack_find_get

2014-01-07 Thread Florian Westphal
Eric Dumazet wrote: > > diff --git a/net/netfilter/nf_conntrack_core.c > > b/net/netfilter/nf_conntrack_core.c > > index 43549eb..7a34bb2 100644 > > --- a/net/netfilter/nf_conntrack_core.c > > +++ b/net/netfilter/nf_conntrack_core.c > > @@ -387,8 +387,12 @@ begin: > > !at

Re: [PATCH] netfilter: nf_conntrack: fix RCU race in nf_conntrack_find_get

2014-01-07 Thread Eric Dumazet
On Tue, 2014-01-07 at 14:31 +0400, Andrey Vagin wrote: > Lets look at destroy_conntrack: > > hlist_nulls_del_rcu(&ct->tuplehash[IP_CT_DIR_ORIGINAL].hnnode); > ... > nf_conntrack_free(ct) > kmem_cache_free(net->ct.nf_conntrack_cachep, ct); > > net->ct.nf_conntrack_cachep is created with SLAB

Re: [PATCH] netfilter: nf_conntrack: fix RCU race in nf_conntrack_find_get

2014-01-07 Thread Vasily Averin
On 01/07/2014 02:31 PM, Andrey Vagin wrote: > Lets look at destroy_conntrack: > > hlist_nulls_del_rcu(&ct->tuplehash[IP_CT_DIR_ORIGINAL].hnnode); > ... > nf_conntrack_free(ct) > kmem_cache_free(net->ct.nf_conntrack_cachep, ct); > > net->ct.nf_conntrack_cachep is created with SLAB_DESTROY_BY

[PATCH] netfilter: nf_conntrack: fix RCU race in nf_conntrack_find_get

2014-01-07 Thread Andrey Vagin
Lets look at destroy_conntrack: hlist_nulls_del_rcu(&ct->tuplehash[IP_CT_DIR_ORIGINAL].hnnode); ... nf_conntrack_free(ct) kmem_cache_free(net->ct.nf_conntrack_cachep, ct); net->ct.nf_conntrack_cachep is created with SLAB_DESTROY_BY_RCU. The hash is protected by rcu, so readers look up co