Blame SOURCES/0034-evaluate-missing-datatype-definition-in-implicit_set.patch

acfc56
From 3193f74613b16a42d7784452ebf4d53ccd33b887 Mon Sep 17 00:00:00 2001
acfc56
From: Phil Sutter <psutter@redhat.com>
acfc56
Date: Tue, 12 Jan 2021 10:34:35 +0100
acfc56
Subject: [PATCH] evaluate: missing datatype definition in
acfc56
 implicit_set_declaration()
acfc56
acfc56
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1877022
acfc56
Upstream Status: nftables commit 54eb1e16cc478
acfc56
acfc56
commit 54eb1e16cc4787906fe8206858f0ea0bfb9c1209
acfc56
Author: Pablo Neira Ayuso <pablo@netfilter.org>
acfc56
Date:   Sun Jun 7 15:23:21 2020 +0200
acfc56
acfc56
    evaluate: missing datatype definition in implicit_set_declaration()
acfc56
acfc56
    set->data from implicit_set_declaration(), otherwise, set_evaluation()
acfc56
    bails out with:
acfc56
acfc56
     # nft -f /etc/nftables/inet-filter.nft
acfc56
     /etc/nftables/inet-filter.nft:8:32-54: Error: map definition does not specify
acfc56
     mapping data type
acfc56
                    tcp dport vmap { 22 : jump ssh_input }
acfc56
                                   ^^^^^^^^^^^^^^^^^^^^^^^
acfc56
     /etc/nftables/inet-filter.nft:13:26-52: Error: map definition does not specify
acfc56
     mapping data type
acfc56
                     iif vmap { "eth0" : jump wan_input }
acfc56
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
acfc56
acfc56
    Add a test to cover this case.
acfc56
acfc56
    Fixes: 7aa08d45031e ("evaluate: Perform set evaluation on implicitly declared (anonymous) sets")
acfc56
    Closes: https://bugzilla.kernel.org/show_bug.cgi?id=208093
acfc56
    Reviewed-by: Stefano Brivio <sbrivio@redhat.com>
acfc56
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
acfc56
---
8ff5ad
 src/evaluate.c                              | 22 +++++++++++----------
8ff5ad
 tests/shell/testcases/maps/0009vmap_0       | 19 ++++++++++++++++++
8ff5ad
 tests/shell/testcases/maps/dumps/0009vmap_0 | 13 ++++++++++++
acfc56
 3 files changed, 44 insertions(+), 10 deletions(-)
acfc56
 create mode 100755 tests/shell/testcases/maps/0009vmap_0
acfc56
 create mode 100644 tests/shell/testcases/maps/dumps/0009vmap_0
acfc56
acfc56
diff --git a/src/evaluate.c b/src/evaluate.c
acfc56
index fc45cef..a966ed4 100644
acfc56
--- a/src/evaluate.c
acfc56
+++ b/src/evaluate.c
acfc56
@@ -79,6 +79,7 @@ static int set_evaluate(struct eval_ctx *ctx, struct set *set);
acfc56
 static struct expr *implicit_set_declaration(struct eval_ctx *ctx,
acfc56
 					     const char *name,
acfc56
 					     struct expr *key,
acfc56
+					     struct expr *data,
acfc56
 					     struct expr *expr)
