Skip to contentSkip to conversation

netfilter: nft_immediate: No increment ctx->level for NFT_GOTO

PATCH New Pablo Neira Ayuso 1 participant 1 message Sep 22, 2020

Subsystems (2)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 netfilter: nft_immediate: No increment ctx->level for NFT_GOTO

From: Steve Hill <[email protected]>

nft_immediate_validate() and nft_lookup_validate_setelem() treat NFT_GOTO and NFT_JUMP identically, incrementing pctx->level for both. This results in a -EMLINK ("Too many links") being unexpectedly returned for rulesets that use lots of gotos.

This fixes this problem by not incrementing pctx->level when following gotos.

[ [email protected]: Rebased. Restore pctx->level on error for clarity ]

Fixes 26b2f552525c ("netfilter: nf_tables: fix jumpstack depth validation")
---
 net/netfilter/nft_immediate.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
net/netfilter/nft_immediate.c +5 -5
index c63eb3b17178..303c19e94a11 100644
@@ -158,21 +158,21 @@ static int nft_immediate_validate(const struct nft_ctx *ctx,
 		return 0;
 
 	data = &priv->data;
-
+	err = 0;
 	switch (data->verdict.code) {
 	case NFT_JUMP:
-	case NFT_GOTO:
 		pctx->level++;
 		err = nft_chain_validate(ctx, data->verdict.chain);
-		if (err < 0)
-			return err;
 		pctx->level--;
 		break;
+	case NFT_GOTO:
+		err = nft_chain_validate(ctx, data->verdict.chain);
+		break;
 	default:
 		break;
 	}
 
-	return 0;
+	return err;
 }
 
 static int nft_immediate_offload_verdict(struct nft_offload_ctx *ctx,
Signature · 1 line
2.20.1