Skip to contentSkip to conversation

tests: shell: bad_rule_graphs: add chain linked from different hooks

PATCH New Florian Westphal 1 participant 1 message Nov 25, 2025 netfilter

lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 tests: shell: bad_rule_graphs: add chain linked from different hooks

On a kernel with broken (never upstreamed) patch this fails with:

Accepted bad ruleset with jump from filter type to masquerade (3) and
Accepted bad ruleset with jump from prerouting to masquerade

... because bogus optimisation suppresses re-validation of 'n2', even though it becomes reachable from an invalid base chain (filter, but n2 has nat-only masquerade expression).

Another broken corner-case is validation of the different hook types:
When it becomes reachable from nat:prerouting in addition to the allowed nat:postrouting the validation step must fail.

Improve test coverage to ensure future optimisations catch this.

---
 .../testcases/transactions/bad_rule_graphs    | 68 +++++++++++++
 .../dumps/bad_rule_graphs.json-nft            | 98 +++++++++++++++++--
 .../transactions/dumps/bad_rule_graphs.nft    | 17 +++-
 3 files changed, 173 insertions(+), 10 deletions(-)
tests/shell/testcases/transactions/bad_rule_graphs +68 -0
index 53047c3c229f..1f36bad80792 100755
@@ -259,4 +259,72 @@ $NFT "add rule t c9 tcp dport 80 tproxy to :20000 meta mark set 1 accept"
 good_ruleset $? "add tproxy expression to c9"
 check_bad_expr
 
+$NFT -f - <<EOF
+table t {
+	chain n2 {
+		meta oifname "ppp*" masquerade
+	}
+
+	chain n1 {
+		ip saddr 192.168.0.0/16 jump n2
+	}
+
+	chain n0 { type nat hook postrouting priority 0;
+		jump n1
+	}
+}
+EOF
+good_ruleset $? "add nat skeleton"
+
+$NFT -f - <<EOF
+table t {
+	chain c2 {
+		jump n2
+	}
+}
+EOF
+bad_ruleset $? "jump from filter type to masquerade"
+
+$NFT flush chain t n2
+$NFT -f - <<EOF
+table t {
+	chain c2 {
+		jump n2
+	}
+
+	chain n2 { meta oifname "ppp0" masquerade; }
+}
+EOF
+bad_ruleset $? "jump from filter type to masquerade (2)"
+
+$NFT -f - <<EOF
+delete chain t c0
+delete chain t c1
+EOF
+good_ruleset $? "delete c1/c0"
+
+$NFT -f - <<EOF
+table t {
+	chain c1 { }
+
+	chain n2 { masquerade; }
+	chain n1 { goto n2; }
+
+	chain n0 { type nat hook postrouting priority 0;
+		goto n1
+	}
+
+	chain c0 { type filter hook input priority 0;
+		jump c1
+	}
+}
+EOF
+good_ruleset $? "add nat skeleton (2)"
+
+$NFT add rule t c1 goto n2
+bad_ruleset $? "jump from filter type to masquerade (3)"
+
+$NFT add chain 't invalid { type nat hook prerouting priority 0; goto n2; }'
+bad_ruleset $? "jump from prerouting to masquerade"
+
 exit $?
tests/shell/testcases/transactions/dumps/bad_rule_graphs.json-nft +90 -8

127 lines not on this page · raw message

tests/shell/testcases/transactions/dumps/bad_rule_graphs.nft +15 -2
index 3a5936500c6e..314809c3ddab 100644
@@ -18,9 +18,22 @@ table ip t {
 	chain c2 {
 	}
 
+	chain n2 {
+		masquerade
+	}
+
+	chain n1 {
+		ip saddr 192.168.0.0/16 jump n2
+		goto n2
+	}
+
+	chain n0 {
+		type nat hook postrouting priority filter; policy accept;
+		jump n1
+		goto n1
+	}
+
 	chain c1 {
-		jump c2
-		ip saddr vmap @m
 	}
 
 	chain c0 {
Signature · 1 line
2.51.2