Linux Netfilter development
 help / color / mirror / Atom feed
From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [nft PATCH] Reject invalid chain priority values in user space
Date: Fri, 10 Mar 2023 12:05:04 +0100	[thread overview]
Message-ID: <ZAsO4JDiyBuSIYLf@orbyte.nwl.cc> (raw)
In-Reply-To: <ZAr0hLGgIpc1Cg9o@salvia>

On Fri, Mar 10, 2023 at 10:12:36AM +0100, Pablo Neira Ayuso wrote:
> On Fri, Mar 10, 2023 at 01:13:14AM +0100, Phil Sutter wrote:
> > The kernel doesn't accept nat type chains with a priority of -200 or
> > below. Catch this and provide a better error message than the kernel's
> > EOPNOTSUPP.
> > 
> > Signed-off-by: Phil Sutter <phil@nwl.cc>
> > ---
> >  src/evaluate.c | 10 ++++++++++
> >  1 file changed, 10 insertions(+)
> > 
> > diff --git a/src/evaluate.c b/src/evaluate.c
> > index d24f8b66b0de8..af4844c1ef6cc 100644
> > --- a/src/evaluate.c
> > +++ b/src/evaluate.c
> > @@ -4842,6 +4842,8 @@ static int chain_evaluate(struct eval_ctx *ctx, struct chain *chain)
> >  	}
> >  
> >  	if (chain->flags & CHAIN_F_BASECHAIN) {
> > +		int priority;
> > +
> >  		chain->hook.num = str2hooknum(chain->handle.family,
> >  					      chain->hook.name);
> >  		if (chain->hook.num == NF_INET_NUMHOOKS)
> > @@ -4854,6 +4856,14 @@ static int chain_evaluate(struct eval_ctx *ctx, struct chain *chain)
> >  			return __stmt_binary_error(ctx, &chain->priority.loc, NULL,
> >  						   "invalid priority expression %s in this context.",
> >  						   expr_name(chain->priority.expr));
> > +
> 
> maybe get this here to declutter the branch?
> 
>                 mpz_export_data(&priority, chain->priority.expr->value,
>                                 BYTEORDER_HOST_ENDIAN, sizeof(int)));

Will do. Initially I wanted to use mpz_get_si() but it expects a larger
data size. It even works if one casts the return value to int, but I
guess it won't anymore on Big Endian (and is a hack anyway).

> this is in basechain context, so it should be fine.

Yes, indeed. Also the call to evaluate_priority() ensures
chain->priority.expr is as expected.

> > +		if (!strcmp(chain->type.str, "nat") &&
> > +		    (mpz_export_data(&priority, chain->priority.expr->value,
> > +				    BYTEORDER_HOST_ENDIAN, sizeof(int))) &&
> > +		    priority <= -200)
> > +			return __stmt_binary_error(ctx, &chain->priority.loc, NULL,
> > +						   "Nat type chains must have a priority value above -200.");
>                                                     ^^^
> 
> I'd suggest lower case 'nat' which is what the user specifies in the
> chain declaration.

I'll rewrite the sentence.

> Thanks for addressing my feedback.

Thanks for the quick review!

      reply	other threads:[~2023-03-10 11:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-10  0:13 [nft PATCH] Reject invalid chain priority values in user space Phil Sutter
2023-03-10  9:12 ` Pablo Neira Ayuso
2023-03-10 11:05   ` Phil Sutter [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=ZAsO4JDiyBuSIYLf@orbyte.nwl.cc \
    --to=phil@nwl.cc \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox