Skip to content

Commit

Permalink
Merge git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf
Browse files Browse the repository at this point in the history
Pablo Neira Ayuso says:

====================
Netfilter fixes for net

The following patchset contains Netfilter fixes for net:

1) Insufficient validation of element datatype and length in
   nft_setelem_parse_data(). At least commit 7d74026 updates
   maximum element data area up to 64 bytes when only 16 bytes
   where supported at the time. Support for larger element size
   came later in fdb9c40 though. Picking this older commit
   as Fixes: tag to be safe than sorry.

2) Memleak in pipapo destroy path, reproducible when transaction
   in aborted. This is already triggering in the existing netfilter
   test infrastructure since more recent new tests are covering this
   path.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Jul 3, 2022
2 parents 3d5a2a3 + 9827a0e commit 280e3a8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
9 changes: 8 additions & 1 deletion net/netfilter/nf_tables_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -5213,13 +5213,20 @@ static int nft_setelem_parse_data(struct nft_ctx *ctx, struct nft_set *set,
struct nft_data *data,
struct nlattr *attr)
{
u32 dtype;
int err;

err = nft_data_init(ctx, data, NFT_DATA_VALUE_MAXLEN, desc, attr);
if (err < 0)
return err;

if (desc->type != NFT_DATA_VERDICT && desc->len != set->dlen) {
if (set->dtype == NFT_DATA_VERDICT)
dtype = NFT_DATA_VERDICT;
else
dtype = NFT_DATA_VALUE;

if (dtype != desc->type ||
set->dlen != desc->len) {
nft_data_release(data, desc->type);
return -EINVAL;
}
Expand Down
48 changes: 33 additions & 15 deletions net/netfilter/nft_set_pipapo.c
Original file line number Diff line number Diff line change
Expand Up @@ -2124,6 +2124,32 @@ static int nft_pipapo_init(const struct nft_set *set,
return err;
}

/**
* nft_set_pipapo_match_destroy() - Destroy elements from key mapping array
* @set: nftables API set representation
* @m: matching data pointing to key mapping array
*/
static void nft_set_pipapo_match_destroy(const struct nft_set *set,
struct nft_pipapo_match *m)
{
struct nft_pipapo_field *f;
int i, r;

for (i = 0, f = m->f; i < m->field_count - 1; i++, f++)
;

for (r = 0; r < f->rules; r++) {
struct nft_pipapo_elem *e;

if (r < f->rules - 1 && f->mt[r + 1].e == f->mt[r].e)
continue;

e = f->mt[r].e;

nft_set_elem_destroy(set, e, true);
}
}

/**
* nft_pipapo_destroy() - Free private data for set and all committed elements
* @set: nftables API set representation
Expand All @@ -2132,26 +2158,13 @@ static void nft_pipapo_destroy(const struct nft_set *set)
{
struct nft_pipapo *priv = nft_set_priv(set);
struct nft_pipapo_match *m;
struct nft_pipapo_field *f;
int i, r, cpu;
int cpu;

m = rcu_dereference_protected(priv->match, true);
if (m) {
rcu_barrier();

for (i = 0, f = m->f; i < m->field_count - 1; i++, f++)
;

for (r = 0; r < f->rules; r++) {
struct nft_pipapo_elem *e;

if (r < f->rules - 1 && f->mt[r + 1].e == f->mt[r].e)
continue;

e = f->mt[r].e;

nft_set_elem_destroy(set, e, true);
}
nft_set_pipapo_match_destroy(set, m);

#ifdef NFT_PIPAPO_ALIGN
free_percpu(m->scratch_aligned);
Expand All @@ -2165,6 +2178,11 @@ static void nft_pipapo_destroy(const struct nft_set *set)
}

if (priv->clone) {
m = priv->clone;

if (priv->dirty)
nft_set_pipapo_match_destroy(set, m);

#ifdef NFT_PIPAPO_ALIGN
free_percpu(priv->clone->scratch_aligned);
#endif
Expand Down

0 comments on commit 280e3a8

Please sign in to comment.