]> git.baikalelectronics.ru Git - kernel.git/commit
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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 30 May 2023 11:44:01 +0000 (12:44 +0100)
commit8801c2f623aaa6acb31182141d905e5af186f119
tree7fe5e6b9a11426d669fe9e36f7626e618df30b49
parent52068a4d3710a374cddc85adaeb54efdea8c5a99
netfilter: conntrack: fix possible bug_on with enable_hooks=1

[ Upstream commit e72eeab542dbf4f544e389e64fa13b82a1b6d003 ]

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: ae08d40e69a0 ("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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/netfilter/core.c
net/netfilter/nf_conntrack_standalone.c