All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Florian Westphal <fw@strlen.de>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH nf] netfilter: nft_set_pipapo: reject mismatched sum of field_len with key length
Date: Tue, 28 Jan 2025 01:57:16 +0100	[thread overview]
Message-ID: <Z5grbJ3psaGWWH-0@calendula> (raw)
In-Reply-To: <20250128003012.GA29891@breakpoint.cc>

On Tue, Jan 28, 2025 at 01:30:12AM +0100, Florian Westphal wrote:
> Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> > The field length description provides the length of each separated key
> > fields in the concatenation. The set key length provides the total size
> > of the key aligned to 32-bits for the pipapo set backend. Reject with
> > EINVAL if the field length description and set key length provided by
> > userspace are inconsistent.
> > 
> > Fixes: 3c4287f62044 ("nf_tables: Add set type for arbitrary concatenation of ranges")
> > Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
> > ---
> >  net/netfilter/nft_set_pipapo.c | 7 +++++++
> >  1 file changed, 7 insertions(+)
> > 
> > diff --git a/net/netfilter/nft_set_pipapo.c b/net/netfilter/nft_set_pipapo.c
> > index 7be342b495f5..3b1a53e68989 100644
> > --- a/net/netfilter/nft_set_pipapo.c
> > +++ b/net/netfilter/nft_set_pipapo.c
> > @@ -2235,6 +2235,7 @@ static int nft_pipapo_init(const struct nft_set *set,
> >  	struct nft_pipapo_match *m;
> >  	struct nft_pipapo_field *f;
> >  	int err, i, field_count;
> > +	unsigned int len = 0;
> >  
> >  	BUILD_BUG_ON(offsetof(struct nft_pipapo_elem, priv) != 0);
> >  
> > @@ -2246,6 +2247,12 @@ static int nft_pipapo_init(const struct nft_set *set,
> >  	if (field_count > NFT_PIPAPO_MAX_FIELDS)
> >  		return -EINVAL;
> >  
> > +	for (i = 0; i < field_count; i++)
> > +		len += round_up(desc->field_len[i], sizeof(u32));
> > +
> > +	if (len != set->klen)
> > +		return -EINVAL;
> > +
> 
> I fail to grasp why nft_set_desc_concat() doesn't catch it:
> 
>         for (i = 0; i < desc->field_count; i++)
>                 num_regs += DIV_ROUND_UP(desc->field_len[i], sizeof(u32));
> 
>         key_num_regs = DIV_ROUND_UP(desc->klen, sizeof(u32));
>         if (key_num_regs != num_regs);	----> here....
>                 return -EINVAL;

This check is loose, I will post a v2 fixing up nft_set_desc_concat().

Thanks.

      reply	other threads:[~2025-01-28  0:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-27 23:49 [PATCH nf] netfilter: nft_set_pipapo: reject mismatched sum of field_len with key length Pablo Neira Ayuso
2025-01-28  0:30 ` Florian Westphal
2025-01-28  0:57   ` Pablo Neira Ayuso [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z5grbJ3psaGWWH-0@calendula \
    --to=pablo@netfilter.org \
    --cc=fw@strlen.de \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.