Skip to content

Commit e72eeab

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: conntrack: fix possible bug_on with enable_hooks=1
I received a bug report (no reproducer so far) where we trip over 712 rcu_read_lock(); 713 ct_hook = rcu_dereference(nf_ct_hook); 714 BUG_ON(ct_hook == NULL); // here In nf_conntrack_destroy(). First turn this BUG_ON into a WARN. I think it was triggered via enable_hooks=1 flag. When this flag is turned on, the conntrack hooks are registered before nf_ct_hook pointer gets assigned. This opens a short window where packets enter the conntrack machinery, can have skb->_nfct set up and a subsequent kfree_skb might occur before nf_ct_hook is set. Call nf_conntrack_init_end() to set nf_ct_hook before we register the pernet ops. Fixes: ba3fbe6 ("netfilter: nf_conntrack: provide modparam to always register conntrack hooks") Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent dc1c9fd commit e72eeab

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

net/netfilter/core.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,9 +711,11 @@ void nf_conntrack_destroy(struct nf_conntrack *nfct)
711711

712712
rcu_read_lock();
713713
ct_hook = rcu_dereference(nf_ct_hook);
714-
BUG_ON(ct_hook == NULL);
715-
ct_hook->destroy(nfct);
714+
if (ct_hook)
715+
ct_hook->destroy(nfct);
716716
rcu_read_unlock();
717+
718+
WARN_ON(!ct_hook);
717719
}
718720
EXPORT_SYMBOL(nf_conntrack_destroy);
719721

net/netfilter/nf_conntrack_standalone.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1218,11 +1218,12 @@ static int __init nf_conntrack_standalone_init(void)
12181218
nf_conntrack_htable_size_user = nf_conntrack_htable_size;
12191219
#endif
12201220

1221+
nf_conntrack_init_end();
1222+
12211223
ret = register_pernet_subsys(&nf_conntrack_net_ops);
12221224
if (ret < 0)
12231225
goto out_pernet;
12241226

1225-
nf_conntrack_init_end();
12261227
return 0;
12271228

12281229
out_pernet:

0 commit comments

Comments
 (0)