Skip to contentSkip to conversation

xtables: Fix typo in nft_rebuild_cache()

PATCH In review Phil Sutter 1 participant 2 messages May 14, 2019 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/1 xtables: Fix typo in nft_rebuild_cache()

Conditional cache flush logic was inverted.

Fixes 862818ac3a0de ("xtables: add and use nft_build_cache")
---
 iptables/nft.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
iptables/nft.c +1 -1
index 6354b7e8e72fe..83e0d9a69b37c 100644
@@ -1541,7 +1541,7 @@ void nft_build_cache(struct nft_handle *h)
 
 void nft_rebuild_cache(struct nft_handle *h)
 {
-	if (!h->have_cache)
+	if (h->have_cache)
 		flush_chain_cache(h, NULL);
 
 	__nft_build_cache(h);
Signature · 1 line
2.21.0
author reviewer
#1 lore raw

Hi,

Quoted 13 lines · Phil Sutter

Conditional cache flush logic was inverted.

Fixes 862818ac3a0de ("xtables: add and use nft_build_cache")
---
 iptables/nft.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
iptables/nft.c +0 -0
index 6354b7e8e72fe..83e0d9a69b37c 100644

iptables/nft.c void nft_build_cache(struct nft_handle *h) · line 1547

Quoted 8 lines
iptables/nft.c +1 -1
@@ -1541,7 +1541,7 @@ void nft_build_cache(struct nft_handle *h)
 
 void nft_rebuild_cache(struct nft_handle *h)
 {
-	if (!h->have_cache)
+	if (h->have_cache)
 		flush_chain_cache(h, NULL);
 
 	__nft_build_cache(h);

So with this change I broke your transaction reload logic. The problem is that data in h->obj_list potentially sits in cache, too. At least rules have to be there so insert with index works correctly. If the cache is flushed before regenerating the batch, use-after-free occurs which crashes the program.

We need to either keep the old cache around or keep locally generated entries when flushing (which might require more intelligent cache update, too).

I also have a fix for your testcase, will submit that in a minute as well.

Cheers, Phil