Skip to contentSkip to conversation

netfilter: nft_ct: move custom expectation support to helper

PATCH Superseded Pablo Neira Ayuso 1 participant 1 message Jul 30

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH v2 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, it only supports for creating expectations in the other direction and it was broken with DNAT too.

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.

Fixes 857b46027d6f ("netfilter: nft_ct: add ct expectations support")

---
v2: - fix incorrect verdict on ct_expect_help()
- restrict expectation creation to original direction
- undo .num_expects atomic counter if expectation creation fails

 include/net/netfilter/nf_conntrack_helper.h |   2 +
 net/netfilter/nf_conntrack_helper.c         |  18 ++-
 net/netfilter/nft_ct.c                      | 127 +++++++++++++++-----
 3 files changed, 114 insertions(+), 33 deletions(-)
include/net/netfilter/nf_conntrack_helper.h +2 -0
index c761cd8158b2..4420846e41f2 100644
@@ -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
index 500509b17663..1197e8793494 100644
@@ -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 +100 -27

181 lines not on this page · raw message

Signature · 1 line
2.47.3