All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH nft] evaluate: set key byteorder when evaluating mapping
@ 2026-11-24 23:53 Pablo Neira Ayuso
  2026-11-25 10:31 ` Phil Sutter
  0 siblings, 1 reply; 2+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-24 23:53 UTC (permalink / raw)
  To: netfilter-devel; +Cc: phil

set->key->dtype is TYPE_INTEGER (see integer_type definition) which uses
BYTEORDER_INVALID by default, this is used to set up the context for
parsing the symbols in the mapping. Set explicit byteorder context to
address this bug.

Fixes: 144d97e151adb ("src: normalize set element with EXPR_MAPPING")
Reported-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 src/evaluate.c                                |   3 +-
 .../maps/dumps/nat_addr_port.json-nft         | 134 ++++++++++++++++++
 .../testcases/maps/dumps/nat_addr_port.nft    |  18 +++
 tests/shell/testcases/maps/nat_addr_port      |  12 ++
 4 files changed, 166 insertions(+), 1 deletion(-)

diff --git a/src/evaluate.c b/src/evaluate.c
index 8ce37e57a836..61372dd80cdd 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -2393,7 +2393,8 @@ static int expr_evaluate_mapping(struct eval_ctx *ctx, struct expr **expr)
 	if (!set_is_map(set->flags))
 		return set_error(ctx, set, "set is not a map");
 
-	expr_set_context(&ctx->ectx, set->key->dtype, set->key->len);
+	__expr_set_context(&ctx->ectx, set->key->dtype, set->key->byteorder, set->key->len, 0);
+
 	ctx->ectx.key = key;
 
 	if (expr_evaluate(ctx, &mapping->left) < 0)
diff --git a/tests/shell/testcases/maps/dumps/nat_addr_port.json-nft b/tests/shell/testcases/maps/dumps/nat_addr_port.json-nft
index 216761c6f150..288178710387 100644
--- a/tests/shell/testcases/maps/dumps/nat_addr_port.json-nft
+++ b/tests/shell/testcases/maps/dumps/nat_addr_port.json-nft
@@ -65,6 +65,42 @@
         ]
       }
     },
+    {
+      "map": {
+        "family": "ip",
+        "name": "w",
+        "table": "ipfoo",
+        "type": {
+          "typeof": {
+            "numgen": {
+              "mode": "inc",
+              "mod": 3,
+              "offset": 0
+            }
+          }
+        },
+        "handle": 0,
+        "map": "mark",
+        "elem": [
+          [
+            0,
+            9
+          ],
+          [
+            1,
+            8
+          ],
+          [
+            2,
+            7
+          ],
+          [
+            3,
+            6
+          ]
+        ]
+      }
+    },
     {
       "map": {
         "family": "ip",
@@ -411,6 +447,37 @@
         ]
       }
     },
+    {
+      "rule": {
+        "family": "ip",
+        "table": "ipfoo",
+        "chain": "c",
+        "handle": 0,
+        "expr": [
+          {
+            "mangle": {
+              "key": {
+                "meta": {
+                  "key": "mark"
+                }
+              },
+              "value": {
+                "map": {
+                  "key": {
+                    "numgen": {
+                      "mode": "inc",
+                      "mod": 2000,
+                      "offset": 0
+                    }
+                  },
+                  "data": "@w"
+                }
+              }
+            }
+          }
+        ]
+      }
+    },
     {
       "table": {
         "family": "ip6",
@@ -469,6 +536,42 @@
         ]
       }
     },
+    {
+      "map": {
+        "family": "ip6",
+        "name": "w",
+        "table": "ip6foo",
+        "type": {
+          "typeof": {
+            "numgen": {
+              "mode": "inc",
+              "mod": 3,
+              "offset": 0
+            }
+          }
+        },
+        "handle": 0,
+        "map": "mark",
+        "elem": [
+          [
+            0,
+            9
+          ],
+          [
+            1,
+            8
+          ],
+          [
+            2,
+            7
+          ],
+          [
+            3,
+            6
+          ]
+        ]
+      }
+    },
     {
       "map": {
         "family": "ip6",
@@ -788,6 +891,37 @@
         ]
       }
     },
+    {
+      "rule": {
+        "family": "ip6",
+        "table": "ip6foo",
+        "chain": "c",
+        "handle": 0,
+        "expr": [
+          {
+            "mangle": {
+              "key": {
+                "meta": {
+                  "key": "mark"
+                }
+              },
+              "value": {
+                "map": {
+                  "key": {
+                    "numgen": {
+                      "mode": "inc",
+                      "mod": 2000,
+                      "offset": 0
+                    }
+                  },
+                  "data": "@w"
+                }
+              }
+            }
+          }
+        ]
+      }
+    },
     {
       "table": {
         "family": "inet",
diff --git a/tests/shell/testcases/maps/dumps/nat_addr_port.nft b/tests/shell/testcases/maps/dumps/nat_addr_port.nft
index f4a952e9db42..24315b2981f5 100644
--- a/tests/shell/testcases/maps/dumps/nat_addr_port.nft
+++ b/tests/shell/testcases/maps/dumps/nat_addr_port.nft
@@ -7,6 +7,14 @@ table ip ipfoo {
 		typeof numgen inc mod 2 : ip daddr . tcp dport
 	}
 
+	map w {
+		typeof numgen inc mod 3 : meta mark
+		elements = { 0 : 0x00000009,
+			     1 : 0x00000008,
+			     2 : 0x00000007,
+			     3 : 0x00000006 }
+	}
+
 	map x {
 		type ipv4_addr : ipv4_addr
 	}
@@ -32,6 +40,7 @@ table ip ipfoo {
 		meta l4proto 6 dnat to 10.2.3.4:4242
 		dnat to numgen inc mod 2 map @t1
 		meta l4proto 6 dnat ip to numgen inc mod 2 map @t2
+		meta mark set numgen inc mod 2000 map @w
 	}
 }
 table ip6 ip6foo {
@@ -43,6 +52,14 @@ table ip6 ip6foo {
 		typeof numgen inc mod 2 : ip6 daddr . tcp dport
 	}
 
+	map w {
+		typeof numgen inc mod 3 : meta mark
+		elements = { 0 : 0x00000009,
+			     1 : 0x00000008,
+			     2 : 0x00000007,
+			     3 : 0x00000006 }
+	}
+
 	map x {
 		type ipv6_addr : ipv6_addr
 	}
@@ -66,6 +83,7 @@ table ip6 ip6foo {
 		meta l4proto 6 dnat to [fd00:10:244::4]:6443
 		dnat to numgen inc mod 2 map @t1
 		meta l4proto 6 dnat ip6 to numgen inc mod 2 map @t2
+		meta mark set numgen inc mod 2000 map @w
 	}
 }
 table inet inetfoo {
diff --git a/tests/shell/testcases/maps/nat_addr_port b/tests/shell/testcases/maps/nat_addr_port
index 5f6ff1c49cc0..b1a458d601c6 100755
--- a/tests/shell/testcases/maps/nat_addr_port
+++ b/tests/shell/testcases/maps/nat_addr_port
@@ -11,6 +11,11 @@ table ip ipfoo {
 		typeof numgen inc mod 2 : ip daddr . tcp dport
 	}
 
+	map w {
+		typeof numgen inc mod 3 : meta mark
+		elements = { 0 : 9, 1 : 8, 2 : 7, 3 : 6 }
+	}
+
 	map x {
 		type ipv4_addr : ipv4_addr
 	}
@@ -34,6 +39,7 @@ table ip ipfoo {
 		meta l4proto tcp dnat ip addr . port to 10.2.3.4 . 4242
 		dnat ip to numgen inc mod 2 map @t1
 		meta l4proto tcp dnat ip addr . port to numgen inc mod 2 map @t2
+		meta mark set numgen inc mod 2000 map @w
 	}
 }
 EOF
@@ -55,6 +61,11 @@ table ip6 ip6foo {
 		typeof numgen inc mod 2 : ip6 daddr . tcp dport
 	}
 
+	map w {
+		typeof numgen inc mod 3 : meta mark
+		elements = { 0 : 9, 1 : 8, 2 : 7, 3 : 6 }
+	}
+
 	map x {
 		type ipv6_addr : ipv6_addr
 	}
@@ -76,6 +87,7 @@ table ip6 ip6foo {
 		meta l4proto tcp dnat ip6 addr . port to fd00:10:244::4 . 6443
 		dnat ip6 to numgen inc mod 2 map @t1
 		meta l4proto tcp dnat ip6 addr . port to numgen inc mod 2 map @t2
+		meta mark set numgen inc mod 2000 map @w
 	}
 }
 EOF
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH nft] evaluate: set key byteorder when evaluating mapping
  2026-11-24 23:53 [PATCH nft] evaluate: set key byteorder when evaluating mapping Pablo Neira Ayuso
@ 2026-11-25 10:31 ` Phil Sutter
  0 siblings, 0 replies; 2+ messages in thread
From: Phil Sutter @ 2026-11-25 10:31 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel

On Wed, Nov 25, 2026 at 12:53:06AM +0100, Pablo Neira Ayuso wrote:
> set->key->dtype is TYPE_INTEGER (see integer_type definition) which uses
> BYTEORDER_INVALID by default, this is used to set up the context for
> parsing the symbols in the mapping. Set explicit byteorder context to
> address this bug.
> 
> Fixes: 144d97e151adb ("src: normalize set element with EXPR_MAPPING")
> Reported-by: Phil Sutter <phil@nwl.cc>
> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

Tested-by: Phil Sutter <phil@nwl.cc>

Thanks for the quick fix, Pablo!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-25 10:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 23:53 [PATCH nft] evaluate: set key byteorder when evaluating mapping Pablo Neira Ayuso
2026-11-25 10:31 ` Phil Sutter

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.