netfilter: fix possible bug_on with enable_hooks=1
Subsystems (2)
Florian Westphal
maintainerPATCH 1/1 netfilter: 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.
--- net/netfilter/core.c | 6 ++++-- net/netfilter/nf_conntrack_standalone.c | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-)
net/netfilter/core.c +4 -2
@@ -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);
net/netfilter/nf_conntrack_standalone.c +2 -1
@@ -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:
Signature · 1 line
2.39.2
Quoted 11 lines · Florian Westphal
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); // hereIn
nf_conntrack_destroy().First turn this
BUG_ONinto a WARN. I think it was triggered via enable_hooks=1 flag.
Quoted 8 lines
When this flag is turned on, the conntrack hooks are registered before
nf_ct_hookpointer gets assigned.
This opens a short window where packets enter the conntrack machinery, can haveskb->_nfctset up and a subsequentkfree_skbmight occur beforenf_ct_hookis set.Call
nf_conntrack_init_end()to setnf_ct_hookbefore we register the pernet ops.
Applied to nf, thanks