]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
netfilter: expect: add to hash table after expect init
authorFlorian Westphal <fw@strlen.de>
Mon, 10 Jul 2017 13:06:39 +0000 (15:06 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 24 Jul 2017 10:20:10 +0000 (12:20 +0200)
assuming we have lockless readers we should make sure they can only
see expectations that have already been initialized.

hlist_add_head_rcu acts as memory barrier, move it after timer setup.

Theoretically we could crash due to a del_timer() on other cpu
seeing garbage data.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
net/netfilter/nf_conntrack_expect.c

index 899c2c36da136fe3e7268e44437a8d49d73789e2..2c63808bea96e320fc9c529493030aba45a233a6 100644 (file)
@@ -368,12 +368,6 @@ static void nf_ct_expect_insert(struct nf_conntrack_expect *exp)
        /* two references : one for hash insert, one for the timer */
        refcount_add(2, &exp->use);
 
-       hlist_add_head_rcu(&exp->lnode, &master_help->expectations);
-       master_help->expecting[exp->class]++;
-
-       hlist_add_head_rcu(&exp->hnode, &nf_ct_expect_hash[h]);
-       net->ct.expect_count++;
-
        setup_timer(&exp->timeout, nf_ct_expectation_timed_out,
                    (unsigned long)exp);
        helper = rcu_dereference_protected(master_help->helper,
@@ -384,6 +378,12 @@ static void nf_ct_expect_insert(struct nf_conntrack_expect *exp)
        }
        add_timer(&exp->timeout);
 
+       hlist_add_head_rcu(&exp->lnode, &master_help->expectations);
+       master_help->expecting[exp->class]++;
+
+       hlist_add_head_rcu(&exp->hnode, &nf_ct_expect_hash[h]);
+       net->ct.expect_count++;
+
        NF_CT_STAT_INC(net, expect_create);
 }