Skip to content

Commit

Permalink
netfilter: conntrack: protect early_drop by rcu read lock
Browse files Browse the repository at this point in the history
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: 242922a ("netfilter: conntrack: simplify early_drop")
Cc: Florian Westphal <fw@strlen.de>
Signed-off-by: Liping Zhang <liping.zhang@spreadtrum.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
  • Loading branch information
Liping Zhang authored and Pablo Neira Ayuso committed Jul 12, 2016
1 parent c2b9b4f commit 3101e0f
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions net/netfilter/nf_conntrack_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -880,13 +880,16 @@ 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++);
ct_hash = nf_conntrack_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;
Expand Down

0 comments on commit 3101e0f

Please sign in to comment.