]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
rule: fix sym refcount assertion
authorFlorian Westphal <fw@strlen.de>
Mon, 15 Jan 2024 13:27:15 +0000 (14:27 +0100)
committerFlorian Westphal <fw@strlen.de>
Mon, 15 Jan 2024 17:21:41 +0000 (18:21 +0100)
Scope release must happen last.
afl provided a reproducer where policy is a define, because
scope is released too early we get:
nft: src/rule.c:559: scope_release: Assertion `sym->refcnt == 1' failed.

... because chain->policy is EXPR_SYMBOL.

Fixes: 627c451b2351 ("src: allow variables in the chain priority specification")
Signed-off-by: Florian Westphal <fw@strlen.de>
src/rule.c
tests/shell/testcases/bogons/nft-f/define_policy_assert [new file with mode: 0644]

index 172ba1f606e98c1436da8b3283a0abb1d6026bfc..342c43fb1b4b23737eae5ccd33b9c4748561a0d5 100644 (file)
@@ -729,7 +729,6 @@ void chain_free(struct chain *chain)
        list_for_each_entry_safe(rule, next, &chain->rules, list)
                rule_free(rule);
        handle_free(&chain->handle);
-       scope_release(&chain->scope);
        free_const(chain->type.str);
        expr_free(chain->dev_expr);
        for (i = 0; i < chain->dev_array_len; i++)
@@ -738,6 +737,11 @@ void chain_free(struct chain *chain)
        expr_free(chain->priority.expr);
        expr_free(chain->policy);
        free_const(chain->comment);
+
+       /* MUST be released after all expressions, they could
+        * hold refcounts.
+        */
+       scope_release(&chain->scope);
        free(chain);
 }
 
diff --git a/tests/shell/testcases/bogons/nft-f/define_policy_assert b/tests/shell/testcases/bogons/nft-f/define_policy_assert
new file mode 100644 (file)
index 0000000..f1e58b5
--- /dev/null
@@ -0,0 +1,3 @@
+chain y x { priority filter
+define p = foo
+policy $p