netfilter: nft_ct: move custom expectation support to helper
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH 1/1 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 confirmed conntracks.
This is still not sufficient though. Early insertion of expectations into the expectations list, which resides in the ct helper extension area might lead 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.
However, I'd rather not increase the size of the struct nf_conn for this feature, which only supports for creating expectations in the reply direction, which restricts its usecase. Note that ct expectation is also broken with NAT, because the dnat mappings is not available until the conntrack is confirmed.
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 safely release the internal helper that is allocated and attached to the conntrack entry to create the custom expectations.
---
v1: this replaces:
[nf,v2] netfilter: nft_ct: postpone expectation creation to confirmed conntrack by following a different approach.
include/net/netfilter/nf_conntrack_helper.h | 2 + net/netfilter/nf_conntrack_helper.c | 18 ++- net/netfilter/nft_ct.c | 119 +++++++++++++++----- 3 files changed, 106 insertions(+), 33 deletions(-)
include/net/netfilter/nf_conntrack_helper.h +2 -0
@@ -114,6 +114,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_free (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
@@ -456,13 +456,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_free (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 );
@@ -476,6 +471,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_free); + +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_free (me); +}EXPORT_SYMBOL_GPL (nf_conntrack_helper_unregister); void nf_ct_helper_init(struct nf_conntrack_helper *helper,
net/netfilter/nft_ct.c +92 -27
173 lines not on this page · raw message
Signature · 1 line
2.47.3