Skip to contentSkip to conversation

cache: check for NULL chain in cache_init()

PATCH New Pablo Neira Ayuso 1 participant 1 message Apr 1, 2021 netfilter

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 cache: check for NULL chain in cache_init()

Another process might race to add chains after chain_cache_init(). The generation check does not help since it comes after cache_init(). NLM_F_DUMP_INTR only guarantees consistency within one single netlink dump operation, so it does not help either (cache population requires several netlink dump commands).

Let's be safe and do not assume the chain exists in the cache when populating the rule cache.

---
 src/cache.c | 3 +++
 1 file changed, 3 insertions(+)
src/cache.c +3 -0
index f7187ee7237f..5c21b8958a28 100644
@@ -338,6 +338,9 @@ static int cache_init_objects(struct netlink_ctx *ctx, unsigned int flags)
 				if (!chain)
 					chain = chain_binding_lookup(table,
 							rule->handle.chain.name);
+				if (!chain)
+					goto cache_fails;
+
 				list_move_tail(&rule->list, &chain->rules);
 			}
 			if (ret < 0) {
Signature · 1 line
2.20.1