Skip to contentSkip to conversation

rule: return error if table does not exist

PATCH In review Florian Westphal 2 participants 2 messages Mar 20, 2025 netfilter

lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 rule: return error if table does not exist

The bogon triggers segfault due to NULL dereference. Error out and set errno to ENOENT; caller uses strerror() in the errmsg.

After fix, loading reproducer results in:
/tmp/A:2:1-18: Error: Could not process rule: No such file or directory list table inet p
^^^^^^^^^^^^^^^^^^

---
 src/rule.c                                                | 8 +++++++-
 .../testcases/bogons/nft-f/list_a_deleted_table_crash     | 3 +++
 2 files changed, 10 insertions(+), 1 deletion(-)
 create mode 100644 tests/shell/testcases/bogons/nft-f/list_a_deleted_table_crash
src/rule.c +7 -1
index 3edfa4715853..00fbbc4c080a 100644
@@ -2380,10 +2380,16 @@ static int do_command_list(struct netlink_ctx *ctx, struct cmd *cmd)
 	if (nft_output_json(&ctx->nft->output))
 		return do_command_list_json(ctx, cmd);
 
-	if (cmd->handle.table.name != NULL)
+	if (cmd->handle.table.name != NULL) {
 		table = table_cache_find(&ctx->nft->cache.table_cache,
 					 cmd->handle.table.name,
 					 cmd->handle.family);
+		if (!table) {
+			errno = ENOENT;
+			return -1;
+		}
+	}
+
 	switch (cmd->obj) {
 	case CMD_OBJ_TABLE:
 		if (!cmd->handle.table.name)
tests/shell/testcases/bogons/nft-f/list_a_deleted_table_crash new file +3 -0
new file mode 100644
index 000000000000..b802430bb6cc
@@ -0,0 +1,3 @@
+table inet p
+list table inet p
+delete  table inet p
Signature · 1 line
2.48.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Florian Westphal

The bogon triggers segfault due to NULL dereference. Error out and set errno to ENOENT; caller uses strerror() in the errmsg.

After fix, loading reproducer results in:
/tmp/A:2:1-18: Error: Could not process rule: No such file or directory list table inet p
^^^^^^^^^^^^^^^^^^

Thanks.

Quoted 41 lines
---
 src/rule.c                                                | 8 +++++++-
 .../testcases/bogons/nft-f/list_a_deleted_table_crash     | 3 +++
 2 files changed, 10 insertions(+), 1 deletion(-)
 create mode 100644 tests/shell/testcases/bogons/nft-f/list_a_deleted_table_crash
src/rule.c +7 -1
index 3edfa4715853..00fbbc4c080a 100644
@@ -2380,10 +2380,16 @@ static int do_command_list(struct netlink_ctx *ctx, struct cmd *cmd)
 	if (nft_output_json(&ctx->nft->output))
 		return do_command_list_json(ctx, cmd);
 
-	if (cmd->handle.table.name != NULL)
+	if (cmd->handle.table.name != NULL) {
 		table = table_cache_find(&ctx->nft->cache.table_cache,
 					 cmd->handle.table.name,
 					 cmd->handle.family);
+		if (!table) {
+			errno = ENOENT;
+			return -1;
+		}
+	}
+
 	switch (cmd->obj) {
 	case CMD_OBJ_TABLE:
 		if (!cmd->handle.table.name)
tests/shell/testcases/bogons/nft-f/list_a_deleted_table_crash new file +3 -0
new file mode 100644
index 000000000000..b802430bb6cc
@@ -0,0 +1,3 @@
+table inet p
+list table inet p
+delete  table inet p
Signature · 1 line
2.48.1