Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 242922a02717 ("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>

authored by

Liping Zhang and committed by
Pablo Neira Ayuso
3101e0fc c2b9b4fe

+3
+3
net/netfilter/nf_conntrack_core.c
··· 880 880 struct hlist_nulls_head *ct_hash; 881 881 unsigned hash, sequence, drops; 882 882 883 + rcu_read_lock(); 883 884 do { 884 885 sequence = read_seqcount_begin(&nf_conntrack_generation); 885 886 hash = scale_hash(_hash++); ··· 888 887 } while (read_seqcount_retry(&nf_conntrack_generation, sequence)); 889 888 890 889 drops = early_drop_list(net, &ct_hash[hash]); 890 + rcu_read_unlock(); 891 + 891 892 if (drops) { 892 893 NF_CT_STAT_ADD_ATOMIC(net, early_drop, drops); 893 894 return true;