From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Florian Westphal <fw@strlen.de>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH nf] netfilter: conntrack: fix infinite loop on rmmod
Date: Mon, 11 May 2020 19:29:02 +0200 [thread overview]
Message-ID: <20200511172902.GB2064@salvia> (raw)
In-Reply-To: <20200510122807.24011-1-fw@strlen.de>
On Sun, May 10, 2020 at 02:28:07PM +0200, Florian Westphal wrote:
> 'rmmod nf_conntrack' can hang forever, because the netns exit
> gets stuck in nf_conntrack_cleanup_net_list():
>
> i_see_dead_people:
> busy = 0;
> list_for_each_entry(net, net_exit_list, exit_list) {
> nf_ct_iterate_cleanup(kill_all, net, 0, 0);
> if (atomic_read(&net->ct.count) != 0)
> busy = 1;
> }
> if (busy) {
> schedule();
> goto i_see_dead_people;
> }
>
> When nf_ct_iterate_cleanup iterates the conntrack table, all nf_conn
> structures can be found twice:
> once for the original tuple and once for the conntracks reply tuple.
>
> get_next_corpse() only calls the iterator when the entry is
> in original direction -- the idea was to avoid unneeded invocations
> of the iterator callback.
>
> When support for clashing entries was added, the assumption that
> all nf_conn objects are added twice, once in original, once for reply
> tuple no longer holds -- NF_CLASH_BIT entries are only added in
> the non-clashing reply direction.
>
> Thus, if at least one NF_CLASH entry is in the list then
> nf_conntrack_cleanup_net_list() always skips it completely.
>
> During normal netns destruction, this causes a hang of several
> seconds, until the gc worker removes the entry (NF_CLASH entries
> always have a 1 second timeout).
>
> But in the rmmod case, the gc worker has already been stopped, so
> ct.count never becomes 0.
>
> We can fix this in two ways:
>
> 1. Add a second test for CLASH_BIT and call iterator for those
> entries as well, or:
> 2. Skip the original tuple direction and use the reply tuple.
>
> 2) is simpler, so do that.
Applied, thanks.
prev parent reply other threads:[~2020-05-11 17:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-10 12:28 [PATCH nf] netfilter: conntrack: fix infinite loop on rmmod Florian Westphal
2020-05-11 17:29 ` Pablo Neira Ayuso [this message]
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=20200511172902.GB2064@salvia \
--to=pablo@netfilter.org \
--cc=fw@strlen.de \
--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).