From: Liping Zhang <zlpnobody@163.com>
To: pablo@netfilter.org
Cc: netfilter-devel@vger.kernel.org,
Liping Zhang <liping.zhang@spreadtrum.com>,
Florian Westphal <fw@strlen.de>
Subject: [PATCH nf-next 1/2] netfilter: conntrack: protect early_drop by rcu read lock
Date: Tue, 12 Jul 2016 19:45:00 +0800 [thread overview]
Message-ID: <1468323901-15767-1-git-send-email-zlpnobody@163.com> (raw)
From: Liping Zhang <liping.zhang@spreadtrum.com>
User can add ct entry via nfnetlink(IPCTNL_MSG_CT_NEW), and if the total
number reach the nf_conntrack_max, we will try to drop some ct entries.
But in this case(the main function call path is ctnetlink_create_conntrack
-> nf_conntrack_alloc -> early_drop), rcu_read_lock is not held, so race
with hash resize will happen.
Fixes: 242922a02717 ("netfilter: conntrack: simplify early_drop")
Cc: Florian Westphal <fw@strlen.de>
Signed-off-by: Liping Zhang <liping.zhang@spreadtrum.com>
---
net/netfilter/nf_conntrack_core.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index e0e9c9a..2d46225 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -880,6 +880,7 @@ static noinline int early_drop(struct net *net, unsigned int _hash)
struct hlist_nulls_head *ct_hash;
unsigned hash, sequence, drops;
+ rcu_read_lock();
do {
sequence = read_seqcount_begin(&nf_conntrack_generation);
hash = scale_hash(_hash++);
@@ -887,6 +888,8 @@ static noinline int early_drop(struct net *net, unsigned int _hash)
} while (read_seqcount_retry(&nf_conntrack_generation, sequence));
drops = early_drop_list(net, &ct_hash[hash]);
+ rcu_read_unlock();
+
if (drops) {
NF_CT_STAT_ADD_ATOMIC(net, early_drop, drops);
return true;
--
2.5.5
next reply other threads:[~2016-07-12 11:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-12 11:45 Liping Zhang [this message]
2016-07-12 11:45 ` [PATCH nf-next 2/2] netfilter: conntrack: simplify the code by using nf_conntrack_get_ht Liping Zhang
2016-07-12 13:03 ` Florian Westphal
2016-07-13 8:13 ` Liping Zhang
2016-07-12 13:01 ` [PATCH nf-next 1/2] netfilter: conntrack: protect early_drop by rcu read lock Florian Westphal
2016-07-12 14:34 ` Pablo Neira Ayuso
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=1468323901-15767-1-git-send-email-zlpnobody@163.com \
--to=zlpnobody@163.com \
--cc=fw@strlen.de \
--cc=liping.zhang@spreadtrum.com \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.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).