acfc56
 {
acfc56
 	struct cmd *cmd;
acfc56
@@ -92,6 +93,7 @@ static struct expr *implicit_set_declaration(struct eval_ctx *ctx,
acfc56
 	set->flags	= NFT_SET_ANONYMOUS | expr->set_flags;
acfc56
 	set->handle.set.name = xstrdup(name);
acfc56
 	set->key	= key;
acfc56
+	set->data	= data;
acfc56
 	set->init	= expr;
acfc56
 	set->automerge	= set->flags & NFT_SET_INTERVAL;
acfc56
 
acfc56
@@ -1387,7 +1389,7 @@ static int expr_evaluate_map(struct eval_ctx *ctx, struct expr **expr)
acfc56
 	struct expr_ctx ectx = ctx->ectx;
acfc56
 	struct expr *map = *expr, *mappings;
acfc56
 	const struct datatype *dtype;
acfc56
-	struct expr *key;
acfc56
+	struct expr *key, *data;
acfc56
 
acfc56
 	expr_set_context(&ctx->ectx, NULL, 0);
acfc56
 	if (expr_evaluate(ctx, &map->map) < 0)
acfc56
@@ -1406,15 +1408,14 @@ static int expr_evaluate_map(struct eval_ctx *ctx, struct expr **expr)
acfc56
 					  ctx->ectx.byteorder,
acfc56
 					  ctx->ectx.len, NULL);
acfc56
 
acfc56
+		dtype = set_datatype_alloc(ectx.dtype, ectx.byteorder);
acfc56
+		data = constant_expr_alloc(&netlink_location, dtype,
acfc56
+					   dtype->byteorder, ectx.len, NULL);
acfc56
+
acfc56
 		mappings = implicit_set_declaration(ctx, "__map%d",
acfc56
-						    key,
acfc56
+						    key, data,
acfc56
 						    mappings);
acfc56
 
acfc56
-		dtype = set_datatype_alloc(ectx.dtype, ectx.byteorder);
acfc56
-
acfc56
-		mappings->set->data = constant_expr_alloc(&netlink_location,
acfc56
-							  dtype, dtype->byteorder,
acfc56
-							  ectx.len, NULL);
acfc56
 		if (ectx.len && mappings->set->data->len != ectx.len)
acfc56
 			BUG("%d vs %d\n", mappings->set->data->len, ectx.len);
acfc56
 
acfc56
@@ -1857,7 +1858,8 @@ static int expr_evaluate_relational(struct eval_ctx *ctx, struct expr **expr)
acfc56
 		case EXPR_SET:
acfc56
 			right = rel->right =
acfc56
 				implicit_set_declaration(ctx, "__set%d",
acfc56
-							 expr_get(left), right);
acfc56
+							 expr_get(left), NULL,
acfc56
+							 right);
acfc56
 			/* fall through */
acfc56
 		case EXPR_SET_REF:
acfc56
 			/* Data for range lookups needs to be in big endian order */
acfc56
@@ -2335,7 +2337,7 @@ static int stmt_evaluate_meter(struct eval_ctx *ctx, struct stmt *stmt)
acfc56
 		set->set_flags |= NFT_SET_TIMEOUT;
acfc56
 
acfc56
 	setref = implicit_set_declaration(ctx, stmt->meter.name,
acfc56
-					  expr_get(key), set);
acfc56
+					  expr_get(key), NULL, set);
acfc56
 
acfc56
 	setref->set->desc.size = stmt->meter.size;
acfc56
 	stmt->meter.set = setref;
acfc56
@@ -3173,7 +3175,7 @@ static int stmt_evaluate_objref_map(struct eval_ctx *ctx, struct stmt *stmt)
acfc56
 					  ctx->ectx.len, NULL);
acfc56
 
acfc56
 		mappings = implicit_set_declaration(ctx, "__objmap%d",
acfc56
-						    key, mappings);
acfc56
+						    key, NULL, mappings);
acfc56
 		mappings->set->objtype  = stmt->objref.type;
acfc56
 
acfc56
 		map->mappings = mappings;
acfc56
diff --git a/tests/shell/testcases/maps/0009vmap_0 b/tests/shell/testcases/maps/0009vmap_0
acfc56
new file mode 100755
acfc56
index 0000000..7627c81
acfc56
--- /dev/null
acfc56
+++ b/tests/shell/testcases/maps/0009vmap_0
acfc56
@@ -0,0 +1,19 @@
acfc56
+#!/bin/bash
acfc56
+
acfc56
+set -e
acfc56
+
acfc56
+EXPECTED="table inet filter {
acfc56
+        chain ssh_input {
acfc56
+        }
acfc56
+
acfc56
+        chain wan_input {
acfc56
+                tcp dport vmap { 22 : jump ssh_input }
acfc56
+        }
acfc56
+
acfc56
+        chain prerouting {
acfc56
+                type filter hook prerouting priority -300; policy accept;
acfc56
+                iif vmap { "lo" : jump wan_input }
acfc56
+        }
acfc56
+}"
acfc56
+
acfc56
+$NFT -f - <<< "$EXPECTED"
acfc56
diff --git a/tests/shell/testcases/maps/dumps/0009vmap_0 b/tests/shell/testcases/maps/dumps/0009vmap_0
acfc56
new file mode 100644
acfc56
index 0000000..540a8af
acfc56
--- /dev/null
acfc56
+++ b/tests/shell/testcases/maps/dumps/0009vmap_0
acfc56
@@ -0,0 +1,13 @@
acfc56
+table inet filter {
acfc56
+	chain ssh_input {
acfc56
+	}
acfc56
+
acfc56
+	chain wan_input {
acfc56
+		tcp dport vmap { 22 : jump ssh_input }
acfc56
+	}
acfc56
+
acfc56
+	chain prerouting {
acfc56
+		type filter hook prerouting priority -300; policy accept;
acfc56
+		iif vmap { "lo" : jump wan_input }
acfc56
+	}
acfc56
+}
acfc56
-- 
8ff5ad
2.31.1
acfc56