From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Phil Sutter <phil@nwl.cc>, netfilter-devel@vger.kernel.org
Subject: Re: [nft PATCH] libnftables: Fix for multiple context instances
Date: Wed, 22 Nov 2017 19:18:46 +0100 [thread overview]
Message-ID: <20171122181845.GA17189@salvia> (raw)
In-Reply-To: <20171122174943.GA32305@orbyte.nwl.cc>
Hi Phil,
On Wed, Nov 22, 2017 at 06:49:43PM +0100, Phil Sutter wrote:
> On Mon, Nov 20, 2017 at 05:53:13PM +0100, Pablo Neira Ayuso wrote:
> > On Mon, Nov 20, 2017 at 04:58:22PM +0100, Phil Sutter wrote:
> > > On Mon, Nov 20, 2017 at 02:07:32PM +0100, Pablo Neira Ayuso wrote:
> > > > On Mon, Nov 20, 2017 at 01:54:18PM +0100, Phil Sutter wrote:
> > > > > On Mon, Nov 20, 2017 at 01:37:26PM +0100, Pablo Neira Ayuso wrote:
> > > > > > On Thu, Nov 16, 2017 at 08:10:24PM +0100, Phil Sutter wrote:
> > > > > > > If a second context is created, the second call to nft_ctx_free() leads
> > > > > > > to freeing invalid pointers in nft_exit(). Fix this by introducing a
> > > > > > > reference counter so that neither nft_init() nor nft_exit() run more
> > > > > > > than once in a row.
> > > > > > >
> > > > > > > This reference counter has to be protected from parallel access. Do this
> > > > > > > using a mutex in a way that once nft_init() returns, the first call to
> > > > > > > that function running in parallel is guaranteed to be finished -
> > > > > > > otherwise it could happen that things being initialized in one thread
> > > > > > > are already accessed in another one.
> > > > > >
> > > > > > I would prefer this table is placed into the context object, so they
> > > > > > are not global anymore. So I would prefer we fix this the right way(tm).
> > > > > >
> > > > > > Let me know your thoughts, thanks!
> > > > >
> > > > > I don't think that's feasible: Looking at 'mark_tbl' for instance, this is
> > > > > accessed from callbacks in 'mark_type', so we would have to make nft_ctx
> > > > > accessible by all functions dealing with datatypes.
> > > >
> > > > Probably some specific new context object that wrap access to these
> > > > tables, not necessarily nft_ctx.
> > > >
> > > > It's just more code, it will not be a small patch, but I don't see any
> > > > reason this can't be done.
> > >
> > > Yes, this is my guess as well. Though for what benefit? I don't think
> > > having this logic for global run-time data is bad per se. What is it
> > > that you don't like about it?
> >
> > This is breaking the assumption that releasing the context object will
> > be clearing all state behind us.
>
> Hmm. Does that matter here? I don't think it makes sense to make the
> generated iproute2 tables context-local data. And I don't even see a way
> to make gmp_init() and xt_init() apply per context only.
Actually, there's no real internal state neither in gmp_init() nor in
xt_init(), so we could be just a one-time initialization things, once
and never ever again.
Moreover, the existing behaviour allows simple API clients to refresh
context on demand, via poor-man release context object and alloc it
again. Actually, we could add a function to force an context update,
so we re-parse all those files again and get fresh context.
> The effort of implementing this is quite high as well, since the table
> pointers would have to be passed down to all places where datatypes are
> parsed or printed.
I understand, but high? I'm seeing a bunch of datatype_lookup() and
datatype_print() calls, and we already have context objects all over
the place to propagate this.
BTW, do you have a usecase to make this library thread safe now? This
is just going to hit the single nfnl mutex in the kernel side, so
there is not much gain in having multiple threads sending commands to
the kernel. We can just leave this task to some Outreachy intern if
you're busy now ;-). We've been doing quite a bit of work so far is to
de-global everything, we could have just started by adding this mutex
since the beginning. So we're almost there.
Anyway, looking at more essencial stuff, probably it's time to have a
look at the batch mode, this one-command per call is expensive.
next prev parent reply other threads:[~2017-11-22 18:18 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-16 19:10 [nft PATCH] libnftables: Fix for multiple context instances Phil Sutter
2017-11-20 12:37 ` Pablo Neira Ayuso
2017-11-20 12:54 ` Phil Sutter
2017-11-20 13:07 ` Pablo Neira Ayuso
2017-11-20 15:58 ` Phil Sutter
2017-11-20 16:53 ` Pablo Neira Ayuso
2017-11-22 17:49 ` Phil Sutter
2017-11-22 18:18 ` Pablo Neira Ayuso [this message]
[not found] ` <20171204100955.GA1822@salvia>
[not found] ` <20171204105324.GX32305@orbyte.nwl.cc>
[not found] ` <20171204110142.GA19776@salvia>
[not found] ` <20171204164327.GA32305@orbyte.nwl.cc>
[not found] ` <20171204184604.GA1556@salvia>
2017-12-05 13:43 ` libnftables extended API proposal (Was: Re: [nft PATCH] libnftables: Fix for multiple context instances) Phil Sutter
2017-12-07 0:05 ` Pablo Neira Ayuso
2017-12-07 11:34 ` Phil Sutter
2017-12-10 21:55 ` Pablo Neira Ayuso
2017-12-16 16:06 ` libnftables extended API proposal Phil Sutter
2017-12-18 23:00 ` Pablo Neira Ayuso
2017-12-20 12:32 ` Phil Sutter
2017-12-20 22:23 ` Pablo Neira Ayuso
2017-12-22 13:08 ` Phil Sutter
2017-12-22 13:49 ` Pablo Neira Ayuso
2017-12-22 15:30 ` Phil Sutter
2017-12-22 20:39 ` Pablo Neira Ayuso
2017-12-23 13:19 ` Phil Sutter
2017-12-28 19:21 ` Pablo Neira Ayuso
2017-12-29 14:58 ` Phil Sutter
2018-01-02 18:02 ` Pablo Neira Ayuso
2018-01-05 17:52 ` Phil Sutter
2018-01-09 23:31 ` Pablo Neira Ayuso
2018-01-10 4:46 ` mark diener
2018-01-10 10:39 ` Phil Sutter
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=20171122181845.GA17189@salvia \
--to=pablo@netfilter.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=phil@nwl.cc \
/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).