Netfilter fixes for net
Subsystems (4)
Pablo Neira Ayuso
maintainercover Netfilter fixes for net
Hi,
The following patchset contains Netfilter fixes for net:
1) Reinstantiate Florian Westphal as a Netfilter maintainer.
2) Depend on both NETFILTER_XTABLES and NETFILTER_XTABLES_LEGACY, from Arnd Bergmann.
3) Use id to annotate last conntrack/expectation visited to resume netlink dump, patches from Florian Westphal.
4) Fix bogus element in nft_pipapo avx2 lookup, introduced in the last nf-next batch of updates, also from Florian.
5) Return 0 instead of recycling ret variable in nf_conntrack_log_invalid_sysctl(), introduced in the last nf-next batch of updates, from Dan Carpenter.
6) Fix WARN_ON_ONCE triggered by syzbot with larger cgroup level in nft_socket.
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git nf-25-08-07
Thanks.
----------------------------------------------------------------
The following changes since commit d942fe13f72bec92f6c689fbd74c5ec38228c16a:
net: ti: icssg-prueth: Fix skb handling for XDP_PASS (2025-08-05 18:03:33 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git tags/nf-25-08-07
for you to fetch changes up to 1dee968d22eaeb3eede70df513ab3f8dd1712e3e:
netfilter: nft_socket: remove WARN_ON_ONCE with huge level value (2025-08-07 13:19:26 +0200)
----------------------------------------------------------------
netfilter pull request 25-08-07
----------------------------------------------------------------
Arnd Bergmann (1):
netfilter: add back NETFILTER_XTABLES dependencies
Dan Carpenter (1):
netfilter: conntrack: clean up returns in nf_conntrack_log_invalid_sysctl()
Florian Westphal (4):
MAINTAINERS: resurrect my netfilter maintainer entry
netfilter: ctnetlink: fix refcount leak on table dump
netfilter: ctnetlink: remove refcounting in expectation dumpers
netfilter: nft_set_pipapo: don't return bogus extension pointer
Pablo Neira Ayuso (1):
netfilter: nft_socket: remove WARN_ON_ONCE with huge level value
MAINTAINERS | 1 + net/bridge/netfilter/Kconfig | 1 + net/ipv4/netfilter/Kconfig | 3 ++ net/ipv6/netfilter/Kconfig | 1 + net/netfilter/nf_conntrack_netlink.c | 65 +++++++++++++++------------------ net/netfilter/nf_conntrack_standalone.c | 6 +-- net/netfilter/nft_set_pipapo_avx2.c | 12 +++--- net/netfilter/nft_socket.c | 2 +- 8 files changed, 46 insertions(+), 45 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/7 MAINTAINERS: resurrect my netfilter maintainer entry
From: Florian Westphal <[email protected]>
This reverts commit b5048d27872a9734d142540ea23c3e897e47e05c. Its been more than a year, hope my motivation lasts a bit longer than last time :-)
--- MAINTAINERS | 1 + 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
@@ -17313,6 +17313,7 @@ F: drivers/net/ethernet/neterion/ NETFILTER M: Pablo Neira Ayuso <[email protected]> M: Jozsef Kadlecsik <[email protected]> +M: Florian Westphal <[email protected]> L: [email protected] L: [email protected] S: Maintained
Signature · 1 line
2.30.2
Re: [PATCH net 1/7] MAINTAINERS: resurrect my netfilter maintainer entry
Quoted 9 lines · Pablo Neira Ayuso
From: Florian Westphal <[email protected]>
This reverts commit
b5048d27872a9734d142540ea23c3e897e47e05c. Its been more than a year, hope my motivation lasts a bit longer than last time :-)Signed-off-by Florian Westphal <[email protected]>Signed-off-by Pablo Neira Ayuso <[email protected]>
Oh very nice, welcome back Florian !
Simon Horman
reviewerRe: [PATCH net 1/7] MAINTAINERS: resurrect my netfilter maintainer entry
Quoted 4 lines · Eric Dumazet
Quoted 3 lines · Pablo Neira Ayuso
From: Florian Westphal <[email protected]>
Quoted 8 lines
Quoted 6 lines
This reverts commit
b5048d27872a9734d142540ea23c3e897e47e05c. Its been more than a year, hope my motivation lasts a bit longer than last time :-)Signed-off-by Florian Westphal <[email protected]>Signed-off-by Pablo Neira Ayuso <[email protected]>Oh very nice, welcome back Florian !
Yes, very nice indeed. Welcome back Florian !
Re: [PATCH net 1/7] MAINTAINERS: resurrect my netfilter maintainer entry
Quoted 5 lines
From: Florian Westphal <[email protected]>
This reverts commit
b5048d27872a9734d142540ea23c3e897e47e05c. Its been more than a year, hope my motivation lasts a bit longer than last time :-)
This is fantastic news !
Re: [PATCH net 1/7] MAINTAINERS: resurrect my netfilter maintainer entry
In reply to Pablo Neira AyusoThis series was applied to netdev/net.git (main) by Pablo Neira Ayuso <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Pablo Neira Ayuso <[email protected]>:
Quoted 10 lines · On Thu, 7 Aug 2025 13:29:42 +0200 you wrote:
From: Florian Westphal <[email protected]>
This reverts commit
b5048d27872a9734d142540ea23c3e897e47e05c. Its been more than a year, hope my motivation lasts a bit longer than last time :-)Signed-off-by Florian Westphal <[email protected]>Signed-off-by Pablo Neira Ayuso <[email protected]>[...]
Here is the summary with links:
- [net,1/7] MAINTAINERS: resurrect my netfilter maintainer entry
https://git.kernel.org/netdev/net/c/f752adfaf5f7 - [net,2/7] netfilter: add back NETFILTER_XTABLES dependencies https://git.kernel.org/netdev/net/c/25a8b88f000c - [net,3/7] netfilter: ctnetlink: fix refcount leak on table dump https://git.kernel.org/netdev/net/c/de788b2e6227 - [net,4/7] netfilter: ctnetlink: remove refcounting in expectation dumpers https://git.kernel.org/netdev/net/c/1492e3dcb2be - [net,5/7] netfilter: nft_set_pipapo: don't return bogus extension pointer https://git.kernel.org/netdev/net/c/c8a7c2c60818 - [net,6/7] netfilter: conntrack: clean up returns in nf_conntrack_log_invalid_sysctl() https://git.kernel.org/netdev/net/c/f54186df806f - [net,7/7] netfilter: nft_socket: remove WARN_ON_ONCE with huge level value https://git.kernel.org/netdev/net/c/1dee968d22ea
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Pablo Neira Ayuso
maintainerPATCH 2/7 netfilter: add back NETFILTER_XTABLES dependencies
In reply to Pablo Neira AyusoFrom: Arnd Bergmann <[email protected]>
Some Kconfig symbols were changed to depend on the 'bool' symbol NETFILTER_XTABLES_LEGACY, which means they can now be set to built-in when the xtables code itself is in a loadable module:
x86_64-linux-ld: vmlinux.o: in function `arpt_unregister_table_pre_exit':
(.text+0x1831987): undefined reference to `xt_find_table'
x86_64-linux-ld: vmlinux.o: in function `get_info.constprop.0':
arp_tables.c:(.text+0x1831aab): undefined reference to `xt_request_find_table_lock'
x86_64-linux-ld: arp_tables.c:(.text+0x1831bea): undefined reference to `xt_table_unlock'
x86_64-linux-ld: vmlinux.o: in function `do_arpt_get_ctl':
arp_tables.c:(.text+0x183205d): undefined reference to `xt_find_table_lock'
x86_64-linux-ld: arp_tables.c:(.text+0x18320c1): undefined reference to `xt_table_unlock'
x86_64-linux-ld: arp_tables.c:(.text+0x183219a): undefined reference to `xt_recseq'
Change these to depend on both NETFILTER_XTABLES and NETFILTER_XTABLES_LEGACY.
--- net/bridge/netfilter/Kconfig | 1 + net/ipv4/netfilter/Kconfig | 3 +++ net/ipv6/netfilter/Kconfig | 1 + 3 files changed, 5 insertions(+)
net/bridge/netfilter/Kconfig +1 -0
@@ -43,6 +43,7 @@ config NF_CONNTRACK_BRIDGE config BRIDGE_NF_EBTABLES_LEGACY tristate "Legacy EBTABLES support" depends on BRIDGE && NETFILTER_XTABLES_LEGACY + depends on NETFILTER_XTABLES default n help Legacy ebtables packet/frame classifier.
net/ipv4/netfilter/Kconfig +3 -0
@@ -14,6 +14,7 @@ config NF_DEFRAG_IPV4 config IP_NF_IPTABLES_LEGACY tristate "Legacy IP tables support" depends on NETFILTER_XTABLES_LEGACY + depends on NETFILTER_XTABLES default m if NETFILTER_XTABLES_LEGACY help iptables is a legacy packet classifier.
@@ -326,6 +327,7 @@ endif # IP_NF_IPTABLES config IP_NF_ARPTABLES tristate "Legacy ARPTABLES support" depends on NETFILTER_XTABLES_LEGACY + depends on NETFILTER_XTABLES default n help arptables is a legacy packet classifier.
@@ -343,6 +345,7 @@ config IP_NF_ARPFILTER select IP_NF_ARPTABLES select NETFILTER_FAMILY_ARP depends on NETFILTER_XTABLES_LEGACY + depends on NETFILTER_XTABLES help ARP packet filtering defines a table `filter', which has a series of rules for simple ARP packet filtering at local input and
net/ipv6/netfilter/Kconfig +1 -0
@@ -10,6 +10,7 @@ menu "IPv6: Netfilter Configuration" config IP6_NF_IPTABLES_LEGACY tristate "Legacy IP6 tables support" depends on INET && IPV6 && NETFILTER_XTABLES_LEGACY + depends on NETFILTER_XTABLES default m if NETFILTER_XTABLES_LEGACY help ip6tables is a legacy packet classifier.
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 3/7 netfilter: ctnetlink: fix refcount leak on table dump
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
There is a reference count leak in ctnetlink_dump_table():
if (res < 0) {
nf_conntrack_get(&ct->ct_general); // HERE
cb->args[1] = (unsigned long)ct;
...While its very unlikely, its possible that ct == last. If this happens, then the refcount of ct was already incremented. This 2nd increment is never undone.
This prevents the conntrack object from being released, which in turn keeps prevents cnet->count from dropping back to 0.
This will then block the netns dismantle (or conntrack rmmod) as nf_conntrack_cleanup_net_list() will wait forever.
This can be reproduced by running conntrack_resize.sh selftest in a loop. It takes ~20 minutes for me on a preemptible kernel on average before I see a runaway kworker spinning in nf_conntrack_cleanup_net_list.
One fix would to change this to:
if (res < 0) {
if (ct != last)
nf_conntrack_get(&ct->ct_general);But this reference counting isn't needed in the first place. We can just store a cookie value instead.
A followup patch will do the same for ctnetlink_exp_dump_table, it looks to me as if this has the same problem and like ctnetlink_dump_table, we only need a 'skip hint', not the actual object so we can apply the same cookie strategy there as well.
--- net/netfilter/nf_conntrack_netlink.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)
net/netfilter/nf_conntrack_netlink.c +13 -11
@@ -884,8 +884,6 @@ ctnetlink_conntrack_event(unsigned int events, const struct nf_ct_event *item)static int ctnetlink_done (struct netlink_callback *cb) { -if (cb->args[1 ]) -nf_ct_put ((struct nf_conn *)cb->args[1 ]);kfree (cb->data);return 0 ; }
@@ -1208,19 +1206,26 @@ static int ctnetlink_filter_match(struct nf_conn *ct, void *data)return 0 ; } +static unsigned long ctnetlink_get_id (const struct nf_conn *ct) +{ +unsigned long id =nf_ct_get_id (ct); + +return id ? id :1 ; +} +static int ctnetlink_dump_table (struct sk_buff *skb,struct netlink_callback *cb) {unsigned int flags = cb->data ?NLM_F_DUMP_FILTERED :0 ;struct net *net =sock_net (skb->sk); -struct nf_conn *ct, *last; +unsigned long last_id = cb->args[1 ];struct nf_conntrack_tuple_hash *h;struct hlist_nulls_node *n;struct nf_conn *nf_ct_evict[8 ]; +struct nf_conn *ct;int res, i;spinlock_t *lockp; - last = (struct nf_conn *)cb->args[1 ]; i =0 ;local_bh_disable ();
@@ -1257,7 +1262,7 @@ ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb)continue ;if (cb->args[1 ]) { -if (ct != last) +if (ctnetlink_get_id (ct) != last_id)continue ; cb->args[1 ] =0 ; }
@@ -1270,8 +1275,7 @@ ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb)NFNL_MSG_TYPE (cb->nlh->nlmsg_type), ct, true, flags);if (res <0 ) { -nf_conntrack_get (&ct->ct_general); - cb->args[1 ] = (unsigned long )ct; + cb->args[1 ] =ctnetlink_get_id (ct);spin_unlock (lockp); goto out; }
@@ -1284,12 +1288,10 @@ ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb) } out:local_bh_enable (); -if (last) { +if (last_id) {/* nf ct hash resize happened, now clear the leftover. */ -if ((struct nf_conn *)cb->args[1 ] == last) +if (cb->args[1 ] == last_id) cb->args[1 ] =0 ; - -nf_ct_put (last); }while (i) {
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 4/7 netfilter: ctnetlink: remove refcounting in expectation dumpers
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Same pattern as previous patch: do not keep the expectation object alive via refcount, only store a cookie value and then use that as the skip hint for dump resumption.
AFAICS this has the same issue as the one resolved in the conntrack dumper, when we do
if (!refcount_inc_not_zero(&exp->use))
to increment the refcount, there is a chance that exp == last, which causes a double-increment of the refcount and subsequent memory leak.
--- net/netfilter/nf_conntrack_netlink.c | 41 ++++++++++++---------------- 1 file changed, 17 insertions(+), 24 deletions(-)
net/netfilter/nf_conntrack_netlink.c +17 -24
@@ -3170,23 +3170,27 @@ ctnetlink_expect_event(unsigned int events, const struct nf_exp_event *item)return 0 ; }#endif -static int ctnetlink_exp_done (struct netlink_callback *cb) + +static unsigned long ctnetlink_exp_id (const struct nf_conntrack_expect *exp) { -if (cb->args[1 ]) -nf_ct_expect_put ((struct nf_conntrack_expect *)cb->args[1 ]); -return 0 ; +unsigned long id = (unsigned long )exp; + + id +=nf_ct_get_id (exp->master); + id += exp->class; + +return id ? id :1 ; }static int ctnetlink_exp_dump_table (struct sk_buff *skb,struct netlink_callback *cb) {struct net *net =sock_net (skb->sk); -struct nf_conntrack_expect *exp, *last;struct nfgenmsg *nfmsg =nlmsg_data (cb->nlh);u_int8_t l3proto = nfmsg->nfgen_family; +unsigned long last_id = cb->args[1 ]; +struct nf_conntrack_expect *exp;rcu_read_lock (); - last = (struct nf_conntrack_expect *)cb->args[1 ];for (; cb->args[0 ] < nf_ct_expect_hsize; cb->args[0 ]++) { restart: hlist_for_each_entry_rcu(exp, &nf_ct_expect_hash[cb->args[0]],
@@ -3198,7 +3202,7 @@ ctnetlink_exp_dump_table(struct sk_buff *skb, struct netlink_callback *cb)continue ;if (cb->args[1 ]) { -if (exp != last) +if (ctnetlink_exp_id (exp) != last_id)continue ; cb->args[1 ] =0 ; }
@@ -3207,9 +3211,7 @@ ctnetlink_exp_dump_table(struct sk_buff *skb, struct netlink_callback *cb) cb->nlh->nlmsg_seq, IPCTNL_MSG_EXP_NEW, exp) < 0) { -if (!refcount_inc_not_zero (&exp->use)) -continue ; - cb->args[1 ] = (unsigned long )exp; + cb->args[1 ] =ctnetlink_exp_id (exp); goto out; } }
@@ -3220,32 +3222,30 @@ ctnetlink_exp_dump_table(struct sk_buff *skb, struct netlink_callback *cb) } out:rcu_read_unlock (); -if (last) -nf_ct_expect_put (last); -return skb->len; }static int ctnetlink_exp_ct_dump_table (struct sk_buff *skb,struct netlink_callback *cb) { -struct nf_conntrack_expect *exp, *last;struct nfgenmsg *nfmsg =nlmsg_data (cb->nlh);struct nf_conn *ct = cb->data;struct nf_conn_help *help =nfct_help (ct);u_int8_t l3proto = nfmsg->nfgen_family; +unsigned long last_id = cb->args[1 ]; +struct nf_conntrack_expect *exp;if (cb->args[0 ])return 0 ;rcu_read_lock (); - last = (struct nf_conntrack_expect *)cb->args[1 ]; + restart:hlist_for_each_entry_rcu (exp, &help->expectations, lnode) {if (l3proto && exp->tuple.src.l3num != l3proto)continue ;if (cb->args[1 ]) { -if (exp != last) +if (ctnetlink_exp_id (exp) != last_id)continue ; cb->args[1 ] =0 ; }
@@ -3253,9 +3253,7 @@ ctnetlink_exp_ct_dump_table(struct sk_buff *skb, struct netlink_callback *cb) cb->nlh->nlmsg_seq, IPCTNL_MSG_EXP_NEW, exp) < 0) { -if (!refcount_inc_not_zero (&exp->use)) -continue ; - cb->args[1 ] = (unsigned long )exp; + cb->args[1 ] =ctnetlink_exp_id (exp); goto out; } }
@@ -3266,9 +3264,6 @@ ctnetlink_exp_ct_dump_table(struct sk_buff *skb, struct netlink_callback *cb) cb->args[0 ] =1 ; out:rcu_read_unlock (); -if (last) -nf_ct_expect_put (last); -return skb->len; }
@@ -3287,7 +3282,6 @@ static int ctnetlink_dump_exp_ct(struct net *net, struct sock *ctnl,struct nf_conntrack_zone zone;struct netlink_dump_control c = { .dump = ctnetlink_exp_ct_dump_table, - .done = ctnetlink_exp_done, }; err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_MASTER,
@@ -3337,7 +3331,6 @@ static int ctnetlink_get_expect(struct sk_buff *skb,else {struct netlink_dump_control c = { .dump = ctnetlink_exp_dump_table, - .done = ctnetlink_exp_done, };return netlink_dump_start (info->sk, skb, info->nlh, &c); }
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 5/7 netfilter: nft_set_pipapo: don't return bogus extension pointer
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Dan Carpenter says:
Commit 17a20e09f086 ("netfilter: nft_set: remove one argument from lookup and update functions") [..] leads to the following Smatch static checker warning:
net/netfilter/nft_set_pipapo_avx2.c:1269 nft_pipapo_avx2_lookup()
error: uninitialized symbol 'ext'.
Fix this by initing ext to NULL and set it only once we've found a match.
--- net/netfilter/nft_set_pipapo_avx2.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
net/netfilter/nft_set_pipapo_avx2.c +6 -6
@@ -1150,12 +1150,12 @@ nft_pipapo_avx2_lookup(const struct net *net, const struct nft_set *set, const u32 *key) {struct nft_pipapo *priv =nft_set_priv (set); +const struct nft_set_ext *ext =NULL ;struct nft_pipapo_scratch *scratch;u8 genmask =nft_genmask_cur (net);const struct nft_pipapo_match *m;const struct nft_pipapo_field *f;const u8 *rp = (const u8 *)key; -const struct nft_set_ext *ext;unsigned long *res, *fill;bool map_index;int i;
@@ -1246,13 +1246,13 @@ nft_pipapo_avx2_lookup(const struct net *net, const struct nft_set *set, goto out;if (last) { - ext = &f->mt[ret].e->ext; -if (unlikely (nft_set_elem_expired (ext) || - !nft_set_elem_active (ext, genmask))) { - ext =NULL ; +const struct nft_set_ext *e = &f->mt[ret].e->ext; + +if (unlikely (nft_set_elem_expired (e) || + !nft_set_elem_active (e, genmask))) goto next_match; - } + ext = e; goto out; }
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 6/7 netfilter: conntrack: clean up returns in nf_conntrack_log_invalid_sysctl()
In reply to Pablo Neira AyusoFrom: Dan Carpenter <[email protected]>
Smatch complains that these look like error paths with missing error codes, especially the one where we return if nf_log_is_registered() is true:
net/netfilter/nf_conntrack_standalone.c:575 nf_conntrack_log_invalid_sysctl()
warn: missing error code? 'ret'
In fact, all these return zero deliberately. Change them to return a literal instead which helps readability as well as silencing the warning.
--- net/netfilter/nf_conntrack_standalone.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/netfilter/nf_conntrack_standalone.c +3 -3
@@ -567,16 +567,16 @@ nf_conntrack_log_invalid_sysctl(const struct ctl_table *table, int write,return ret;if (*(u8 *)table->data ==0 ) -return ret; +return 0 ;/* Load nf_log_syslog only if no logger is currently registered */ for (i =0 ; i <NFPROTO_NUMPROTO ; i++) {if (nf_log_is_registered (i)) -return ret; +return 0 ; }request_module ("%s" ,"nf_log_syslog" ); -return ret; +return 0 ; }static struct ctl_table_header *nf_ct_netfilter_header;
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 7/7 netfilter: nft_socket: remove WARN_ON_ONCE with huge level value
In reply to Pablo Neira Ayusosyzbot managed to reach this WARN_ON_ONCE by passing a huge level value, remove it.
WARNING: CPU: 0 PID: 5853 at net/netfilter/nft_socket.c:220 nft_socket_init+0x2f4/0x3d0 net/netfilter/nft_socket.c:220
--- net/netfilter/nft_socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nft_socket.c +1 -1
@@ -217,7 +217,7 @@ static int nft_socket_init(const struct nft_ctx *ctx, level += err;/* Implies a giant cgroup tree */ -if (WARN_ON_ONCE (level >255 )) +if (level >255 )return -EOPNOTSUPP ; priv->level = level;
Signature · 1 line
2.30.2