]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
evaluate: remove table from cache on delete table
authorPablo Neira Ayuso <pablo@netfilter.org>
Tue, 28 Jul 2020 17:32:44 +0000 (19:32 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 29 Jul 2020 21:40:58 +0000 (23:40 +0200)
The following ruleset crashes nft if loaded twice, via nft -ef:

 add table inet filter
 delete table inet filter

 table inet filter {
        chain input {
                type filter hook input priority filter; policy drop;
                iifname { "eth0" } counter accept
        }
 }

If the table contains anonymous sets, such as __set0, then delete + add
table might result in nft reusing the existing stale __set0 in the cache.
The problem is that nft gets confused and it reuses the existing stale
__set0 instead of the new anonymous set __set0 with the same name.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/evaluate.c
tests/shell/testcases/sets/0053echo_0 [new file with mode: 0755]
tests/shell/testcases/sets/dumps/0053echo_0.nft [new file with mode: 0644]

index 26d73959db583f649fd9bf56ee4e8ae4b6174f8a..a84e9609c1ff6e825ee9168ab24a493e88b16bea 100644 (file)
@@ -4172,6 +4172,18 @@ static int cmd_evaluate_add(struct eval_ctx *ctx, struct cmd *cmd)
        }
 }
 
+static void table_del_cache(struct eval_ctx *ctx, struct cmd *cmd)
+{
+       struct table *table;
+
+       table = table_lookup(&cmd->handle, &ctx->nft->cache);
+       if (!table)
+               return;
+
+       list_del(&table->list);
+       table_free(table);
+}
+
 static int cmd_evaluate_delete(struct eval_ctx *ctx, struct cmd *cmd)
 {
        switch (cmd->obj) {
@@ -4180,7 +4192,10 @@ static int cmd_evaluate_delete(struct eval_ctx *ctx, struct cmd *cmd)
        case CMD_OBJ_SET:
        case CMD_OBJ_RULE:
        case CMD_OBJ_CHAIN:
+               return 0;
        case CMD_OBJ_TABLE:
+               table_del_cache(ctx, cmd);
+               return 0;
        case CMD_OBJ_FLOWTABLE:
        case CMD_OBJ_COUNTER:
        case CMD_OBJ_QUOTA:
diff --git a/tests/shell/testcases/sets/0053echo_0 b/tests/shell/testcases/sets/0053echo_0
new file mode 100755 (executable)
index 0000000..6bb03c2
--- /dev/null
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+set -e
+
+EXPECTED="add table inet filter
+delete table inet filter
+
+table inet filter {
+        chain input {
+                type filter hook input priority filter; policy drop;
+                iifname { lo } ip saddr { 10.0.0.0/8 } ip daddr { 192.168.100.62 } tcp dport { 2001 } counter accept
+        }
+}
+"
+
+$NFT -ef - <<< "$EXPECTED"
diff --git a/tests/shell/testcases/sets/dumps/0053echo_0.nft b/tests/shell/testcases/sets/dumps/0053echo_0.nft
new file mode 100644 (file)
index 0000000..6a81663
--- /dev/null
@@ -0,0 +1,6 @@
+table inet filter {
+       chain input {
+               type filter hook input priority filter; policy drop;
+               iifname { "lo" } ip saddr { 10.0.0.0/8 } ip daddr { 192.168.100.62 } tcp dport { 2001 } counter packets 0 bytes 0 accept
+       }
+}