rule: fix sym refcount assertion
Florian Westphal
maintainerPATCH 1/1 rule: fix sym refcount assertion
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 <[email protected]>
--- src/rule.c | 6 +++++- tests/shell/testcases/bogons/nft-f/define_policy_assert | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 tests/shell/testcases/bogons/nft-f/define_policy_assert
src/rule.c +5 -1
@@ -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); }
tests/shell/testcases/bogons/nft-f/define_policy_assert new file +3 -0
@@ -0,0 +1,3 @@ +chain y x { priority filter +define p = foo +policy $p
Signature · 1 line
2.43.0