netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH nf] netfilter: nft_set_pipapo: allocate pcpu scratch maps on clone
@ 2022-01-05 13:19 Florian Westphal
  2022-01-05 15:20 ` Stefano Brivio
  2022-01-06  9:41 ` Pablo Neira Ayuso
  0 siblings, 2 replies; 3+ messages in thread
From: Florian Westphal @ 2022-01-05 13:19 UTC (permalink / raw)
  To: netfilter-devel; +Cc: sbrivio, Florian Westphal, etkaar

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")
Reported-by: etkaar <lists.netfilter.org@prvy.eu>
Signed-off-by: Florian Westphal <fw@strlen.de>
---
 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(+)

diff --git a/net/netfilter/nft_set_pipapo.c b/net/netfilter/nft_set_pipapo.c
index dce866d93fee..2c8051d8cca6 100644
--- a/net/netfilter/nft_set_pipapo.c
+++ b/net/netfilter/nft_set_pipapo.c
@@ -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
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH nf] netfilter: nft_set_pipapo: allocate pcpu scratch maps on clone
  2022-01-05 13:19 [PATCH nf] netfilter: nft_set_pipapo: allocate pcpu scratch maps on clone Florian Westphal
@ 2022-01-05 15:20 ` Stefano Brivio
  2022-01-06  9:41 ` Pablo Neira Ayuso
  1 sibling, 0 replies; 3+ messages in thread
From: Stefano Brivio @ 2022-01-05 15:20 UTC (permalink / raw)
  To: Florian Westphal; +Cc: netfilter-devel, etkaar

On Wed,  5 Jan 2022 14:19:54 +0100
Florian Westphal <fw@strlen.de> 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.
> 
> 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")
> Reported-by: etkaar <lists.netfilter.org@prvy.eu>
> Signed-off-by: Florian Westphal <fw@strlen.de>

Reviewed-by: Stefano Brivio <sbrivio@redhat.com>

-- 
Stefano


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH nf] netfilter: nft_set_pipapo: allocate pcpu scratch maps on clone
  2022-01-05 13:19 [PATCH nf] netfilter: nft_set_pipapo: allocate pcpu scratch maps on clone Florian Westphal
  2022-01-05 15:20 ` Stefano Brivio
@ 2022-01-06  9:41 ` Pablo Neira Ayuso
  1 sibling, 0 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2022-01-06  9:41 UTC (permalink / raw)
  To: Florian Westphal; +Cc: netfilter-devel, sbrivio, etkaar

On Wed, Jan 05, 2022 at 02:19:54PM +0100, Florian Westphal 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.
> 
> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-01-06  9:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-05 13:19 [PATCH nf] netfilter: nft_set_pipapo: allocate pcpu scratch maps on clone Florian Westphal
2022-01-05 15:20 ` Stefano Brivio
2022-01-06  9:41 ` Pablo Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).