Skip to content

Commit

Permalink
netfilter: nft_set_pipapo: allocate pcpu scratch maps on clone
Browse files Browse the repository at this point in the history
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: 3c4287f ("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>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
  • Loading branch information
Florian Westphal authored and ummakynes committed Jan 6, 2022
1 parent 4e1860a commit 23c5426
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions net/netfilter/nft_set_pipapo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 23c5426

Please sign in to comment.