netfilter: updates for net
Subsystems (4)
Florian Westphal
maintainercover netfilter: updates for net
Hi,
The following patchset contains Netfilter fixes for *net*:
1) Jozsef Kadlecsik is retiring. Fortunately Jozsef will still keep an eye on ipset patches.
2) remove a bogus direction check from nat core, this caused spurious flakes in the 'reverse clash' selftest, from myself.
3) nf_tables doesn't need to do chain validation on register store, from Pablo Neira Ayuso.
4) nf_tables shouldn't revisit chains during ruleset (graph) validation if possible. Both 3 and 4 were slated for -next initially but there are now two independent reports of people hitting soft lockup errors during ruleset validation, so it makes no sense anymore to route this via -next given this is -stable material. From myself.
5) call cond_resched() in a more frequently visited place during nf_tables chain validation, this wasn't possible earlier due to rcu read lock, but nowadays its not held anymore during set walks.
6) Don't fail conntrack packetdrill test with HZ=100 kernels.
Please, pull these changes from:
The following changes since commit 885bebac9909994050bbbeed0829c727e42bd1b7:
nfc: pn533: Fix error code in pn533_acr122_poweron_rdr() (2025-12-11 01:40:00 -0800)
are available in the Git repository at:
https://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git nf-25-12-16
for you to fetch changes up to fec7b0795548b43e2c3c46e3143c34ef6070341c:
selftests: netfilter: packetdrill: avoid failure on HZ=100 kernel (2025-12-15 15:04:04 +0100)
----------------------------------------------------------------
netfilter pull request nf-25-12-16
----------------------------------------------------------------
Florian Westphal (4):
netfilter: nf_nat: remove bogus direction check
netfilter: nf_tables: avoid chain re-validation if possible
netfilter: nf_tables: avoid softlockup warnings in nft_chain_validate
selftests: netfilter: packetdrill: avoid failure on HZ=100 kernel
Jozsef Kadlecsik (1):
MAINTAINERS: Remove Jozsef Kadlecsik from MAINTAINERS file
Pablo Neira Ayuso (1):
netfilter: nf_tables: remove redundant chain validation on register store
CREDITS | 1 + MAINTAINERS | 1 - include/net/netfilter/nf_tables.h | 34 ++++++--- net/netfilter/nf_nat_core.c | 14 +--- net/netfilter/nf_tables_api.c | 84 +++++++++++++++++----- .../net/netfilter/conntrack_reverse_clash.c | 13 ++-- .../net/netfilter/conntrack_reverse_clash.sh | 2 + .../packetdrill/conntrack_syn_challenge_ack.pkt | 2 +- 8 files changed, 107 insertions(+), 44 deletions(-)
# WARNING: skip 0001-MAINTAINERS-Remove-Jozsef-Kadlecsik-from-MAINTAINERS.patch, no "Fixes" tag! # INFO: 0002-netfilter-nf_nat-remove-bogus-direction-check.patch fixes commit from v6.12-rc1~38^2^2~13 # INFO: 0003-netfilter-nf_tables-remove-redundant-chain-validatio.patch fixes commit from v4.18-rc1~114^2~78^2~5 # WARNING: skip 0004-netfilter-nf_tables-avoid-chain-re-validation-if-pos.patch, no "Fixes" tag!
Florian Westphal
maintainerPATCH 1/6 MAINTAINERS: Remove Jozsef Kadlecsik from MAINTAINERS file
From: Jozsef Kadlecsik <[email protected]>
I'm retiring from maintaining netfilter. I'll still keep an eye on ipset and respond to anything related to it.
Thank you!
--- CREDITS | 1 + MAINTAINERS | 1 - 2 files changed, 1 insertion(+), 1 deletion(-)
CREDITS +1 -0
@@ -1983,6 +1983,7 @@ D: netfilter: TCP window tracking code D: netfilter: raw table D: netfilter: iprange match D: netfilter: new logging interfaces +D: netfilter: ipset D: netfilter: various other hacks S: Tata S: Hungary
MAINTAINERS +0 -1
@@ -17808,7 +17808,6 @@ F: drivers/net/ethernet/neterion/ NETFILTER M: Pablo Neira Ayuso <[email protected]> -M: Jozsef Kadlecsik <[email protected]> M: Florian Westphal <[email protected]> R: Phil Sutter <[email protected]> L: [email protected]
Signature · 1 line
2.51.2
Re: [PATCH net 1/6] MAINTAINERS: Remove Jozsef Kadlecsik from MAINTAINERS file
This series was applied to netdev/net.git (main) by Florian Westphal <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Florian Westphal <[email protected]>:
Quoted 8 lines · On Tue, 16 Dec 2025 20:08:59 +0100 you wrote:
From: Jozsef Kadlecsik <[email protected]>
I'm retiring from maintaining netfilter. I'll still keep an eye on ipset and respond to anything related to it.
Thank you!
[...]
Here is the summary with links:
- [net,1/6] MAINTAINERS: Remove Jozsef Kadlecsik from MAINTAINERS file
https://git.kernel.org/netdev/net/c/99c6931fe1f5 - [net,2/6] netfilter: nf_nat: remove bogus direction check https://git.kernel.org/netdev/net/c/5ec8ca26fe93 - [net,3/6] netfilter: nf_tables: remove redundant chain validation on register store https://git.kernel.org/netdev/net/c/a67fd55f6a09 - [net,4/6] netfilter: nf_tables: avoid chain re-validation if possible https://git.kernel.org/netdev/net/c/8e1a1bc4f5a4 - [net,5/6] netfilter: nf_tables: avoid softlockup warnings in nft_chain_validate https://git.kernel.org/netdev/net/c/7e7a817f2dfd - [net,6/6] selftests: netfilter: packetdrill: avoid failure on HZ=100 kernel https://git.kernel.org/netdev/net/c/fec7b0795548
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Florian Westphal
maintainerPATCH 2/6 netfilter: nf_nat: remove bogus direction check
In reply to Florian WestphalJakub reports spurious failures of the 'conntrack_reverse_clash.sh' selftest. A bogus test makes nat core resort to port rewrite even though there is no need for this.
When the test is made, nf_nat_used_tuple() would already have caused us to return if no other CPU had added a colliding entry. Moreover, nf_nat_used_tuple() would have ignored the colliding entry if their origin tuples had been the same.
All that is left to check is if the colliding entry in the hash table is subject to NAT, and, if its not, if our entry matches in the reverse direction, e.g. hash table has
addr1:1234 -> addr2:80, and we want to commit
addr2:80 -> addr1:1234.
Because we already checked that neither the new nor the committed entry is subject to NAT we only have to check origin vs. reply tuple:
for non-nat entries, the reply tuple is always the inverted original.
Just in case there are more problems extend the error reporting in the selftest while at it and dump conntrack table/stats on error.
--- net/netfilter/nf_nat_core.c | 14 +------------- .../net/netfilter/conntrack_reverse_clash.c | 13 +++++++++---- .../net/netfilter/conntrack_reverse_clash.sh | 2 ++ 3 files changed, 12 insertions(+), 17 deletions(-)
net/netfilter/nf_nat_core.c +1 -13
@@ -294,25 +294,13 @@ nf_nat_used_tuple_new(const struct nf_conntrack_tuple *tuple, ct =nf_ct_tuplehash_to_ctrack (thash); -/* NB: IP_CT_DIR_ORIGINAL should be impossible because -* nf_nat_used_tuple() handles origin collisions. -* -* Handle remote chance other CPU confirmed its ct right after. -*/ -if (thash->tuple.dst.dir !=IP_CT_DIR_REPLY ) - goto out; -/* clashing connection subject to NAT? Retry with new tuple. */ if (READ_ONCE (ct->status) & uses_nat) goto out;if (nf_ct_tuple_equal (&ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple, - &ignored_ct->tuplehash[IP_CT_DIR_REPLY ].tuple) && -nf_ct_tuple_equal (&ct->tuplehash[IP_CT_DIR_REPLY ].tuple, - &ignored_ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple)) { + &ignored_ct->tuplehash[IP_CT_DIR_REPLY ].tuple)) taken = false; - goto out; - } out:nf_ct_put (ct);return taken;
tools/testing/selftests/net/netfilter/conntrack_reverse_clash.c +9 -4
@@ -33,9 +33,14 @@ static void die(const char *e)exit (111 ); } -static void die_port (uint16_t got,uint16_t want) +static void die_port (const struct sockaddr_in *sin,uint16_t want) { -fprintf (stderr,"Port number changed, wanted %d got %d\n" , want,ntohs (got)); +uint16_t got =ntohs (sin->sin_port); +char str[INET_ADDRSTRLEN ]; + +inet_ntop (AF_INET , &sin->sin_addr, str,sizeof (str)); + +fprintf (stderr,"Port number changed, wanted %d got %d from %s\n" , want, got, str);exit (1 ); }
@@ -100,7 +105,7 @@ int main(int argc, char *argv[])die ("child recvfrom" );if (peer.sin_port !=htons (PORT )) -die_port (peer.sin_port,PORT ); +die_port (&peer,PORT ); }else {if (sendto (s2, buf,LEN ,0 , (struct sockaddr *)&sa1,sizeof (sa1)) !=LEN )continue ;
@@ -109,7 +114,7 @@ int main(int argc, char *argv[])die ("parent recvfrom" );if (peer.sin_port !=htons ((PORT +1 ))) -die_port (peer.sin_port,PORT +1 ); +die_port (&peer,PORT +1 ); } }
tools/testing/selftests/net/netfilter/conntrack_reverse_clash.sh +2 -0
@@ -45,6 +45,8 @@ if ip netns exec "$ns0" ./conntrack_reverse_clash; then echo "PASS: No SNAT performed for null bindings" else echo "ERROR: SNAT performed without any matching snat rule" + ip netns exec "$ns0" conntrack -L + ip netns exec "$ns0" conntrack -S exit 1 fi
Signature · 1 line
2.51.2
Florian Westphal
maintainerPATCH 3/6 netfilter: nf_tables: remove redundant chain validation on register store
In reply to Florian WestphalFrom: Pablo Neira Ayuso <[email protected]>
This validation predates the introduction of the state machine that determines when to enter slow path validation for error reporting.
Currently, table validation is perform when:
- new rule contains expressions that need validation.
- new set element with jump/goto verdict.
Validation on register store skips most checks with no basechains, still this walks the graph searching for loops and ensuring expressions are called from the right hook. Remove this.
--- net/netfilter/nf_tables_api.c | 11 ----------- 1 file changed, 11 deletions(-)
net/netfilter/nf_tables_api.c +0 -11
@@ -11676,21 +11676,10 @@ static int nft_validate_register_store(const struct nft_ctx *ctx, enum nft_data_types type, unsigned int len) { - int err; - switch (reg) {case NFT_REG_VERDICT :if (type !=NFT_DATA_VERDICT )return -EINVAL ; - -if (data !=NULL && - (data->verdict.code ==NFT_GOTO || - data->verdict.code ==NFT_JUMP )) { - err =nft_chain_validate (ctx, data->verdict.chain); -if (err <0 ) -return err; - } -break ;default :if (type !=NFT_DATA_VALUE )
Signature · 1 line
2.51.2
Florian Westphal
maintainerPATCH 4/6 netfilter: nf_tables: avoid chain re-validation if possible
In reply to Florian WestphalHamza Mahfooz reports cpu soft lock-ups innft_chain_validate():
watchdog: BUG: soft lockup - CPU#1 stuck for 27s! [iptables-nft-re:37547] [..] RIP: 0010:nft_chain_validate+0xcb/0x110 [nf_tables] [..] nft_immediate_validate+0x36/0x50 [nf_tables] nft_chain_validate+0xc9/0x110 [nf_tables] nft_immediate_validate+0x36/0x50 [nf_tables] nft_chain_validate+0xc9/0x110 [nf_tables] nft_immediate_validate+0x36/0x50 [nf_tables] nft_chain_validate+0xc9/0x110 [nf_tables] nft_immediate_validate+0x36/0x50 [nf_tables] nft_chain_validate+0xc9/0x110 [nf_tables] nft_immediate_validate+0x36/0x50 [nf_tables] nft_chain_validate+0xc9/0x110 [nf_tables] nft_immediate_validate+0x36/0x50 [nf_tables] nft_chain_validate+0xc9/0x110 [nf_tables] nft_table_validate+0x6b/0xb0 [nf_tables] nf_tables_validate+0x8b/0xa0 [nf_tables] nf_tables_commit+0x1df/0x1eb0 [nf_tables]
[..]
Currently nf_tables will traverse the entire table (chain graph), starting from the entry points (base chains), exploring all possible paths (chain jumps). But there are cases where we could avoid revalidation.
Consider:
1 input -> j2 -> j3 2 input -> j2 -> j3 3 input -> j1 -> j2 -> j3
Then the second rule does not need to revalidate j2, and, by extension j3, because this was already checked during validation of the first rule. We need to validate it only for rule 3.
This is needed because chain loop detection also ensures we do not exceed the jump stack: Just because we know that j2 is cycle free, its last jump might now exceed the allowed stack size. We also need to update all reachable chains with the new largest observed call depth.
Care has to be taken to revalidate even if the chain depth won't be an
issue: chain validation also ensures that expressions are not called from invalid base chains. For example, the masquerade expression can only be called from NAT postrouting base chains.
Therefore we also need to keep record of the base chain context (type, hooknum) and revalidate if the chain becomes reachable from a different hook location.
--- include/net/netfilter/nf_tables.h | 34 +++++++++++---- net/netfilter/nf_tables_api.c | 69 +++++++++++++++++++++++++++++-- 2 files changed, 91 insertions(+), 12 deletions(-)
include/net/netfilter/nf_tables.h +26 -8
@@ -1091,6 +1091,29 @@ struct nft_rule_blob { __attribute__((aligned(__alignof__(struct nft_rule_dp)))); }; +enum nft_chain_types { +NFT_CHAIN_T_DEFAULT =0 , +NFT_CHAIN_T_ROUTE , +NFT_CHAIN_T_NAT , +NFT_CHAIN_T_MAX +}; + +/** +* struct nft_chain_validate_state - validation state +* +* If a chain is encountered again during table validation it is +* possible to avoid revalidation provided the calling context is +* compatible. This structure stores relevant calling context of +* previous validations. +* +* @hook_mask: the hook numbers and locations the chain is linked to +* @depth: the deepest call chain level the chain is linked to +*/ +struct nft_chain_validate_state { +u8 hook_mask[NFT_CHAIN_T_MAX ]; +u8 depth; +}; +/** * struct nft_chain - nf_tables chain *
@@ -1109,6 +1132,7 @@ struct nft_rule_blob {* @udlen: user data length * @udata: user data in the chain * @blob_next: rule blob pointer to the next in the chain +* @vstate: validation state */ struct nft_chain {struct nft_rule_blob __rcu *blob_gen_0;
@@ -1128,9 +1152,10 @@ struct nft_chain {/* Only used during control plane commit phase: */ struct nft_rule_blob *blob_next; +struct nft_chain_validate_state vstate; }; -int nft_chain_validate (const struct nft_ctx *ctx,const struct nft_chain *chain); +int nft_chain_validate (const struct nft_ctx *ctx,struct nft_chain *chain);int nft_setelem_validate (const struct nft_ctx *ctx,struct nft_set *set,const struct nft_set_iter *iter,struct nft_elem_priv *elem_priv);
@@ -1138,13 +1163,6 @@ int nft_set_catchall_validate(const struct nft_ctx *ctx, struct nft_set *set);int nf_tables_bind_chain (const struct nft_ctx *ctx,struct nft_chain *chain);void nf_tables_unbind_chain (const struct nft_ctx *ctx,struct nft_chain *chain); -enum nft_chain_types { -NFT_CHAIN_T_DEFAULT =0 , -NFT_CHAIN_T_ROUTE , -NFT_CHAIN_T_NAT , -NFT_CHAIN_T_MAX -}; -/** * struct nft_chain_type - nf_tables chain type info *
net/netfilter/nf_tables_api.c +65 -4
117 lines not on this page · raw message
Signature · 1 line
2.51.2
Florian Westphal
maintainerPATCH 5/6 netfilter: nf_tables: avoid softlockup warnings in nft_chain_validate
In reply to Florian WestphalThis reverts commit314c82841602 ("netfilter: nf_tables: can't schedule in nft_chain_validate"):
Since commit a60a5abe19d6 ("netfilter: nf_tables: allow iter callbacks to sleep") the iterator callback is invoked without rcu read lock held, so this cond_resched() is now valid.
--- net/netfilter/nf_tables_api.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nf_tables_api.c +2 -2
@@ -4171,6 +4171,8 @@ int nft_chain_validate(const struct nft_ctx *ctx, struct nft_chain *chain)if (err <0 )return err; } + +cond_resched (); }nft_chain_vstate_update (ctx, chain);
@@ -4195,8 +4197,6 @@ static int nft_table_validate(struct net *net, const struct nft_table *table) err =nft_chain_validate (&ctx, chain);if (err <0 ) goto err; - -cond_resched (); } err:
Signature · 1 line
2.51.2
Florian Westphal
maintainerPATCH 6/6 selftests: netfilter: packetdrill: avoid failure on HZ=100 kernel
In reply to Florian Westphalpacketdrill --ip_version=ipv4 --mtu=1500 --tolerance_usecs=1000000 --non_fatal packet conntrack_syn_challenge_ack.pkt conntrack v1.4.8 (conntrack-tools): 1 flow entries have been shown. conntrack_syn_challenge_ack.pkt:32: error executing `conntrack -f $NFCT_IP_VERSION \
-L -p tcp --dport 8080 | grep UNREPLIED | grep -q SYN_SENT` command: non-zero status 1
Affected kernel had CONFIG_HZ=100; reset packet was still sitting in backlog.
--- .../net/netfilter/packetdrill/conntrack_syn_challenge_ack.pkt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/net/netfilter/packetdrill/conntrack_syn_challenge_ack.pkt +1 -1
@@ -26,7 +26,7 @@ +0.01 > R 643160523:643160523(0) win 0 -+0.01 `conntrack -f $NFCT_IP_VERSION -L -p tcp --dport 8080 2>/dev/null | grep UNREPLIED | grep -q SYN_SENT` ++0.1 `conntrack -f $NFCT_IP_VERSION -L -p tcp --dport 8080 2>/dev/null | grep UNREPLIED | grep -q SYN_SENT` // Must go through. +0.01 > S 0:0(0) win 65535 <mss 1460,sackOK,TS val 1 ecr 0,nop,wscale 8>
Signature · 1 line
2.51.2
Paolo Abeni
maintainerQuoted 28 lines · Florian Westphal
The following patchset contains Netfilter fixes for *net*:
1) Jozsef Kadlecsik is retiring. Fortunately Jozsef will still keep an eye on ipset patches.
2) remove a bogus direction check from nat core, this caused spurious flakes in the 'reverse clash' selftest, from myself.
3)
nf_tablesdoesn't need to do chain validation on register store, from Pablo Neira Ayuso.4)
nf_tablesshouldn't revisit chains during ruleset (graph) validation if possible. Both 3 and 4 were slated for -next initially but there are now two independent reports of people hitting soft lockup errors during ruleset validation, so it makes no sense anymore to route this via -next given this is -stable material. From myself.5) call
cond_resched()in a more frequently visited place duringnf_tableschain validation, this wasn't possible earlier due to rcu read lock, but nowadays its not held anymore during set walks.6) Don't fail conntrack packetdrill test with HZ=100 kernels.
Please, pull these changes from:
The following changes since commit885bebac9909994050bbbeed0829c727e42bd1b7:nfc: pn533: Fix error code in
pn533_acr122_poweron_rdr()(2025-12-11 01:40:00 -0800)
Quoted 7 lines
are available in the Git repository at:
https://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git nf-25-12-16
for you to fetch changes up to
fec7b0795548b43e2c3c46e3143c34ef6070341c:selftests: netfilter: packetdrill: avoid failure on HZ=100 kernel (2025-12-15 15:04:04 +0100)
Pulled, thanks!
Paolo