]> git.itanic.dy.fi Git - linux-stable/commitdiff
netfilter: conntrack: fix possible bug_on with enable_hooks=1
authorFlorian Westphal <fw@strlen.de>
Thu, 4 May 2023 12:55:02 +0000 (14:55 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 10 May 2023 06:50:39 +0000 (08:50 +0200)
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: ba3fbe663635 ("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>
net/netfilter/core.c
net/netfilter/nf_conntrack_standalone.c

index f0783e42108bab59cbf59e4296898ed3bffaf44c..5f76ae86a6561f6decc21c6d35e5311e7488c921 100644 (file)
@@ -711,9 +711,11 @@ void nf_conntrack_destroy(struct nf_conntrack *nfct)
 
        rcu_read_lock();
        ct_hook = rcu_dereference(nf_ct_hook);
-       BUG_ON(ct_hook == NULL);
-       ct_hook->destroy(nfct);
+       if (ct_hook)
+               ct_hook->destroy(nfct);
        rcu_read_unlock();
+
+       WARN_ON(!ct_hook);
 }
 EXPORT_SYMBOL(nf_conntrack_destroy);
 
index 57f6724c99a76763e212a53b4e29c969d3efa469..169e16fc2bceb1b611da209bd6b1250b125f1baf 100644 (file)
@@ -1218,11 +1218,12 @@ static int __init nf_conntrack_standalone_init(void)
        nf_conntrack_htable_size_user = nf_conntrack_htable_size;
 #endif
 
+       nf_conntrack_init_end();
+
        ret = register_pernet_subsys(&nf_conntrack_net_ops);
        if (ret < 0)
                goto out_pernet;
 
-       nf_conntrack_init_end();
        return 0;
 
 out_pernet: