netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Anders K. Pedersen | Cohaesio" <akp@cohaesio.com>
To: "netfilter-devel@vger.kernel.org"
	<netfilter-devel@vger.kernel.org>,
	"pablo@netfilter.org" <pablo@netfilter.org>
Subject: [PATCH nftables] Fix register allocation for EXPR_SET_ELEM
Date: Tue, 18 Oct 2016 03:40:01 +0000	[thread overview]
Message-ID: <1476762001.1038.70.camel@cohaesio.com> (raw)

From: Anders K. Pedersen <akp@cohaesio.com>

I noticed that while

 # nft add rule ip6 filter postrouting \
	flow table acct_out \{ meta iif . ip6 saddr timeout 600s counter \}

works, the opposite order for the concatenated expressions fails:

 # nft add rule ip6 filter postrouting \
	flow table acct_out \{ ip6 saddr . meta iif timeout 600s counter \}
 nft: netlink_linearize.c:634: netlink_gen_expr: Assertion `dreg < ctx->reg_low' failed.

I traced this down to get_register() and release_register(), where the
EXPR_CONCAT handling isn't hit, when it's embedded in EXPR_SET_ELEM, and
fixed it similarly to how EXPR_SET_ELEM is handled in netlink_gen_expr().

Signed-off-by: Anders K. Pedersen <akp@cohaesio.com>
---
 src/netlink_linearize.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/netlink_linearize.c b/src/netlink_linearize.c
--- a/src/netlink_linearize.c
+++ b/src/netlink_linearize.c
@@ -73,6 +73,9 @@ static void __release_register(struct netlink_linearize_ctx *ctx,
 static enum nft_registers get_register(struct netlink_linearize_ctx *ctx,
 				       const struct expr *expr)
 {
+	if (expr && expr->ops->type == EXPR_SET_ELEM)
+		return get_register(ctx, expr->key);
+
 	if (expr && expr->ops->type == EXPR_CONCAT)
 		return __get_register(ctx, expr->len);
 	else
@@ -82,6 +85,9 @@ static enum nft_registers get_register(struct netlink_linearize_ctx *ctx,
 static void release_register(struct netlink_linearize_ctx *ctx,
 			     const struct expr *expr)
 {
+	if (expr && expr->ops->type == EXPR_SET_ELEM)
+		return release_register(ctx, expr->key);
+
 	if (expr && expr->ops->type == EXPR_CONCAT)
 		__release_register(ctx, expr->len);
 	else

                 reply	other threads:[~2016-10-18  3:40 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1476762001.1038.70.camel@cohaesio.com \
    --to=akp@cohaesio.com \
    --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).