Skip to contentSkip to conversation

netfilter: nft_set_pipapo: allocate pcpu scratch maps on clone

PATCH Applied Florian Westphal 3 participants 3 messages Jan 5, 2022 – Jan 6, 2022

Subsystems (2)
lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 netfilter: nft_set_pipapo: allocate pcpu scratch maps on clone

This is needed in case a new transaction is made that doesn't insert any new elements into an already existing set.

Else, after second 'nft -f ruleset.txt', lookups in such a set will fail because ->lookup() encounters raw_cpu_ptr(m->scratch) == NULL.

For the initial rule load, insertion of elements takes care of the allocation, but for rule reloads this isn't guaranteed: we might not have additions to the set.

Fixes 3c4287f62044a90e ("nf_tables: Add set type for arbitrary concatenation of ranges")

---
Change since test patch:
handle 'out_scratch_realloc' error handling to free scratch maps on errors.

 net/netfilter/nft_set_pipapo.c | 8 ++++++++
 1 file changed, 8 insertions(+)
net/netfilter/nft_set_pipapo.c +8 -0
index dce866d93fee..2c8051d8cca6 100644
@@ -1290,6 +1290,11 @@ static struct nft_pipapo_match *pipapo_clone(struct nft_pipapo_match *old)
 	if (!new->scratch_aligned)
 		goto out_scratch;
 #endif
+	for_each_possible_cpu(i)
+		*per_cpu_ptr(new->scratch, i) = NULL;
+
+	if (pipapo_realloc_scratch(new, old->bsize_max))
+		goto out_scratch_realloc;
 
 	rcu_head_init(&new->rcu);
 
@@ -1334,6 +1339,9 @@ static struct nft_pipapo_match *pipapo_clone(struct nft_pipapo_match *old)
 		kvfree(dst->lt);
 		dst--;
 	}
+out_scratch_realloc:
+	for_each_possible_cpu(i)
+		kfree(*per_cpu_ptr(new->scratch, i));
 #ifdef NFT_PIPAPO_ALIGN
 	free_percpu(new->scratch_aligned);
 #endif
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · On Wed, 5 Jan 2022 14:19:54 +0100 Florian Westphal <[email protected]> wrote:

This is needed in case a new transaction is made that doesn't insert any new elements into an already existing set.

Else, after second 'nft -f ruleset.txt', lookups in such a set will fail because ->lookup() encounters raw_cpu_ptr(m->scratch) == NULL.

Quoted 7 lines

For the initial rule load, insertion of elements takes care of the allocation, but for rule reloads this isn't guaranteed: we might not have additions to the set.

Fixes 3c4287f62044a90e ("nf_tables: Add set type for arbitrary concatenation of ranges")
Signature · 1 line
Stefano
maintainer Applied
#2 lore raw
In reply to Florian Westphal
Quoted 9 lines · Florian Westphal

This is needed in case a new transaction is made that doesn't insert any new elements into an already existing set.

Else, after second 'nft -f ruleset.txt', lookups in such a set will fail because ->lookup() encounters raw_cpu_ptr(m->scratch) == NULL.

For the initial rule load, insertion of elements takes care of the allocation, but for rule reloads this isn't guaranteed: we might not have additions to the set.

Applied, thanks