From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Patrick McHardy <kaber@trash.net>
Cc: netfilter-devel@vger.kernel.org, arturo.borrero.glez@gmail.com
Subject: Re: [PATCH] netfilter: nf_tables: fix racy rule deletion
Date: Wed, 5 Feb 2014 17:38:06 +0100 [thread overview]
Message-ID: <20140205163806.GA4575@localhost> (raw)
In-Reply-To: <20140205154843.GA31493@macbook.localnet>
On Wed, Feb 05, 2014 at 03:48:46PM +0000, Patrick McHardy wrote:
> On Sat, Jan 25, 2014 at 02:03:51PM +0100, Pablo Neira Ayuso wrote:
> > As a side effect, we save memory as we don't need rcu_head per rule
> > anymore.
>
> We can also save some memory for now unnecessary families in the private
> structs since we have the context available during destruction again.
Right, that was only needed with when we were using call_rcu. I'll
revisit that.
> > @@ -1809,9 +1803,6 @@ static int nf_tables_commit(struct sk_buff *skb)
> > synchronize_rcu();
> >
> > list_for_each_entry_safe(rupd, tmp, &net->nft.commit_list, list) {
> > - /* Delete this rule from the dirty list */
> > - list_del(&rupd->list);
> > -
> > /* This rule was inactive in the past and just became active.
> > * Clear the next bit of the genmask since its meaning has
> > * changed, now it is the future.
> > @@ -1822,6 +1813,7 @@ static int nf_tables_commit(struct sk_buff *skb)
> > rupd->chain, rupd->rule,
> > NFT_MSG_NEWRULE, 0,
> > rupd->family);
> > + list_del(&rupd->list);
> > kfree(rupd);
> > continue;
> > }
> > @@ -1831,7 +1823,15 @@ static int nf_tables_commit(struct sk_buff *skb)
> > nf_tables_rule_notify(skb, rupd->nlh, rupd->table, rupd->chain,
> > rupd->rule, NFT_MSG_DELRULE, 0,
> > rupd->family);
> > + }
> > +
> > + /* Make sure we don't see any packet traversing old rules */
> > + synchronize_rcu();
> > +
> > + /* Now we can safely release unused old rules */
> > + list_for_each_entry_safe(rupd, tmp, &net->nft.commit_list, list) {
> > nf_tables_rule_destroy(rupd->rule);
> > + list_del(&rupd->list);
> > kfree(rupd);
> > }
> >
> > @@ -1844,20 +1844,26 @@ static int nf_tables_abort(struct sk_buff *skb)
> > struct nft_rule_trans *rupd, *tmp;
> >
> > list_for_each_entry_safe(rupd, tmp, &net->nft.commit_list, list) {
> > - /* Delete all rules from the dirty list */
> > - list_del(&rupd->list);
> > -
> > if (!nft_rule_is_active_next(net, rupd->rule)) {
> > nft_rule_clear(net, rupd->rule);
> > + list_del(&rupd->list);
> > kfree(rupd);
> > continue;
> > }
> >
> > /* This rule is inactive, get rid of it */
> > list_del_rcu(&rupd->rule->list);
> > + }
> > +
> > + /* Make sure we don't see any packet accessing aborted rules */
> > + synchronize_rcu();
> > +
> > + list_for_each_entry_safe(rupd, tmp, &net->nft.commit_list, list) {
> > nf_tables_rule_destroy(rupd->rule);
> > + list_del(&rupd->list);
> > kfree(rupd);
> > }
>
> I have to admit this all seems slightly confusing to me, we now have three
> synhronize_rcu()s in this function, are all those really needed?
There are only two to separate the different stages. To my
understanding, the first one ensures that all packets has left the
previous generation before we start purging out old rules. Then, the
second one makes sure that no packets are still checking the old rule
genmask that have just been deleted, so we can safely release it.
Before this patch, we only needed one since we were using call_rcu
after deleting the rules from the list.
next prev parent reply other threads:[~2014-02-05 16:38 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-25 13:03 [PATCH] netfilter: nf_tables: fix racy rule deletion Pablo Neira Ayuso
2014-01-25 13:55 ` Patrick McHardy
2014-01-25 16:35 ` Patrick McHardy
2014-01-25 17:14 ` Patrick McHardy
2014-01-26 8:54 ` Pablo Neira Ayuso
2014-01-26 12:23 ` Patrick McHardy
2014-02-05 23:02 ` Pablo Neira Ayuso
2014-02-05 15:48 ` Patrick McHardy
2014-02-05 16:38 ` Pablo Neira Ayuso [this message]
2014-02-05 16:48 ` Patrick McHardy
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=20140205163806.GA4575@localhost \
--to=pablo@netfilter.org \
--cc=arturo.borrero.glez@gmail.com \
--cc=kaber@trash.net \
--cc=netfilter-devel@vger.kernel.org \
/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).