Skip to contentSkip to conversation

evaluate: force full cache update on rule index translation

PATCH Superseded Eric Garver 2 participants 3 messages May 1, 2019 – May 6, 2019 netfilter

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 evaluate: force full cache update on rule index translation

If we've done a partial fetch of the cache and the genid is the same the cache update will be skipped without fetching the rules. This causes the index to handle lookup to fail. To remedy the situation we flush the cache and force a full update.

Fixes 816d8c7659c1 ("Support 'add/insert rule index <IDX>'")
---
 src/evaluate.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
src/evaluate.c +5 -1
index 3593eb80a6a6..a2585291e7c4 100644
@@ -3182,7 +3182,11 @@ static int rule_translate_index(struct eval_ctx *ctx, struct rule *rule)
 	struct rule *r;
 	int ret;
 
-	/* update cache with CMD_LIST so that rules are fetched, too */
+	/* Update cache with CMD_LIST so that rules are fetched, too. The explicit
+	 * release is necessary because the genid may be the same, in which case
+	 * the update would be a no-op.
+	 */
+	cache_release(&ctx->nft->cache);
 	ret = cache_update(ctx->nft, CMD_LIST, ctx->msgs);
 	if (ret < 0)
 		return ret;
Signature · 1 line
2.20.1
#1 lore raw
Quoted 4 lines · Eric Garver

If we've done a partial fetch of the cache and the genid is the same the cache update will be skipped without fetching the rules. This causes the index to handle lookup to fail. To remedy the situation we flush the cache and force a full update.

@Eric: Would you mind to post a reproducer? I'd like to make a test for tests/shell/ infrastructure to make sure future changes don't break this.

@Phil: Not related to this, but do you think it would be good to rework rule index insertion to support for NFTA_RULE_POSITION_ID?

Thanks!

Quoted 26 lines
Fixes 816d8c7659c1 ("Support 'add/insert rule index <IDX>'")
---
 src/evaluate.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
src/evaluate.c +5 -1
index 3593eb80a6a6..a2585291e7c4 100644
@@ -3182,7 +3182,11 @@ static int rule_translate_index(struct eval_ctx *ctx, struct rule *rule)
 	struct rule *r;
 	int ret;
 
-	/* update cache with CMD_LIST so that rules are fetched, too */
+	/* Update cache with CMD_LIST so that rules are fetched, too. The explicit
+	 * release is necessary because the genid may be the same, in which case
+	 * the update would be a no-op.
+	 */
+	cache_release(&ctx->nft->cache);
 	ret = cache_update(ctx->nft, CMD_LIST, ctx->msgs);
 	if (ret < 0)
 		return ret;
Signature · 1 line
2.20.1
#2 lore raw
Quoted 9 lines · Pablo Neira Ayuso
Quoted 4 lines · Eric Garver

If we've done a partial fetch of the cache and the genid is the same the cache update will be skipped without fetching the rules. This causes the index to handle lookup to fail. To remedy the situation we flush the cache and force a full update.

@Eric: Would you mind to post a reproducer? I'd like to make a test for tests/shell/ infrastructure to make sure future changes don't break this.

I'll post a v2 with test additions.