Skip to content

Commit 56a97e7

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: expect: add to hash table after expect init
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 <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 7a68ada commit 56a97e7

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

net/netfilter/nf_conntrack_expect.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,12 +368,6 @@ static void nf_ct_expect_insert(struct nf_conntrack_expect *exp)
368368
/* two references : one for hash insert, one for the timer */
369369
refcount_add(2, &exp->use);
370370

371-
hlist_add_head_rcu(&exp->lnode, &master_help->expectations);
372-
master_help->expecting[exp->class]++;
373-
374-
hlist_add_head_rcu(&exp->hnode, &nf_ct_expect_hash[h]);
375-
net->ct.expect_count++;
376-
377371
setup_timer(&exp->timeout, nf_ct_expectation_timed_out,
378372
(unsigned long)exp);
379373
helper = rcu_dereference_protected(master_help->helper,
@@ -384,6 +378,12 @@ static void nf_ct_expect_insert(struct nf_conntrack_expect *exp)
384378
}
385379
add_timer(&exp->timeout);
386380

381+
hlist_add_head_rcu(&exp->lnode, &master_help->expectations);
382+
master_help->expecting[exp->class]++;
383+
384+
hlist_add_head_rcu(&exp->hnode, &nf_ct_expect_hash[h]);
385+
net->ct.expect_count++;
386+
387387
NF_CT_STAT_INC(net, expect_create);
388388
}
389389

0 commit comments

Comments
 (0)