Commit 3101e0fc authored by Liping Zhang's avatar Liping Zhang Committed by Pablo Neira Ayuso

netfilter: conntrack: protect early_drop by rcu read lock

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: 242922a0 ("netfilter: conntrack: simplify early_drop")
Cc: Florian Westphal <fw@strlen.de>
Signed-off-by: default avatarLiping Zhang <liping.zhang@spreadtrum.com>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent c2b9b4fe
...@@ -880,6 +880,7 @@ static noinline int early_drop(struct net *net, unsigned int _hash) ...@@ -880,6 +880,7 @@ static noinline int early_drop(struct net *net, unsigned int _hash)
struct hlist_nulls_head *ct_hash; struct hlist_nulls_head *ct_hash;
unsigned hash, sequence, drops; unsigned hash, sequence, drops;
rcu_read_lock();
do { do {
sequence = read_seqcount_begin(&nf_conntrack_generation); sequence = read_seqcount_begin(&nf_conntrack_generation);
hash = scale_hash(_hash++); hash = scale_hash(_hash++);
...@@ -887,6 +888,8 @@ static noinline int early_drop(struct net *net, unsigned int _hash) ...@@ -887,6 +888,8 @@ static noinline int early_drop(struct net *net, unsigned int _hash)
} while (read_seqcount_retry(&nf_conntrack_generation, sequence)); } while (read_seqcount_retry(&nf_conntrack_generation, sequence));
drops = early_drop_list(net, &ct_hash[hash]); drops = early_drop_list(net, &ct_hash[hash]);
rcu_read_unlock();
if (drops) { if (drops) {
NF_CT_STAT_ADD_ATOMIC(net, early_drop, drops); NF_CT_STAT_ADD_ATOMIC(net, early_drop, drops);
return true; return true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment