[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1389202287.26646.95.camel@edumazet-glaptop2.roam.corp.google.com>
Date: Wed, 08 Jan 2014 09:31:27 -0800
From: Eric Dumazet <eric.dumazet@...il.com>
To: Florian Westphal <fw@...len.de>
Cc: Andrey Vagin <avagin@...nvz.org>, netfilter-devel@...r.kernel.org,
netfilter@...r.kernel.org, coreteam@...filter.org,
netdev@...r.kernel.org, linux-kernel@...r.kernel.org,
vvs@...nvz.org, Pablo Neira Ayuso <pablo@...filter.org>,
Patrick McHardy <kaber@...sh.net>,
Jozsef Kadlecsik <kadlec@...ckhole.kfki.hu>,
"David S. Miller" <davem@...emloft.net>,
Cyrill Gorcunov <gorcunov@...nvz.org>
Subject: Re: [PATCH] netfilter: nf_conntrack: fix RCU race in
nf_conntrack_find_get
On Wed, 2014-01-08 at 15:04 +0100, Florian Westphal wrote:
> Eric Dumazet <eric.dumazet@...il.com> 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 the hash table.
> > >
> > > The confirmed bit is set right before we insert the conntrack into
> > > the hash table (after we traversed rules, ct is ready to be
> > > 'published').
> > >
> > > i.e. when the confirmed bit is NOT set we should not be 'seeing' the nf_conn
> > > struct when we perform the lookup, as it should still be sitting on the
> > > 'unconfirmed' list, being invisible to readers.
> > >
> > > Does that explanation make sense to you?
> > >
> > > Thanks for looking into this.
> >
> > Still, this patch adds a loop. And maybe an infinite one if confirmed
> > bit is set from an context that was interrupted by this one.
>
> Hmm. There should be at most one retry.
>
> The confirmed bit should always be set here.
So why are you testing it ?
> If it isn't then this conntrack shouldn't be in the hash table, i.e.
> when we re-try we should find the same conntrack again with the bit set.
Where is this guaranteed ? The invariant is the refcnt being taken.
>
> Asuming the other cpu git interrupted after setting confirmed
> bit but before inserting it into the hash table, then our re-try
> should not be able find a matching entry.
>
> Maybe I am missing something, but I don't see how we could (upon
> retry) find the very same entry again with the bit still not set.
>
> > If you need to test the confirmed bit, then you also need to test it
> > before taking the refcount.
>
> I don't think that would make sense, because it should always be
> set (inserting conntrack into hash table without confirmed set is
> illegal, and it is never unset again).
>
> [ when allocating a new conntrack, ct->status is zeroed, which also
> clears the flag. This happens just before we set the new objects
> refcount to 1 ]
I did this RCU conversion, so I think I know what I am talking about.
The entry should not be put into hash table (or refcnt set to 1),
if its not ready. It is that simple.
We need to address this problem without adding an extra test and
possible loop for the lookups.
Whole point of RCU is to make lookups fast, by possibly making the
writers doing all the needed logic.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists