From: Florian Westphal <fw@strlen.de>
To: <netfilter-devel@vger.kernel.org>
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH nft 2/4] src: tunnel src/dst must be a symbolic expression
Date: Thu, 16 Oct 2025 16:59:34 +0200 [thread overview]
Message-ID: <20251016145955.7785-3-fw@strlen.de> (raw)
In-Reply-To: <20251016145955.7785-1-fw@strlen.de>
Included bogons crash with segfault and assertion. After fix:
tunnel_with_garbage_dst:3:12-14: Error: syntax error, unexpected tcp, expecting string or quoted string or string with a trailing asterisk or '$'
ip saddr tcp dport { }
^^^
The parser change restricts the grammar to no longer allow this,
we would crash here because we enter payload evaluation path that
tries to insert a dependency into the rule, but we don't have one
(ctx->rule and ctx->stmt are NULL as expected here).
The eval stage change makes sure we will reject non-value symbols:
tunnel_with_anon_set_assert:1:12-31: Error: must be a value, not set
define s = { 1.2.3.4, 5.6.7.8 }
^^^^^^^^^^^^^^^^^^^^
Signed-off-by: Florian Westphal <fw@strlen.de>
---
src/evaluate.c | 20 +++++++++++++++++--
src/parser_bison.y | 8 ++++----
.../bogons/nft-f/tunnel_with_anon_set_assert | 8 ++++++++
.../bogons/nft-f/tunnel_with_garbage_dst | 5 +++++
4 files changed, 35 insertions(+), 6 deletions(-)
create mode 100644 tests/shell/testcases/bogons/nft-f/tunnel_with_anon_set_assert
create mode 100644 tests/shell/testcases/bogons/nft-f/tunnel_with_garbage_dst
diff --git a/src/evaluate.c b/src/evaluate.c
index ac482c83cce2..a5cc41819198 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -5851,19 +5851,35 @@ static int ct_timeout_evaluate(struct eval_ctx *ctx, struct obj *obj)
return 0;
}
+static int tunnel_evaluate_addr(struct eval_ctx *ctx, struct expr **exprp)
+{
+ struct expr *e;
+ int ret;
+
+ ret = expr_evaluate(ctx, exprp);
+ if (ret < 0)
+ return ret;
+
+ e = *exprp;
+ if (e->etype != EXPR_VALUE)
+ return expr_error(ctx->msgs, e, "must be a value, not %s", expr_name(e));
+
+ return 0;
+}
+
static int tunnel_evaluate(struct eval_ctx *ctx, struct obj *obj)
{
if (obj->tunnel.src) {
expr_set_context(&ctx->ectx, obj->tunnel.src->dtype,
obj->tunnel.src->dtype->size);
- if (expr_evaluate(ctx, &obj->tunnel.src) < 0)
+ if (tunnel_evaluate_addr(ctx, &obj->tunnel.src) < 0)
return -1;
}
if (obj->tunnel.dst) {
expr_set_context(&ctx->ectx, obj->tunnel.dst->dtype,
obj->tunnel.dst->dtype->size);
- if (expr_evaluate(ctx, &obj->tunnel.dst) < 0)
+ if (tunnel_evaluate_addr(ctx, &obj->tunnel.dst) < 0)
return -1;
if (obj->tunnel.src &&
diff --git a/src/parser_bison.y b/src/parser_bison.y
index 100a5c871e61..b63c7df18a35 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -5068,22 +5068,22 @@ tunnel_config : ID NUM
{
$<obj>0->tunnel.id = $2;
}
- | IP SADDR expr close_scope_ip
+ | IP SADDR symbol_expr close_scope_ip
{
$<obj>0->tunnel.src = $3;
datatype_set($3, &ipaddr_type);
}
- | IP DADDR expr close_scope_ip
+ | IP DADDR symbol_expr close_scope_ip
{
$<obj>0->tunnel.dst = $3;
datatype_set($3, &ipaddr_type);
}
- | IP6 SADDR expr close_scope_ip6
+ | IP6 SADDR symbol_expr close_scope_ip6
{
$<obj>0->tunnel.src = $3;
datatype_set($3, &ip6addr_type);
}
- | IP6 DADDR expr close_scope_ip6
+ | IP6 DADDR symbol_expr close_scope_ip6
{
$<obj>0->tunnel.dst = $3;
datatype_set($3, &ip6addr_type);
diff --git a/tests/shell/testcases/bogons/nft-f/tunnel_with_anon_set_assert b/tests/shell/testcases/bogons/nft-f/tunnel_with_anon_set_assert
new file mode 100644
index 000000000000..6f7b212aefef
--- /dev/null
+++ b/tests/shell/testcases/bogons/nft-f/tunnel_with_anon_set_assert
@@ -0,0 +1,8 @@
+define s = { 1.2.3.4, 5.6.7.8 }
+
+table netdev x {
+ tunnel t {
+ ip saddr $s
+ }
+ }
+
diff --git a/tests/shell/testcases/bogons/nft-f/tunnel_with_garbage_dst b/tests/shell/testcases/bogons/nft-f/tunnel_with_garbage_dst
new file mode 100644
index 000000000000..85eb992cec16
--- /dev/null
+++ b/tests/shell/testcases/bogons/nft-f/tunnel_with_garbage_dst
@@ -0,0 +1,5 @@
+table netdev x {
+ tunnel t {
+ ip saddr tcp dport { }
+ }
+}
--
2.51.0
next prev parent reply other threads:[~2025-10-16 15:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-16 14:59 [PATCH nft 0/4] nft tunnel mode parser/eval fixes Florian Westphal
2025-10-16 14:59 ` [PATCH nft 1/4] evaluate: tunnel: don't assume src is set Florian Westphal
2025-10-16 23:37 ` Fernando Fernandez Mancera
2025-10-16 14:59 ` Florian Westphal [this message]
2025-10-16 23:39 ` [PATCH nft 2/4] src: tunnel src/dst must be a symbolic expression Fernando Fernandez Mancera
2025-10-16 14:59 ` [PATCH nft 3/4] src: parser_bison: prevent multiple ip daddr/saddr definitions Florian Westphal
2025-10-16 23:41 ` Fernando Fernandez Mancera
2025-10-16 14:59 ` [PATCH nft 4/4] evaluate: reject tunnel section if another one is already present Florian Westphal
2025-10-16 23:44 ` Fernando Fernandez Mancera
2025-10-16 23:46 ` [PATCH nft 0/4] nft tunnel mode parser/eval fixes Fernando Fernandez Mancera
2025-10-17 9:39 ` Florian Westphal
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=20251016145955.7785-3-fw@strlen.de \
--to=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.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).