Skip to contentSkip to conversation

cache: don't crash when filter is NULL

PATCH In review Florian Westphal 2 participants 3 messages Apr 1, 2025 netfilter

lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 cache: don't crash when filter is NULL

a delete request will cause a crash in obj_cache_dump, move the deref into the filter block.

Fixes dbff26bfba83 ("cache: consolidate reset command")
---
 src/cache.c                                                 | 6 ++++--
 .../testcases/bogons/nft-f/delete_nonexistant_object_crash  | 1 +
 2 files changed, 5 insertions(+), 2 deletions(-)
 create mode 100644 tests/shell/testcases/bogons/nft-f/delete_nonexistant_object_crash
src/cache.c +4 -2
index b75a5bf3283c..c0d96bd14a80 100644
@@ -902,6 +902,7 @@ static struct nftnl_obj_list *obj_cache_dump(struct netlink_ctx *ctx,
 	int family = NFPROTO_UNSPEC;
 	const char *table = NULL;
 	const char *obj = NULL;
+	bool reset = false;
 	bool dump = true;
 
 	if (filter) {
@@ -914,9 +915,10 @@ static struct nftnl_obj_list *obj_cache_dump(struct netlink_ctx *ctx,
 		}
 		if (filter->list.obj_type)
 			type = filter->list.obj_type;
+
+		reset = filter->reset.obj;
 	}
-	obj_list = mnl_nft_obj_dump(ctx, family, table, obj, type, dump,
-				    filter->reset.obj);
+	obj_list = mnl_nft_obj_dump(ctx, family, table, obj, type, dump, reset);
 	if (!obj_list) {
                 if (errno == EINTR)
 			return NULL;
tests/shell/testcases/bogons/nft-f/delete_nonexistant_object_crash new file +1 -0
new file mode 100644
index 000000000000..c369dec8c07d
@@ -0,0 +1 @@
+delete quota a b
Signature · 1 line
2.49.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Florian Westphal

a delete request will cause a crash in obj_cache_dump, move the deref into the filter block.

Fixes dbff26bfba83 ("cache: consolidate reset command")

Thanks.

Quoted 42 lines
---
 src/cache.c                                                 | 6 ++++--
 .../testcases/bogons/nft-f/delete_nonexistant_object_crash  | 1 +
 2 files changed, 5 insertions(+), 2 deletions(-)
 create mode 100644 tests/shell/testcases/bogons/nft-f/delete_nonexistant_object_crash
src/cache.c +4 -2
index b75a5bf3283c..c0d96bd14a80 100644
@@ -902,6 +902,7 @@ static struct nftnl_obj_list *obj_cache_dump(struct netlink_ctx *ctx,
 	int family = NFPROTO_UNSPEC;
 	const char *table = NULL;
 	const char *obj = NULL;
+	bool reset = false;
 	bool dump = true;
 
 	if (filter) {
@@ -914,9 +915,10 @@ static struct nftnl_obj_list *obj_cache_dump(struct netlink_ctx *ctx,
 		}
 		if (filter->list.obj_type)
 			type = filter->list.obj_type;
+
+		reset = filter->reset.obj;
 	}
-	obj_list = mnl_nft_obj_dump(ctx, family, table, obj, type, dump,
-				    filter->reset.obj);
+	obj_list = mnl_nft_obj_dump(ctx, family, table, obj, type, dump, reset);
 	if (!obj_list) {
                 if (errno == EINTR)
 			return NULL;
tests/shell/testcases/bogons/nft-f/delete_nonexistant_object_crash new file +1 -0
new file mode 100644
index 000000000000..c369dec8c07d
@@ -0,0 +1 @@
+delete quota a b
Signature · 1 line
2.49.0
#2 lore raw
Quoted 8 lines · Pablo Neira Ayuso
Quoted 5 lines · Florian Westphal

a delete request will cause a crash in obj_cache_dump, move the deref into the filter block.

Fixes dbff26bfba83 ("cache: consolidate reset command")

BTW. Same pattern in:

- rule_cache_dump()

Maybe collapse this chunk too?

src/cache.c +4 -2
index b75a5bf3283c..52f7c9abd741 100644
@@ -714,6 +714,7 @@ static int rule_cache_dump(struct netlink_ctx *ctx, const struct handle *h,
 	const char *chain = NULL;
 	uint64_t rule_handle = 0;
 	int family = h->family;
+	bool reset = false;
 	bool dump = true;
 
 	if (filter) {
@@ -727,11 +728,12 @@ static int rule_cache_dump(struct netlink_ctx *ctx, const struct handle *h,
 		}
 		if (filter->list.family)
 			family = filter->list.family;
+
+		reset = filter->reset.rule;
 	}
 
 	rule_cache = mnl_nft_rule_dump(ctx, family,
-				       table, chain, rule_handle, dump,
-				       filter->reset.rule);
+				       table, chain, rule_handle, dump, reset);
 	if (rule_cache == NULL) {
 		if (errno == EINTR)
 			return -1;