Skip to contentSkip to conversation

netfilter: nf_tables: skip register jump/goto validation for non-base chain

PATCH In review Pablo Neira Ayuso 2 participants 6 messages Nov 18, 2025 – Nov 19, 2025

Subsystems (2)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/2 netfilter: nf_tables: skip register jump/goto validation for non-base chain

Validating a non-base chain for each register store slows down validation unnecessarily, remove it.

Fixes a654de8fdc18 ("netfilter: nf_tables: fix chain dependency validation")
---
 net/netfilter/nf_tables_api.c | 3 +++
 1 file changed, 3 insertions(+)
net/netfilter/nf_tables_api.c +3 -0
index 6f35f0b7a33c..bef95cede7b5 100644
@@ -11846,6 +11846,9 @@ static int nft_validate_register_store(const struct nft_ctx *ctx,
 		if (data != NULL &&
 		    (data->verdict.code == NFT_GOTO ||
 		     data->verdict.code == NFT_JUMP)) {
+			if (!nft_is_base_chain(ctx->chain))
+				break;
+
 			err = nft_chain_validate(ctx, data->verdict.chain);
 			if (err < 0)
 				return err;
Signature · 1 line
2.30.2
author maintainer
#1 lore raw

PATCH 2/2 netfilter: nfnetlink: bail out batch processing with EMLINK

Stop batch evaluation on the first EMLINK error, ruleset validation is expensive and it could take a while before user recovers control after sending a batch with too many jump/goto chain.

Fixes 0628b123c96d ("netfilter: nfnetlink: add batch support and use it from nf_tables")
---
 net/netfilter/nfnetlink.c | 4 ++++
 1 file changed, 4 insertions(+)
net/netfilter/nfnetlink.c +4 -0
index 811d02b4c4f7..315240b2368e 100644
@@ -558,6 +558,10 @@ static void nfnetlink_rcv_batch(struct sk_buff *skb, struct nlmsghdr *nlh,
 			 */
 			if (err)
 				status |= NFNL_BATCH_FAILURE;
+
+			/* EMLINK is fatal, stop processing batch. */
+			if (err == -EMLINK)
+				goto done;
 		}
 
 		msglen = NLMSG_ALIGN(nlh->nlmsg_len);
Signature · 1 line
2.30.2
maintainer
#2 lore raw

Re: [PATCH nf-next 2/2] netfilter: nfnetlink: bail out batch processing with EMLINK

Quoted 3 lines · Pablo Neira Ayuso

Stop batch evaluation on the first EMLINK error, ruleset validation is expensive and it could take a while before user recovers control after sending a batch with too many jump/goto chain.

ok, but...

Quoted 11 lines
Fixes 0628b123c96d ("netfilter: nfnetlink: add batch support and use it from nf_tables")
---
 net/netfilter/nfnetlink.c | 4 ++++
 1 file changed, 4 insertions(+)
net/netfilter/nfnetlink.c +0 -0
index 811d02b4c4f7..315240b2368e 100644

net/netfilter/nfnetlink.c static void nfnetlink_rcv_batch(struct sk_buff *skb, struct nlmsghdr *nlh, · line 564

Quoted 7 lines
net/netfilter/nfnetlink.c +4 -0
@@ -558,6 +558,10 @@ static void nfnetlink_rcv_batch(struct sk_buff *skb, struct nlmsghdr *nlh,
 			 */
 			if (err)
 				status |= NFNL_BATCH_FAILURE;
+
+			/* EMLINK is fatal, stop processing batch. */
+			if (err == -EMLINK)
+				goto done;

... but -EINVAL, -ERANGE or any other validation error is also fatal, so why do we make an exception for -EMLINK?

Is it because -EMLINK indicates we already spent lots of time hogging cpu in chain validation and continuing will burn more cycles?

But even if thats the case, I'm not sure its the right choice, we could also spend lots of time without hitting -EMLINK.

Maybe count errors instead and stop after n fatal errors? Would also help with rcv buffer overflow on too many netlink errors.

author maintainer
#3 lore raw

Re: [PATCH nf-next 2/2] netfilter: nfnetlink: bail out batch processing with EMLINK

Quoted 29 lines · Florian Westphal
Quoted 3 lines · Pablo Neira Ayuso

Stop batch evaluation on the first EMLINK error, ruleset validation is expensive and it could take a while before user recovers control after sending a batch with too many jump/goto chain.

ok, but...

Quoted 11 lines
Fixes 0628b123c96d ("netfilter: nfnetlink: add batch support and use it from nf_tables")
---
 net/netfilter/nfnetlink.c | 4 ++++
 1 file changed, 4 insertions(+)
net/netfilter/nfnetlink.c +0 -0
index 811d02b4c4f7..315240b2368e 100644

net/netfilter/nfnetlink.c static void nfnetlink_rcv_batch(struct sk_buff *skb, struct nlmsghdr *nlh, · line 564

Quoted 7 lines
net/netfilter/nfnetlink.c +4 -0
@@ -558,6 +558,10 @@ static void nfnetlink_rcv_batch(struct sk_buff *skb, struct nlmsghdr *nlh,
 			 */
 			if (err)
 				status |= NFNL_BATCH_FAILURE;
+
+			/* EMLINK is fatal, stop processing batch. */
+			if (err == -EMLINK)
+				goto done;

... but -EINVAL, -ERANGE or any other validation error is also fatal, so why do we make an exception for -EMLINK?

Quoted 2 lines

Is it because -EMLINK indicates we already spent lots of time hogging cpu in chain validation and continuing will burn more cycles?

Yes, you can create stupid rulesets with lots of EMLINK to burn cycles.

Quoted 4 lines

But even if thats the case, I'm not sure its the right choice, we could also spend lots of time without hitting -EMLINK.

Maybe count errors instead and stop after n fatal errors?

For other errors, such limit should be possible.

Quoted 2 lines

Would also help with rcv buffer overflow on too many netlink errors.

Error messages are still in the queue, buffer overflow only means in this case that more errors have been omitted.

Limiting the number of messages in a different topic.

For the attempt to support synchronous sockets for simple third party applications, actually limiting it is requirement to ensure buffer does not overflow.

maintainer
#4 lore raw
In reply to Pablo Neira Ayuso
Quoted 14 lines · Pablo Neira Ayuso

Validating a non-base chain for each register store slows down validation unnecessarily, remove it.

Fixes a654de8fdc18 ("netfilter: nf_tables: fix chain dependency validation")
---
 net/netfilter/nf_tables_api.c | 3 +++
 1 file changed, 3 insertions(+)
net/netfilter/nf_tables_api.c +0 -0
index 6f35f0b7a33c..bef95cede7b5 100644

net/netfilter/nf_tables_api.c static int nft_validate_register_store(const struct nft_ctx *ctx, · line 11851

Quoted 6 lines
net/netfilter/nf_tables_api.c +3 -0
@@ -11846,6 +11846,9 @@ static int nft_validate_register_store(const struct nft_ctx *ctx,
 		if (data != NULL &&
 		    (data->verdict.code == NFT_GOTO ||
 		     data->verdict.code == NFT_JUMP)) {
+			if (!nft_is_base_chain(ctx->chain))
+				break;
+

This is confusing. ctx->chain? data->verdict.chain?

Wouldn't it make more sense to elide the check if we have ctx->table->validate_state != NFT_VALIDATE_DO ?

author maintainer
#5 lore raw
Quoted 10 lines · Florian Westphal
Quoted 9 lines · Pablo Neira Ayuso

Validating a non-base chain for each register store slows down validation unnecessarily, remove it.

Fixes a654de8fdc18 ("netfilter: nf_tables: fix chain dependency validation")
---
 net/netfilter/nf_tables_api.c | 3 +++
 1 file changed, 3 insertions(+)
Quoted 13 lines

net/netfilter/nf_tables_api.c static int nft_validate_register_store(const struct nft_ctx *ctx, · line 11851

Quoted 11 lines
net/netfilter/nf_tables_api.c +3 -0
index 6f35f0b7a33c..bef95cede7b5 100644
@@ -11846,6 +11846,9 @@ static int nft_validate_register_store(const struct nft_ctx *ctx,
 		if (data != NULL &&
 		    (data->verdict.code == NFT_GOTO ||
 		     data->verdict.code == NFT_JUMP)) {
+			if (!nft_is_base_chain(ctx->chain))
+				break;
+

This is confusing. ctx->chain? data->verdict.chain?

ctx->chain is the current chain for this new rule.

data->verdict.chain is the destination chain.

Quoted 2 lines

Wouldn't it make more sense to elide the check if we have ctx->table->validate_state != NFT_VALIDATE_DO ?

I am sure we have to skip non-basechains in this case, it makes us walk the graph for no reason, even with NFT_VALIDATE_DO.

Let me have a second look, thanks for reviewing.