Skip to contentSkip to conversation

netfilter: nftables: missing transaction object on flowtable deletion

PATCH In review Pablo Neira Ayuso 1 participant 3 messages Mar 17, 2021 – Mar 18, 2021

Subsystems (2)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/2 netfilter: nftables: missing transaction object on flowtable deletion

The delete flowtable command does not create a transaction if the NFTA_FLOWTABLE_HOOK attribute is specified, hence, the flowtable is never deleted.

Fixes abadb2f865d7 ("netfilter: nf_tables: delete devices from flowtable")
---
 net/netfilter/nf_tables_api.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
net/netfilter/nf_tables_api.c +6 -2
index 224c8e537cb3..6b97a0c7b6d3 100644
@@ -7090,6 +7090,7 @@ static int nf_tables_delflowtable(struct net *net, struct sock *nlsk,
 	const struct nlattr *attr;
 	struct nft_table *table;
 	struct nft_ctx ctx;
+	int err;
 
 	if (!nla[NFTA_FLOWTABLE_TABLE] ||
 	    (!nla[NFTA_FLOWTABLE_NAME] &&
@@ -7118,8 +7119,11 @@ static int nf_tables_delflowtable(struct net *net, struct sock *nlsk,
 
 	nft_ctx_init(&ctx, net, skb, nlh, family, table, NULL, nla);
 
-	if (nla[NFTA_FLOWTABLE_HOOK])
-		return nft_delflowtable_hook(&ctx, flowtable);
+	if (nla[NFTA_FLOWTABLE_HOOK]) {
+		err = nft_delflowtable_hook(&ctx, flowtable);
+		if (err < 0)
+			return err;
+	}
 
 	if (flowtable->use > 0) {
 		NL_SET_BAD_ATTR(extack, attr);
Signature · 1 line
2.20.1
author maintainer
#1 lore raw

PATCH 2/2 netfilter: nftables: skip hook overlap logic if flowtable is stale

If the flowtable has been previously removed in this batch, skip the hook overlap checks. This fixes spurious EEXIST errors when removing and adding the flowtable in the same batch.

---
 net/netfilter/nf_tables_api.c | 3 +++
 1 file changed, 3 insertions(+)
net/netfilter/nf_tables_api.c +3 -0
index 6b97a0c7b6d3..1195f0ac6d37 100644
@@ -6783,6 +6783,9 @@ static int nft_register_flowtable_net_hooks(struct net *net,
 
 	list_for_each_entry(hook, hook_list, list) {
 		list_for_each_entry(ft, &table->flowtables, list) {
+			if (!nft_is_active_next(net, ft))
+				continue;
+
 			list_for_each_entry(hook2, &ft->hook_list, list) {
 				if (hook->ops.dev == hook2->ops.dev &&
 				    hook->ops.pf == hook2->ops.pf) {
Signature · 1 line
2.20.1
author maintainer
#2 lore raw
In reply to Pablo Neira Ayuso
Quoted 3 lines · Pablo Neira Ayuso

The delete flowtable command does not create a transaction if the NFTA_FLOWTABLE_HOOK attribute is specified, hence, the flowtable is never deleted.

Scratch this.

The existing code is correct. Userspace only includes NFTA_FLOWTABLE_HOOK when performing an incremental deletion of devices in the flowtable.