netfilter-devel.vger.kernel.org archive mirror
 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: [PATCH nft 3/3] netlink_linearize: skip set element expression in map statement key
Date: Tue, 26 Sep 2023 17:49:10 +0200	[thread overview]
Message-ID: <ZRL9dlPZbt9pVir5@orbyte.nwl.cc> (raw)
In-Reply-To: <20230926152500.30571-3-pablo@netfilter.org>

On Tue, Sep 26, 2023 at 05:25:00PM +0200, Pablo Neira Ayuso wrote:
> This fix is similar to 22d201010919 ("netlink_linearize: skip set element
> expression in set statement key") to fix map statement.
> 
> netlink_gen_map_stmt() relies on the map key, that is expressed as a set
> element. Use the set element key instead to skip the set element wrap,
> otherwise get_register() abort execution:
> 
>   nft: netlink_linearize.c:650: netlink_gen_expr: Assertion `dreg < ctx->reg_low' failed.
> 
> Reported-by: Luci Stanescu <luci@cnix.ro>
> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

This patch adds map stmt printing and parsing support to JSON, but not a
word about that in the commit message. Did this slip in by accident
(e.g.  'git commit -a')? Anyway, I think it should go into a separate
patch.

[...]
> diff --git a/src/netlink_linearize.c b/src/netlink_linearize.c
> index 53a318aa2e62..99ed9f387a81 100644
> --- a/src/netlink_linearize.c
> +++ b/src/netlink_linearize.c
> @@ -1585,13 +1585,13 @@ static void netlink_gen_map_stmt(struct netlink_linearize_ctx *ctx,
>  	int num_stmts = 0;
>  	struct stmt *this;
>  
> -	sreg_key = get_register(ctx, stmt->map.key);
> -	netlink_gen_expr(ctx, stmt->map.key, sreg_key);
> +	sreg_key = get_register(ctx, stmt->set.key->key);
> +	netlink_gen_expr(ctx, stmt->set.key->key, sreg_key);
>  
>  	sreg_data = get_register(ctx, stmt->map.data);
>  	netlink_gen_expr(ctx, stmt->map.data, sreg_data);
>  
> -	release_register(ctx, stmt->map.key);
> +	release_register(ctx, stmt->set.key->key);
>  	release_register(ctx, stmt->map.data);
>  
>  	nle = alloc_nft_expr("dynset");

Any particular reason why this doesn't just use stmt->map.key->key? The
first two fields in structs set_stmt and map_stmt are identical, so the
above works "by accident".

Cheers, Phil

  reply	other threads:[~2023-09-26 15:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-26 15:24 [PATCH nft 1/3] tests: py: add map support Pablo Neira Ayuso
2023-09-26 15:24 ` [PATCH nft 2/3] json: expose dynamic flag Pablo Neira Ayuso
2023-09-26 15:36   ` Phil Sutter
2023-09-26 15:25 ` [PATCH nft 3/3] netlink_linearize: skip set element expression in map statement key Pablo Neira Ayuso
2023-09-26 15:49   ` Phil Sutter [this message]
2023-09-26 15:58     ` Pablo Neira Ayuso

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=ZRL9dlPZbt9pVir5@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;
as well as URLs for NNTP newsgroup(s).