Skip to contentSkip to conversation

evaluate: don't update cache for anonymous chains

PATCH In review Florian Westphal 2 participants 2 messages Mar 21, 2025 – Mar 22, 2025 netfilter

lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH v2 1/1 evaluate: don't update cache for anonymous chains

Chain lookup needs a name, not a numerical id. After patch, loading bogon gives following errors:

Error: No symbol type information a b index 1 10.1.26.a

v2: Don't return an error, just make it a no-op (Pablo Neira Ayuso)

---
 src/evaluate.c                                            | 7 +++++++
 .../bogons/nft-f/null_deref_on_anon_chain_update_crash    | 8 ++++++++
 2 files changed, 15 insertions(+)
 create mode 100644 tests/shell/testcases/bogons/nft-f/null_deref_on_anon_chain_update_crash
src/evaluate.c +7 -0
index a27961193da5..26aa0ef53241 100644
@@ -5371,6 +5371,13 @@ static int rule_cache_update(struct eval_ctx *ctx, enum cmd_ops op)
 	if (!table)
 		return table_not_found(ctx);
 
+	/* chain is anonymous: no update needed, rules cannot be added
+	 * or removed from anon chains after the chain was committed to
+	 * kernel.
+	 */
+	if (!rule->handle.chain.name)
+		return 0;
+
 	chain = chain_cache_find(table, rule->handle.chain.name);
 	if (!chain)
 		return chain_not_found(ctx);
tests/shell/testcases/bogons/nft-f/null_deref_on_anon_chain_update_crash new file +8 -0
new file mode 100644
index 000000000000..310486c59ee0
@@ -0,0 +1,8 @@
+table ip f {
+        chain c {
+                jump {
+                        accept
+                }
+        }
+}
+a b index 1 10.1.26.a
Signature · 1 line
2.48.1
#1 lore raw
Quoted 1 line · Florian Westphal

Chain lookup needs a name, not a numerical id.

Thanks for this v2.

Quoted 5 lines

After patch, loading bogon gives following errors:

Error: No symbol type information a b index 1 10.1.26.a

v2: Don't return an error, just make it a no-op (Pablo Neira Ayuso)

Fixes c330152b7f77 ("src: support for implicit chain bindings")

I suggest to modify the comment below before you apply:

Quoted 12 lines
---
 src/evaluate.c                                            | 7 +++++++
 .../bogons/nft-f/null_deref_on_anon_chain_update_crash    | 8 ++++++++
 2 files changed, 15 insertions(+)
 create mode 100644 tests/shell/testcases/bogons/nft-f/null_deref_on_anon_chain_update_crash
src/evaluate.c +0 -0
index a27961193da5..26aa0ef53241 100644

src/evaluate.c static int rule_cache_update(struct eval_ctx *ctx, enum cmd_ops op) · line 5377

Quoted 7 lines
src/evaluate.c +4 -0
@@ -5371,6 +5371,13 @@ static int rule_cache_update(struct eval_ctx *ctx, enum cmd_ops op)
 	if (!table)
 		return table_not_found(ctx);
 
+	/* chain is anonymous: no update needed, rules cannot be added
+	 * or removed from anon chains after the chain was committed to
+	 * kernel.
+	 */

I suggest this comment:

        /* chain is anonymous, adding new rules via index is not supported. */

note that this bogon test you provide is actually putting everything in the same transaction. Your comment regarding kernel behaviour is correct, but it does not apply to rule_cache_update(). The issue is that rule_cache_update() does not need to update the cache if this chain is anonymous.

Thanks.

Quoted 24 lines
src/evaluate.c +3 -0
+	if (!rule->handle.chain.name)
+		return 0;
+
 	chain = chain_cache_find(table, rule->handle.chain.name);
 	if (!chain)
 		return chain_not_found(ctx);
tests/shell/testcases/bogons/nft-f/null_deref_on_anon_chain_update_crash new file +8 -0
new file mode 100644
index 000000000000..310486c59ee0
@@ -0,0 +1,8 @@
+table ip f {
+        chain c {
+                jump {
+                        accept
+                }
+        }
+}
+a b index 1 10.1.26.a
Signature · 1 line
2.48.1