netfilter: nf_conntrack_helper: remove synchronize_rcu() on helper removal
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH v3 1/2 netfilter: nf_conntrack_helper: remove synchronize_rcu() on helper removal
The helper stays around after unregistration if it is still in use, turn the expectation removal into a best effort clean up. A helper might win race to create an expectation while it is going away, but such expectation still depends on master conntrack.
---
v3: - new in this series
net/netfilter/nf_conntrack_helper.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
net/netfilter/nf_conntrack_helper.c +2 -4
@@ -458,11 +458,9 @@ void nf_conntrack_helper_unregister(struct nf_conntrack_helper *me)/* This helper is going away, disable it. */ rcu_assign_pointer (me->help,NULL ); -/* Make sure every nothing is still using the helper unless its a -* connection in the hash. +/* This is best effort, helper might win race to create an +* expectation but it still depends on the master conntrack. */ -synchronize_rcu (); -nf_ct_expect_iterate_destroy (expect_iter_me, me);if (refcount_dec_and_test (&me->ct_refcnt))
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH v3 2/2 netfilter: nft_ct: move custom expectation support to helper
Originally, the ct expectation support called nf_ct_helper_ext_add() for confirmed conntracks, which is invalid, triggering a splat. This was fixed by commit 1710eb913bdc ("netfilter: nft_ct: skip expectations for confirmed conntrack") which restricted it to unconfirmed conntracks.
However, early insertion of expectations into the expectations list when the conntrack is unconfirmed leads to stale entries pointing to the wrong hlist_head through .pprev due to ct extension reallocation.
Commit 7c9664351980 ("netfilter: move nat hlist_head to nf_conn") moved the nat hlist_head to nf_conn for this reason:
1. ...
2. When reallocation of extension area occurs we need to fixup the bysource hash head via hlist_replace_rcu.
I'd rather not increase the size of the struct nf_conn for this feature has very limited scope: only one expectation can be created at a time given expect_clash() will make nf_ct_expect_related() reports EBUSY. For this reason, relax nf_ct_expect_related() not to drop packets in case expectation creation fails, therefore, expectation creation becomes best effort. Now the size determines the maximum number of expectations that can be created for this connection, one after another, given the expect_clash() limitations.
To address this issue, add an internal ct helper and attach it to the conntrack entry to streamline the custom ct expectation support with existing ct helpers.
Expose a new nf_conntrack_helper_free() function to release the internal helper that is allocated and attached to the conntrack entry to create the custom expectations.
This patch also restricts the creation of expectations to different helpers other than this custom helper that is created for this type of expectations.
---
v3: - regard nf_ct_l3num() as reported by sashiko
- do not drop packets if expectation creation fails
- nullify helper pointer copied to expect_data
- set a cap to priv->size (even though it is futile, because expectation will clash only one expectation can stay around)
include/net/netfilter/nf_conntrack_helper.h | 2 + net/netfilter/nf_conntrack_helper.c | 18 ++- net/netfilter/nft_ct.c | 140 +++++++++++++++----- 3 files changed, 122 insertions(+), 38 deletions(-)
include/net/netfilter/nf_conntrack_helper.h +2 -0
@@ -112,6 +112,8 @@ int nf_conntrack_helpers_register(struct nf_conntrack_helper *, unsigned int,void nf_conntrack_helpers_unregister (struct nf_conntrack_helper **,unsigned int ); +void nf_conntrack_helper_release (struct nf_conntrack_helper *me); +#define nf_conntrack_helper_deprecated (name) \ pr_warn("The %s conntrack helper is scheduled for removal.\n" \ "Please contact the netfilter-devel mailing list if you still need this.\n", name)
net/netfilter/nf_conntrack_helper.c +12 -6
@@ -448,13 +448,8 @@ static bool expect_iter_me(struct nf_conntrack_expect *exp, void *data)return this == me; } -void nf_conntrack_helper_unregister (struct nf_conntrack_helper *me) +void nf_conntrack_helper_release (struct nf_conntrack_helper *me) { -mutex_lock (&nf_ct_helper_mutex); -hlist_del_rcu (&me->hnode); - nf_ct_helper_count--; -mutex_unlock (&nf_ct_helper_mutex); -/* This helper is going away, disable it. */ rcu_assign_pointer (me->help,NULL );
@@ -466,6 +461,17 @@ void nf_conntrack_helper_unregister(struct nf_conntrack_helper *me)if (refcount_dec_and_test (&me->ct_refcnt))kfree_rcu (me, rcu); } +EXPORT_SYMBOL_GPL (nf_conntrack_helper_release); + +void nf_conntrack_helper_unregister (struct nf_conntrack_helper *me) +{ +mutex_lock (&nf_ct_helper_mutex); +hlist_del_rcu (&me->hnode); + nf_ct_helper_count--; +mutex_unlock (&nf_ct_helper_mutex); + +nf_conntrack_helper_release (me); +}EXPORT_SYMBOL_GPL (nf_conntrack_helper_unregister); void nf_ct_helper_init(struct nf_conntrack_helper *helper,
net/netfilter/nft_ct.c +108 -32
196 lines not on this page · raw message
Signature · 1 line
2.47.3