From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Liping Zhang <zlpnobody@163.com>
Cc: netfilter-devel@vger.kernel.org, Liping Zhang <zlpnobody@gmail.com>
Subject: Re: [PATCH nf V2] netfilter: nfnl_cthelper: fix a race when walk the nf_ct_helper_hash table
Date: Fri, 24 Mar 2017 12:37:49 +0100 [thread overview]
Message-ID: <20170324113749.GA2264@salvia> (raw)
In-Reply-To: <1490279819-31239-1-git-send-email-zlpnobody@163.com>
On Thu, Mar 23, 2017 at 10:36:59PM +0800, Liping Zhang wrote:
> From: Liping Zhang <zlpnobody@gmail.com>
>
> The nf_ct_helper_hash table is protected by nf_ct_helper_mutex, while
> nfct_helper operation is protected by nfnl_lock(NFNL_SUBSYS_CTHELPER).
> So it's possible that one CPU is walking the nf_ct_helper_hash for
> cthelper add/get/del, another cpu is doing nf_conntrack_helpers_unregister
> at the same time. This is dangrous, and may cause use after free error.
>
> Note, delete operation will flush all cthelpers added via nfnetlink, so
> using rcu to do protect is not easy.
>
> Now introduce a dummy list to record all the cthelpers added via
> nfnetlink, then we can walk the dummy list instead of walking the
> nf_ct_helper_hash. Also, keep nfnl_cthelper_dump_table unchanged, it
> may be invoked without nfnl_lock(NFNL_SUBSYS_CTHELPER) held.
>
> Signed-off-by: Liping Zhang <zlpnobody@gmail.com>
> ---
> V2: rebase on the latest nf tree
>
> net/netfilter/nfnetlink_cthelper.c | 182 ++++++++++++++++++-------------------
> 1 file changed, 88 insertions(+), 94 deletions(-)
>
> diff --git a/net/netfilter/nfnetlink_cthelper.c b/net/netfilter/nfnetlink_cthelper.c
> index 2b987d2..304aab8 100644
> --- a/net/netfilter/nfnetlink_cthelper.c
> +++ b/net/netfilter/nfnetlink_cthelper.c
> @@ -32,6 +32,13 @@ MODULE_LICENSE("GPL");
> MODULE_AUTHOR("Pablo Neira Ayuso <pablo@netfilter.org>");
> MODULE_DESCRIPTION("nfnl_cthelper: User-space connection tracking helpers");
>
> +struct nfnl_cthelper {
> + struct list_head list;
> + struct nf_conntrack_helper *helper;
> +};
I overlook this. Any reason for not using this declaration instead?
struct nfnl_cthelper {
struct list_head list;
struct nf_conntrack_helper helper;
};
We would simplify this a bit as the helper would be embedded into the
new nfnl_cthelper structure.
next prev parent reply other threads:[~2017-03-24 11:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-23 14:36 [PATCH nf V2] netfilter: nfnl_cthelper: fix a race when walk the nf_ct_helper_hash table Liping Zhang
2017-03-24 11:37 ` Pablo Neira Ayuso [this message]
2017-03-24 11:56 ` Liping Zhang
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=20170324113749.GA2264@salvia \
--to=pablo@netfilter.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=zlpnobody@163.com \
--cc=zlpnobody@gmail.com \
/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).