Skip to contentSkip to conversation

evaluate: don't update cache for anonymous chains

PATCH Superseded Florian Westphal 2 participants 3 messages Mar 21, 2025 netfilter

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 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 such file or directory chain c {
Error: No symbol type information a b index 1 10.1.26.a

---
 src/evaluate.c                                            | 3 +++
 .../bogons/nft-f/null_deref_on_anon_chain_update_crash    | 8 ++++++++
 2 files changed, 11 insertions(+)
 create mode 100644 tests/shell/testcases/bogons/nft-f/null_deref_on_anon_chain_update_crash
src/evaluate.c +3 -0
index a27961193da5..09df7f158acc 100644
@@ -5371,6 +5371,9 @@ static int rule_cache_update(struct eval_ctx *ctx, enum cmd_ops op)
 	if (!table)
 		return table_not_found(ctx);
 
+	if (!rule->handle.chain.name)
+		return chain_not_found(ctx);
+
 	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 18 lines · Florian Westphal

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

Error: No such file or directory chain c {
Error: No symbol type information a b index 1 10.1.26.a

---
 src/evaluate.c                                            | 3 +++
 .../bogons/nft-f/null_deref_on_anon_chain_update_crash    | 8 ++++++++
 2 files changed, 11 insertions(+)
 create mode 100644 tests/shell/testcases/bogons/nft-f/null_deref_on_anon_chain_update_crash
src/evaluate.c +0 -0
index a27961193da5..09df7f158acc 100644

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

Quoted 5 lines
src/evaluate.c +2 -0
@@ -5371,6 +5371,9 @@ static int rule_cache_update(struct eval_ctx *ctx, enum cmd_ops op)
 	if (!table)
 		return table_not_found(ctx);
 
+	if (!rule->handle.chain.name)
+		return chain_not_found(ctx);

rule_cache_update() is invoked because of index, which toggle NFT_CACHE_UPDATE.

Maybe rule_cache_update() should be skipped for anonymous chain instead? ie. return 0.

Quoted 22 lines
src/evaluate.c +1 -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
author maintainer
#2 lore raw
Quoted 5 lines · Pablo Neira Ayuso

rule_cache_update() is invoked because of index, which toggle NFT_CACHE_UPDATE.

Maybe rule_cache_update() should be skipped for anonymous chain instead? ie. return 0.

Makes sense, i sent a v2 and added a comment wrt. anon chains being immutable.