]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
netlink_delinearize: only remove protocol if equal cmp is used
authorFlorian Westphal <fw@strlen.de>
Wed, 27 Jan 2016 01:53:51 +0000 (02:53 +0100)
committerFlorian Westphal <fw@strlen.de>
Wed, 27 Jan 2016 15:39:41 +0000 (16:39 +0100)
Check for OP_EQ before removing a dependency, else we may zap wrong one,
changing the meaning of the rule.

Listing without patch:
ip protocol udp udp dport ssh
ip protocol udp udp dport ssh
counter packets 1 bytes 308 ip protocol udp udp dport ssh

With patch:
ip protocol != tcp udp dport ssh
ip protocol != udp udp dport ssh
ip protocol != tcp counter packets 1 bytes 308 udp dport ssh

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/netlink_delinearize.c
tests/py/ip/tcp.t [new file with mode: 0644]
tests/py/ip/tcp.t.payload [new file with mode: 0644]

index 76d598ca8ada325fae74fcbaa16c199c00bae209..2732c9657f944e0961e4a9a1884118e40c43a0df 100644 (file)
@@ -1042,6 +1042,7 @@ static void payload_match_expand(struct rule_pp_ctx *ctx,
                 * payload expression.
                 */
                if (ctx->pbase == PROTO_BASE_INVALID &&
+                   expr->op == OP_EQ &&
                    left->flags & EXPR_F_PROTOCOL) {
                        unsigned int proto = mpz_get_be16(tmp->value);
                        const struct proto_desc *desc, *next;
diff --git a/tests/py/ip/tcp.t b/tests/py/ip/tcp.t
new file mode 100644 (file)
index 0000000..4dcfcb6
--- /dev/null
@@ -0,0 +1,6 @@
+:input;type filter hook input priority 0
+
+*ip;test-ip;input
+
+ip protocol tcp tcp dport ssh accept;ok;tcp dport 22 accept
+ip protocol ne tcp udp dport ssh accept;ok;ip protocol != 6 udp dport 22 accept
diff --git a/tests/py/ip/tcp.t.payload b/tests/py/ip/tcp.t.payload
new file mode 100644 (file)
index 0000000..ed0dcc8
--- /dev/null
@@ -0,0 +1,18 @@
+# ip protocol tcp tcp dport ssh accept
+ip test-ip input
+  [ payload load 1b @ network header + 9 => reg 1 ]
+  [ cmp eq reg 1 0x00000006 ]
+  [ payload load 2b @ transport header + 2 => reg 1 ]
+  [ cmp eq reg 1 0x00001600 ]
+  [ immediate reg 0 accept ]
+
+# ip protocol ne tcp udp dport ssh accept
+ip test-ip input
+  [ payload load 1b @ network header + 9 => reg 1 ]
+  [ cmp neq reg 1 0x00000006 ]
+  [ payload load 1b @ network header + 9 => reg 1 ]
+  [ cmp eq reg 1 0x00000011 ]
+  [ payload load 2b @ transport header + 2 => reg 1 ]
+  [ cmp eq reg 1 0x00001600 ]
+  [ immediate reg 0 accept ]
+