]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
flowtable: Make parsing a little more robust
authorPhil Sutter <phil@nwl.cc>
Mon, 19 Mar 2018 17:02:05 +0000 (18:02 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 20 Mar 2018 12:07:39 +0000 (13:07 +0100)
It was surprisingly easy to crash nft with invalid syntax in 'add
flowtable' command. Catch at least three possible ways (illustrated in
provided test case) by making evaluation phase survive so that bison
gets a chance to complain.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/evaluate.c
src/expression.c
tests/shell/testcases/flowtable/0006segfault_0 [new file with mode: 0755]

index 6ae94b0f56de5109903518a077ac20b161879da4..d224f0f3c2c165edc951dc51986702b97fddaf62 100644 (file)
@@ -2838,6 +2838,9 @@ static int flowtable_evaluate(struct eval_ctx *ctx, struct flowtable *ft)
        if (ft->hooknum == NF_INET_NUMHOOKS)
                return chain_error(ctx, ft, "invalid hook %s", ft->hookstr);
 
+       if (!ft->dev_expr)
+               return chain_error(ctx, ft, "Unbound flowtable not allowed (must specify devices)");
+
        return 0;
 }
 
@@ -2874,6 +2877,9 @@ static int rule_evaluate(struct eval_ctx *ctx, struct rule *rule)
 
 static uint32_t str2hooknum(uint32_t family, const char *hook)
 {
+       if (!hook)
+               return NF_INET_NUMHOOKS;
+
        switch (family) {
        case NFPROTO_IPV4:
        case NFPROTO_BRIDGE:
index 5f023d2ad88e778acb39b505a353f2f829edc149..e698b14c969c79e63b31cf1848e550d88ec48738 100644 (file)
@@ -65,7 +65,7 @@ void expr_free(struct expr *expr)
                return;
        if (--expr->refcnt > 0)
                return;
-       if (expr->ops->destroy)
+       if (expr->ops && expr->ops->destroy)
                expr->ops->destroy(expr);
        xfree(expr);
 }
diff --git a/tests/shell/testcases/flowtable/0006segfault_0 b/tests/shell/testcases/flowtable/0006segfault_0
new file mode 100755 (executable)
index 0000000..de590b7
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+# Make sure nft does not segfault when given invalid syntax in 'add flowtable' commands.
+
+$NFT add table ip t
+
+$NFT add flowtable ip t f { hook ingress priority 10\; devices = { lo } }
+[[ $? -eq 1 ]] || exit 1
+
+$NFT add flowtable ip t f { hook ingress\; priority 10\; }
+[[ $? -eq 1 ]] || exit 1
+
+$NFT add flowtable ip t f { hook ingress priority 10\; }
+[[ $? -eq 1 ]] || exit 1