Skip to content

Commit 3101e0f

Browse files
Liping Zhangummakynes
authored andcommitted
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: 242922a ("netfilter: conntrack: simplify early_drop") Cc: Florian Westphal <[email protected]> Signed-off-by: Liping Zhang <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent c2b9b4f commit 3101e0f

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

net/netfilter/nf_conntrack_core.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,13 +880,16 @@ static noinline int early_drop(struct net *net, unsigned int _hash)
880880
struct hlist_nulls_head *ct_hash;
881881
unsigned hash, sequence, drops;
882882

883+
rcu_read_lock();
883884
do {
884885
sequence = read_seqcount_begin(&nf_conntrack_generation);
885886
hash = scale_hash(_hash++);
886887
ct_hash = nf_conntrack_hash;
887888
} while (read_seqcount_retry(&nf_conntrack_generation, sequence));
888889

889890
drops = early_drop_list(net, &ct_hash[hash]);
891+
rcu_read_unlock();
892+
890893
if (drops) {
891894
NF_CT_STAT_ADD_ATOMIC(net, early_drop, drops);
892895
return true;

0 commit comments

Comments
 (0)