Skip to contentSkip to conversation

Netfilter/IPVS fixes

PATCH Applied Pablo Neira Ayuso 4 participants 19 messages Nov 5 – Nov 6

Subsystems (5)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

v4 cover Netfilter/IPVS fixes

v4: - Drop "ipvs: do not create conns from packets with port 0".

This PR was already reviewed in its v2 by netdev-ai-bots. I have dropped all the patches that LLM flagged as needing more work even since.

But I really think v3 was good enough and a follow up for "ipvs: do not create conns from packets with port 0" was just fine to proceed.

Maybe patchbot will ban this pull request again, v3 was blocklisted for not fulfulling the 24 hours rule, that is why it was not reviewed.

But, as said, this was all reviewed in PR v2 already, this is just keeping back 3 patches included in PR v1 needing more work.
-o-

Hi,

The following batch contains Netfilter/IPVS fixes for net, this batch addresses LLM findings, several of these fixes has been reproduced by syzbot:

1) Add recursion count to nf_reject infrastructure to prevent stack overflow, from Fernando F. Mancera.

2) Use kfree_rcu() to release IPVS parent application to fix UaF, from Chengfeng Ye.

3) Fix UaF in IPVS netns removal path due to releasing per-net protocol data too early, from Chengfeng Ye.

4) Preserve recursion count on nfqueue reinjection, from Zihan Xi.

5) Restore GRE timeout in the flowtable, otherwise, WARN_ON_ONCE() is reachable, from Michail Andreas Michalopoulos.

6) Check non-null gc transaction in nft_rbtree before queuing it for processing, from Xingyuan Mo.

7) Replace WARN_ON_ONCE() by DEBUG_NET_WARN_ON_ONCE() in nf_conntrack_bridge which is reachable if the protocol of the tag of a frame differs from the vlan_protocol of the bridge. From Laveesh Bansal.

8) Check x_tables target name is non-null before accessing it when building a new table, from Fernando F. Mancera.

9) Fix out-of-bound memory read in nf_conntrack_sip, from Joas Antonio Dos Santos.

10) Fix a memleak in nf_tables hardware offload when double deleting the same rule, in the same batch.

11) Use a mutex in xt_recent netns exit path instead of spinlock, since proc unregistration might sleep. From Cen Zhang.

12) Zero the nf_nat_range2 struct before filling it up, to avoid using stale uninitialized stack data to configure NAT with an esoteric NAT flags combination. From Florian Westphal.

Please, pull these changes from:

git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git nf-26-11-05

Thanks.

----------------------------------------------------------------

The following changes since commit cb284914e749388eef402938bdb3115fe1f6d337:

net: ipa: Fix double free of the interrupt structure on config error (2026-10-30 19:04:37 -0700)

are available in the Git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git nf-26-11-05

for you to fetch changes up to d1bb235aa409a4e5aeba6c748d953d948625b1e9:

netfilter: nat: zero newrange before filling it in (2026-11-05 13:31:11 +0100)

----------------------------------------------------------------
netfilter pull request 26-11-05

----------------------------------------------------------------
Cen Zhang (Microsoft) (1):
netfilter: xt_recent: do not call remove_proc_entry() under recent_lock

Chengfeng Ye (2):
ipvs: Defer application parent freeing until after RCU readers
ipvs: fix protocol data lifetime during namespace teardown

Fernando Fernandez Mancera (2):
netfilter: nft_reject: prevent unbounded recursion in output hooks
netfilter: x_tables: check target name before accessing verdict

Florian Westphal (1):
netfilter: nat: zero newrange before filling it in

Joas Antonio dos Santos (1):
netfilter: nf_conntrack_sip: fix OOB read in ct_sip_parse_transport()

Laveesh Bansal (1):
netfilter: bridge: use DEBUG_NET_WARN_ON_ONCE in nf_ct_bridge_refrag()

Michail Andreas Michalopoulos (1):
netfilter: flowtable: extend ct timeout of offloaded GRE flows

Pablo Neira Ayuso (1):
netfilter: nf_tables: fix memleak when rule deletion fails with hardware offload

Xingyuan Mo (1):
netfilter: nft_set_rbtree: check catchall_sync return before queue_done

Zihan Xi (1):
netfilter: nf_dup: preserve guard across NFQUEUE reinjection

 include/linux/netdevice_xmit.h             |  4 +--
 include/net/netfilter/nf_dup_netdev.h      | 35 -------------------------
 include/net/netfilter/nf_queue.h           |  1 +
 include/net/netfilter/nf_recursion.h       | 42 ++++++++++++++++++++++++++++++
 net/bridge/netfilter/nf_conntrack_bridge.c |  2 +-
 net/ipv4/netfilter/arp_tables.c            |  5 ++--
 net/ipv4/netfilter/ip_tables.c             |  5 ++--
 net/ipv4/netfilter/nf_reject_ipv4.c        | 12 +++++++++
 net/ipv6/netfilter/ip6_tables.c            |  5 ++--
 net/ipv6/netfilter/nf_reject_ipv6.c        | 13 +++++++++
 net/netfilter/ipvs/ip_vs_app.c             |  2 +-
 net/netfilter/ipvs/ip_vs_core.c            | 12 ++++-----
 net/netfilter/nf_conntrack_sip.c           |  4 +--
 net/netfilter/nf_dup_netdev.c              |  1 +
 net/netfilter/nf_flow_table_core.c         |  1 +
 net/netfilter/nf_nat_masquerade.c          |  4 +--
 net/netfilter/nf_queue.c                   |  1 +
 net/netfilter/nf_tables_api.c              | 21 +++++++--------
 net/netfilter/nf_tables_offload.c          |  3 +++
 net/netfilter/nfnetlink_queue.c            | 17 +++++++++---
 net/netfilter/nft_fwd_netdev.c             |  1 +
 net/netfilter/nft_set_rbtree.c             |  3 ++-
 net/netfilter/xt_NETMAP.c                  |  4 +--
 net/netfilter/xt_recent.c                  |  7 ++---
 24 files changed, 129 insertions(+), 76 deletions(-)
 create mode 100644 include/net/netfilter/nf_recursion.h
author maintainer
#1 lore raw

PATCH v4 1/12 netfilter: nft_reject: prevent unbounded recursion in output hooks

From: Fernando Fernandez Mancera <[email protected]>

nftables payload-mangling rules can rewrite packet contents (such as TCP flags) before they are evaluated by reject targets. This defeats the content-based loop guards, allowing unbounded hook recursion that leads to kernel stack exhaustion and panics.

Fix this by extracting the per-CPU xmit recursion limit previously used by the netdev duplication/forwarding paths into a shared header, and apply it to the inet and inet6 reject transmit functions. It disables BH while transmitting the skb to address a possible migration to different CPU leading to imbalanced decrementation of the recursion counters.

Note that the dev_queue_xmit() path used when CONFIG_BRIDGE_NETFILTER is enabled does not require this recursion guard. In that scenario, the generated reset packet is transmitted directly at Layer 2. Because the packet egresses from a different hook, it cannot synchronously loop. In addition nf_send_unreach() and nf_send_unreach6() are safe as the ICMP transmit functions are protected against recursion by the icmp_xmit_lock() and icmpv6_xmit_lock() guards.

Fixes bee11dc78fc8 ("netfilter: nft_reject: support for IPv6 and TCP reset")
---
 include/linux/netdevice_xmit.h        |  4 +--
 include/net/netfilter/nf_dup_netdev.h | 35 ----------------------
 include/net/netfilter/nf_recursion.h  | 42 +++++++++++++++++++++++++++
 net/ipv4/netfilter/nf_reject_ipv4.c   | 12 ++++++++
 net/ipv6/netfilter/nf_reject_ipv6.c   | 13 +++++++++
 net/netfilter/nf_dup_netdev.c         |  1 +
 net/netfilter/nft_fwd_netdev.c        |  1 +
 7 files changed, 71 insertions(+), 37 deletions(-)
 create mode 100644 include/net/netfilter/nf_recursion.h
include/linux/netdevice_xmit.h +2 -2
index cc232508e695..286ae5a6101e 100644
@@ -18,8 +18,8 @@ struct netdev_xmit {
 	u8			sched_mirred_nest;
 	struct net_device	*sched_mirred_dev[MIRRED_NEST_LIMIT];
 #endif
-#if IS_ENABLED(CONFIG_NF_DUP_NETDEV)
-	u8 nf_dup_skb_recursion;
+#if IS_ENABLED(CONFIG_NETFILTER)
+	u8 nf_xmit_skb_recursion;
 #endif
 };
 
include/net/netfilter/nf_dup_netdev.h +0 -35
index f6b05bd80c3f..a39411264614 100644
@@ -9,41 +9,6 @@
 void nf_dup_netdev_egress(const struct nft_pktinfo *pkt, int oif);
 void nf_fwd_netdev_egress(const struct nft_pktinfo *pkt, int oif);
 
-#define NF_RECURSION_LIMIT	2
-
-#ifndef CONFIG_PREEMPT_RT
-static inline bool nf_dev_xmit_recursion(void)
-{
-	return unlikely(__this_cpu_read(softnet_data.xmit.nf_dup_skb_recursion) >
-			NF_RECURSION_LIMIT);
-}
-
-static inline void nf_dev_xmit_recursion_inc(void)
-{
-	__this_cpu_inc(softnet_data.xmit.nf_dup_skb_recursion);
-}
-
-static inline void nf_dev_xmit_recursion_dec(void)
-{
-	__this_cpu_dec(softnet_data.xmit.nf_dup_skb_recursion);
-}
-#else
-static inline bool nf_dev_xmit_recursion(void)
-{
-	return unlikely(current->net_xmit.nf_dup_skb_recursion > NF_RECURSION_LIMIT);
-}
-
-static inline void nf_dev_xmit_recursion_inc(void)
-{
-	current->net_xmit.nf_dup_skb_recursion++;
-}
-
-static inline void nf_dev_xmit_recursion_dec(void)
-{
-	current->net_xmit.nf_dup_skb_recursion--;
-}
-#endif
-
 struct nft_offload_ctx;
 struct nft_flow_rule;
 
include/net/netfilter/nf_recursion.h new file +42 -0

42 lines not on this page · raw message

net/ipv4/netfilter/nf_reject_ipv4.c +12 -0
index 7cb33af671e2..4082fa184af8 100644
@@ -10,6 +10,7 @@
 #include <net/dst.h>
 #include <net/dst_metadata.h>
 #include <net/netfilter/ipv4/nf_reject.h>
+#include <net/netfilter/nf_recursion.h>
 #include <linux/netfilter_ipv4.h>
 #include <linux/netfilter_bridge.h>
 
@@ -336,7 +337,18 @@ void nf_send_reset(struct net *net, struct sock *sk, struct sk_buff *oldskb,
 		dev_queue_xmit(nskb);
 	} else
 #endif
+	{
+		local_bh_disable();
+		if (nf_dev_xmit_recursion()) {
+			local_bh_enable();
+			goto free_nskb;
+		}
+
+		nf_dev_xmit_recursion_inc();
 		ip_local_out(net, nskb->sk, nskb);
+		nf_dev_xmit_recursion_dec();
+		local_bh_enable();
+	}
 
 	return;
 
net/ipv6/netfilter/nf_reject_ipv6.c +13 -0
index 5e08d8529cc8..7c9464184517 100644
@@ -10,6 +10,7 @@
 #include <net/ip6_checksum.h>
 #include <net/dst_metadata.h>
 #include <net/netfilter/ipv6/nf_reject.h>
+#include <net/netfilter/nf_recursion.h>
 #include <linux/netfilter_ipv6.h>
 #include <linux/netfilter_bridge.h>
 
@@ -409,7 +410,19 @@ void nf_send_reset6(struct net *net, struct sock *sk, struct sk_buff *oldskb,
 		dev_queue_xmit(nskb);
 	} else
 #endif
+	{
+		local_bh_disable();
+		if (nf_dev_xmit_recursion()) {
+			local_bh_enable();
+			kfree_skb(nskb);
+			return;
+		}
+
+		nf_dev_xmit_recursion_inc();
 		ip6_local_out(net, sk, nskb);
+		nf_dev_xmit_recursion_dec();
+		local_bh_enable();
+	}
 }
 EXPORT_SYMBOL_GPL(nf_send_reset6);
 
net/netfilter/nf_dup_netdev.c +1 -0
index c6bd5c29bed6..918716629c15 100644
@@ -12,6 +12,7 @@
 #include <net/netfilter/nf_tables.h>
 #include <net/netfilter/nf_tables_offload.h>
 #include <net/netfilter/nf_dup_netdev.h>
+#include <net/netfilter/nf_recursion.h>
 
 static void nf_do_netdev_egress(struct sk_buff *skb, struct net_device *dev,
 				enum nf_dev_hooks hook)
net/netfilter/nft_fwd_netdev.c +1 -0
index a48c2f765bba..7447da931a95 100644
@@ -14,6 +14,7 @@
 #include <net/netfilter/nf_tables.h>
 #include <net/netfilter/nf_tables_offload.h>
 #include <net/netfilter/nf_dup_netdev.h>
+#include <net/netfilter/nf_recursion.h>
 #include <net/neighbour.h>
 #include <net/ip.h>
 
Signature · 1 line
2.47.3
#2 lore raw

Re: [PATCH net 01/12] netfilter: nft_reject: prevent unbounded recursion in output hooks

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

- Whether the issue was actually triggered, or is only theoretical (e.g. found by code inspection). If it was triggered please include the symptoms, like the stack trace or error messages.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.

The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.

author maintainer
#3 lore raw

Re: [PATCH net 01/12] netfilter: nft_reject: prevent unbounded recursion in output hooks

Quoted 5 lines · On Thu, Nov 05, 2026 at 12:50:41PM +0000, [email protected] wrote:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Quoted 7 lines

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

- Whether the issue was actually triggered, or is only theoretical (e.g. found by code inspection). If it was triggered please include the symptoms, like the stack trace or error messages.

This series was primarily identified through LLM-assisted analysis.

Several issues were actively triggered and confirmed via automated testing. This includes KASAN reports for use-after-free and out-of-bounds access, syzbot reports for warnings and panics, and a confirmed sleeping function call in an atomic context. Another patch identified via LLM and subsequently verified using a userspace ASan harness.

Quoted 8 lines

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.

The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.

#4 lore raw

Re: [PATCH net 01/12] netfilter: nft_reject: prevent unbounded recursion in output hooks

In reply to Pablo Neira Ayuso
This 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 8 lines · On Thu, 5 Nov 2026 13:45:25 +0100 you wrote:

From: Fernando Fernandez Mancera <[email protected]>

nftables payload-mangling rules can rewrite packet contents (such as TCP flags) before they are evaluated by reject targets. This defeats the content-based loop guards, allowing unbounded hook recursion that leads to kernel stack exhaustion and panics.

[...]

Here is the summary with links:
- [net,01/12] netfilter: nft_reject: prevent unbounded recursion in output hooks

    https://git.kernel.org/netdev/net/c/d6c18cadfc6c
  - [net,02/12] ipvs: Defer application parent freeing until after RCU readers
    https://git.kernel.org/netdev/net/c/1e0808008e44
  - [net,03/12] ipvs: fix protocol data lifetime during namespace teardown
    https://git.kernel.org/netdev/net/c/832aa3e89e80
  - [net,04/12] netfilter: nf_dup: preserve guard across NFQUEUE reinjection
    https://git.kernel.org/netdev/net/c/82052e5b5ec3
  - [net,05/12] netfilter: flowtable: extend ct timeout of offloaded GRE flows
    https://git.kernel.org/netdev/net/c/46ecda278f6e
  - [net,06/12] netfilter: nft_set_rbtree: check catchall_sync return before queue_done
    https://git.kernel.org/netdev/net/c/1cec19d70bc2
  - [net,07/12] netfilter: bridge: use DEBUG_NET_WARN_ON_ONCE in nf_ct_bridge_refrag()
    https://git.kernel.org/netdev/net/c/683ff28ab18a
  - [net,08/12] netfilter: x_tables: check target name before accessing verdict
    https://git.kernel.org/netdev/net/c/364b200285bb
  - [net,09/12] netfilter: nf_conntrack_sip: fix OOB read in ct_sip_parse_transport()
    https://git.kernel.org/netdev/net/c/7af52bda65c0
  - [net,10/12] netfilter: nf_tables: fix memleak when rule deletion fails with hardware offload
    https://git.kernel.org/netdev/net/c/e95b3be75ae0
  - [net,11/12] netfilter: xt_recent: do not call remove_proc_entry() under recent_lock
    https://git.kernel.org/netdev/net/c/17c2e41736b6
  - [net,12/12] netfilter: nat: zero newrange before filling it in
    https://git.kernel.org/netdev/net/c/d1bb235aa409

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
author maintainer
#5 lore raw

PATCH v4 2/12 ipvs: Defer application parent freeing until after RCU readers

In reply to Pablo Neira Ayuso

From: Chengfeng Ye <[email protected]>

unregister_ip_vs_app() removes each incarnation from its protocol list and uses call_rcu() to defer freeing it, but frees the parent application immediately. An RCU reader that already found an incarnation can still access the parent through inc->app in ip_vs_app_inc_get().

During FTP helper module unload, the following interleaving is possible:

CPU 0 (RCU reader) CPU 1 (module unload)
tcp_app_conn_bind()

    find inc in protocol list
                                     unregister_ip_vs_app()
                                       ip_vs_app_inc_release(inc)
                                         list_del_rcu(&inc->p_list)
                                         call_rcu(&inc->rcu_head, ...)
                                       kfree(a)
    ip_vs_app_inc_get(inc)
      try_module_get(inc->app->module)

The helper module is already going away, so try_module_get() would fail, but evaluating its argument first reads the freed parent. The subsequent rcu_barrier() in pernet unregistration cannot protect this earlier free. KASAN reported:

  BUG: KASAN: slab-use-after-free in ip_vs_app_inc_get+0x7c/0x90
  Call Trace:
   ip_vs_app_inc_get+0x7c/0x90
   tcp_app_conn_bind+0x1bc/0x290
   ip_vs_conn_new+0x1915/0x20d0
   ip_vs_schedule+0x697/0xea0
   tcp_conn_schedule+0x489/0x820
   ip_vs_in_hook+0x7bf/0x1f40
  Allocated by task 88:
   kmemdup_noprof+0x20/0x50
   register_ip_vs_app+0x12d/0x2c0
   __ip_vs_ftp_init+0x56/0x160 [ip_vs_ftp]
  Freed by task 104:
   kfree+0x131/0x3c0
   unregister_ip_vs_app+0x2f4/0x5b0
   unregister_pernet_operations+0x232/0x490
   unregister_pernet_subsys+0x1c/0x30
   __do_sys_delete_module+0x346/0x510

Use kfree_rcu() with the existing rcu_head to keep the parent alive until these readers finish. Successful helper references already prevent normal module unload, and incarnation RCU callbacks do not access the parent.

Fixes 363c97d7435e ("ipvs: convert app locks")
---
 net/netfilter/ipvs/ip_vs_app.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/ipvs/ip_vs_app.c +1 -1
index 11cbdbaf561d..2c1b47702da2 100644
@@ -242,7 +242,7 @@ void unregister_ip_vs_app(struct netns_ipvs *ipvs, struct ip_vs_app *app)
 		}
 
 		list_del(&a->a_list);
-		kfree(a);
+		kfree_rcu(a, rcu_head);
 
 		/* decrease the module use count */
 		ip_vs_use_count_dec();
Signature · 1 line
2.47.3
author maintainer
#6 lore raw

PATCH v4 3/12 ipvs: fix protocol data lifetime during namespace teardown

In reply to Pablo Neira Ayuso

From: Chengfeng Ye <[email protected]>

IPVS frees its per-net protocol data before control cleanup cancels defense work and unregisters the sysctl table. A defense worker can load a protocol data pointer, then namespace cleanup can unlink and free that object before the worker dereferences pd->pp or pd->next. The worker's securetcp_lock does not serialize with protocol cleanup. A concurrent defense-mode sysctl write can reach the same timeout update path.

KASAN reported:

  BUG: KASAN: slab-use-after-free in ip_vs_protocol_timeout_change
  Workqueue: events_long defense_work_handler
  Call Trace:
   ip_vs_protocol_timeout_change+0x1b4/0x1e0
   update_defense_level+0x63e/0xd80
   defense_work_handler+0x1e/0xc0
  Allocated by task 125:
   ip_vs_protocol_net_init+0xda/0x2f0
   __ip_vs_init+0x16b/0x240
   setup_net+0xfc/0x310
  Freed by task 12:
   ip_vs_protocol_net_cleanup+0x1d6/0x2e0
   __ip_vs_cleanup_batch+0x7d/0x100
   cleanup_net+0x38c/0x770

Run control cleanup before protocol cleanup so that defense work and active sysctl handlers have finished before their protocol data is freed. Initialize protocols before exposing the control interface, and unwind in reverse order, to enforce the same lifetime on initialization failure. Protocol initialization and exit do not depend on control state.

Fixes 9330419d9aa4 ("IPVS: netns, use ip_vs_proto_data as param.")
---
 net/netfilter/ipvs/ip_vs_core.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +6 -6
index fd503f0efb57..8a3c880fdb26 100644
@@ -2502,12 +2502,12 @@ static int __net_init __ip_vs_init(struct net *net)
 	if (ip_vs_estimator_net_init(ipvs) < 0)
 		goto estimator_fail;
 
-	if (ip_vs_control_net_init(ipvs) < 0)
-		goto control_fail;
-
 	if (ip_vs_protocol_net_init(ipvs) < 0)
 		goto protocol_fail;
 
+	if (ip_vs_control_net_init(ipvs) < 0)
+		goto control_fail;
+
 	if (ip_vs_app_net_init(ipvs) < 0)
 		goto app_fail;
 
@@ -2527,10 +2527,10 @@ static int __net_init __ip_vs_init(struct net *net)
 conn_fail:
 	ip_vs_app_net_cleanup(ipvs);
 app_fail:
-	ip_vs_protocol_net_cleanup(ipvs);
-protocol_fail:
 	ip_vs_control_net_cleanup(ipvs);
 control_fail:
+	ip_vs_protocol_net_cleanup(ipvs);
+protocol_fail:
 	ip_vs_estimator_net_cleanup(ipvs);
 estimator_fail:
 	net->ipvs = NULL;
@@ -2547,8 +2547,8 @@ static void __net_exit __ip_vs_cleanup_batch(struct list_head *net_list)
 		ipvs = net_ipvs(net);
 		ip_vs_conn_net_cleanup(ipvs);
 		ip_vs_app_net_cleanup(ipvs);
-		ip_vs_protocol_net_cleanup(ipvs);
 		ip_vs_control_net_cleanup(ipvs);
+		ip_vs_protocol_net_cleanup(ipvs);
 		ip_vs_estimator_net_cleanup(ipvs);
 		IP_VS_DBG(2, "ipvs netns %d released\n", ipvs->gen);
 		net->ipvs = NULL;
Signature · 1 line
2.47.3
author maintainer
#7 lore raw

PATCH v4 4/12 netfilter: nf_dup: preserve guard across NFQUEUE reinjection

In reply to Pablo Neira Ayuso

From: Zihan Xi <[email protected]>

NFQUEUE can suspend traversal of a duplicated packet while the task-local duplication guard is set. The output call then returns and clears the guard before a later verdict resumes hook traversal.

Save the guard in the queue entry and restore it while reinjection continues hook traversal. Preserve and restore the verdict task's prior state, including nested synchronous reinjection.

Fixes cd58bcd9787e ("netfilter: xt_TEE: have cloned packet travel through Xtables too")
Assisted-by LLM
---
 include/net/netfilter/nf_queue.h |  1 +
 net/netfilter/nf_queue.c         |  1 +
 net/netfilter/nfnetlink_queue.c  | 17 ++++++++++++++---
 3 files changed, 16 insertions(+), 3 deletions(-)
include/net/netfilter/nf_queue.h +1 -0
index 86021c55ba3c..4a8cefd8398d 100644
@@ -23,6 +23,7 @@ struct nf_queue_entry {
 	struct net_device	*physout;
 #endif
 	struct nf_hook_state	state;
+	bool			in_nf_duplicate;
 	bool			nf_ct_is_unconfirmed;
 	u16			size; /* sizeof(entry) + saved route keys */
 
net/netfilter/nf_queue.c +1 -0
index 166d05e994ac..bd603e3a99a5 100644
@@ -219,6 +219,7 @@ static int __nf_queue(struct sk_buff *skb, const struct nf_hook_state *state,
 	*entry = (struct nf_queue_entry) {
 		.skb	= skb,
 		.skb_dev = skb->dev,
+		.in_nf_duplicate = current->in_nf_duplicate,
 		.state	= *state,
 		.hook_index = index,
 		.size	= sizeof(*entry) + route_key_size,
net/netfilter/nfnetlink_queue.c +14 -3
index 90d887546f7d..a8aa7ad832c3 100644
@@ -44,6 +44,7 @@
 #include <net/sock.h>
 #include <net/tcp_states.h>
 #include <net/netfilter/nf_queue.h>
+#include <net/net_debug.h>
 #include <net/netns/generic.h>
 
 #include <linux/atomic.h>
@@ -365,21 +366,30 @@ static void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict)
 	const struct nf_hook_entry *hook_entry;
 	const struct nf_hook_entries *hooks;
 	struct sk_buff *skb = entry->skb;
+	bool old_in_nf_duplicate;
 	const struct net *net;
 	unsigned int i;
 	int err;
 	u8 pf;
 
+	DEBUG_NET_WARN_ONCE(current->in_nf_duplicate &&
+			    !entry->in_nf_duplicate,
+			    "%s called with unexpected duplication guard",
+			    __func__);
+	local_bh_disable();
+	old_in_nf_duplicate = current->in_nf_duplicate;
+
 	net = entry->state.net;
 	pf = entry->state.pf;
 
+	current->in_nf_duplicate = entry->in_nf_duplicate;
 	hooks = nf_hook_entries_head(net, pf, entry->state.hook);
 
 	i = entry->hook_index;
 	if (!hooks || i >= hooks->num_hook_entries) {
 		kfree_skb_reason(skb, SKB_DROP_REASON_NETFILTER_DROP);
 		nf_queue_entry_free(entry);
-		return;
+		goto out;
 	}
 
 	hook_entry = &hooks->hooks[i];
@@ -402,9 +412,7 @@ static void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict)
 	switch (verdict & NF_VERDICT_MASK) {
 	case NF_ACCEPT:
 	case NF_STOP:
-		local_bh_disable();
 		entry->state.okfn(entry->state.net, entry->state.sk, skb);
-		local_bh_enable();
 		break;
 	case NF_QUEUE:
 		err = nf_queue(skb, &entry->state, i, verdict);
@@ -418,6 +426,9 @@ static void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict)
 	}
 
 	nf_queue_entry_free(entry);
+out:
+	current->in_nf_duplicate = old_in_nf_duplicate;
+	local_bh_enable();
 }
 
 /* return true if the entry has an unconfirmed conntrack attached that isn't owned by us
Signature · 1 line
2.47.3
author maintainer
#8 lore raw

PATCH v4 5/12 netfilter: flowtable: extend ct timeout of offloaded GRE flows

In reply to Pablo Neira Ayuso

From: Michail Andreas Michalopoulos <[email protected]>

Since commit 03428ca5cee9 ("netfilter: conntrack: rework offload nf_conn timeout extension logic"), the flowtable gc worker extends the timeout of an offloaded conntrack entry from nf_flow_table_extend_ct_timeout() once it falls below 5 minutes. That function only knows about TCP and UDP and hits WARN_ON_ONCE() for any other layer 4 protocol. However, GRE flows can be offloaded too, both via nft_flow_offload and act_ct, since commit 4e8d9584d154 ("netfilter: flowtable: Support GRE").

The timeout of an offloaded GRE entry drops below that threshold as soon as a packet of the flow still goes through conntrack. With ip6gre tunnels using the default encapsulation limit this is ordinary traffic:
the flowtable does not parse the Destination Options header in front of GRE, so every packet of the flow takes the classic forwarding path. It also happens for a packet with ttl <= 1, which the flowtable fast path passes up to the classic forwarding path. nf_conntrack_gre_packet() then refreshes ct->timeout to the GRE stream timeout (180 seconds by default), and the next gc run triggers, as reported by syzbot:

  WARNING: net/netfilter/nf_flow_table_core.c:553 at nf_flow_table_extend_ct_timeout+0x1ee/0x2f0
  Workqueue: events_power_efficient nf_flow_offload_work_gc
  Call Trace:
   nf_flow_offload_gc_step+0x545/0x7b0
   nf_flow_table_iterate+0x13c/0x1f0
   nf_flow_offload_work_gc+0x22/0x70
   process_scheduled_works+0xc3d/0x1630
   worker_thread+0xa47/0xfb0
   kthread+0x38b/0x480

Besides the splat, which panics the machine with panic_on_warn, the default branch sets the new timeout to 1 jiffy, so the conntrack entry expires right away and the offloaded flow is torn down.

Handle GRE like UDP and extend the timeout to NF_CT_DAY. GRE conntrack has no protocol state to take into account, and NF_CT_DAY is also what flow_offload_add() already sets for every offloaded entry, GRE included. This also restores the behaviour from before commit 03428ca5cee9, when the conntrack gc worker extended offloaded entries of any protocol to NF_CT_DAY.

Fixes 03428ca5cee9 ("netfilter: conntrack: rework offload nf_conn timeout extension logic")
Reported-by [email protected]
Assisted-by LLM
---
 net/netfilter/nf_flow_table_core.c | 1 +
 1 file changed, 1 insertion(+)
net/netfilter/nf_flow_table_core.c +1 -0
index 0d72dc8ae47a..2aa2647ed9df 100644
@@ -544,6 +544,7 @@ static void nf_flow_table_extend_ct_timeout(struct nf_conn *ct)
 
 		switch (l4proto) {
 		case IPPROTO_UDP:
+		case IPPROTO_GRE:
 			new_timeout = NF_CT_DAY;
 			break;
 		case IPPROTO_TCP:
Signature · 1 line
2.47.3
author maintainer
#9 lore raw

PATCH v4 6/12 netfilter: nft_set_rbtree: check catchall_sync return before queue_done

In reply to Pablo Neira Ayuso

From: Xingyuan Mo <[email protected]>

nft_rbtree_gc_queue() passes the result of nft_trans_gc_catchall_sync() straight to nft_trans_gc_queue_sync_done(). When the catchall path flushes a full GC batch and nft_trans_gc_alloc() fails, catchall_sync returns NULL and queue_sync_done dereferences trans->net (NULL+0x10). Guard the call like the pipapo GC path already does.

Fixes 7d259f021aaa ("netfilter: nft_set_rbtree: prefer sync gc to async worker")
Assisted-by opencode:deepseek-v4
---
 net/netfilter/nft_set_rbtree.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/nft_set_rbtree.c +2 -1
index fbe1750f1ca2..9d685899da70 100644
@@ -953,7 +953,8 @@ static void nft_rbtree_gc_queue(struct nft_set *set)
 	}
 
 	gc = nft_trans_gc_catchall_sync(gc);
-	nft_trans_gc_queue_sync_done(gc);
+	if (gc)
+		nft_trans_gc_queue_sync_done(gc);
 }
 
 static u64 nft_rbtree_privsize(const struct nlattr * const nla[],
Signature · 1 line
2.47.3
author maintainer
#10 lore raw

PATCH v4 7/12 netfilter: bridge: use DEBUG_NET_WARN_ON_ONCE in nf_ct_bridge_refrag()

In reply to Pablo Neira Ayuso

From: Laveesh Bansal <[email protected]>

nf_ct_bridge_refrag() warns when skb->protocol is neither IPv4 nor IPv6. A vlan filtering bridge can get there with a vlan ethertype: if the protocol of the tag of a frame differs from the vlan_protocol of the bridge, br_allowed_ingress() moves the tag back into the packet after NF_BR_PRE_ROUTING, where bridge conntrack has already defragmented it.

Anyone who can send fragments into a port of such a bridge can trigger the warning, which takes the machine down with panic_on_warn. The packet is dropped either way, so only warn on kernels built with CONFIG_DEBUG_NET.

This only avoids the warning. Such fragmented packets are still dropped. syzbot reported the warning. It keeps triggering on CONFIG_DEBUG_NET kernels until the vlan tag is handled, which is left for a follow-up:

https://syzkaller.appspot.com/bug?extid=a8ba738fe2db6b4bb27f

Fixes 3c171f496ef5 ("netfilter: bridge: add connection tracking system")
Assisted-by LLM
---
 net/bridge/netfilter/nf_conntrack_bridge.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/bridge/netfilter/nf_conntrack_bridge.c +1 -1
index b5444335b86f..8c83dc05114b 100644
@@ -358,7 +358,7 @@ nf_ct_bridge_refrag(struct sk_buff *skb, const struct nf_hook_state *state,
 		nf_br_ip6_fragment(state->net, state->sk, skb, &data, output);
 		break;
 	default:
-		WARN_ON_ONCE(1);
+		DEBUG_NET_WARN_ON_ONCE(1);
 		return NF_DROP;
 	}
 
Signature · 1 line
2.47.3
author maintainer
#11 lore raw

PATCH v4 8/12 netfilter: x_tables: check target name before accessing verdict

In reply to Pablo Neira Ayuso

From: Fernando Fernandez Mancera <[email protected]>

Non-standard targets may contain only struct xt_entry_target. mark_source_chains() nevertheless reads the target as an xt_standard_target before checking its name, potentially reading four bytes beyond a header-only target.

Check that the target is standard before reading its verdict. Non-standard targets remain handled as fallthrough rules.

See the following KASAN trace:

BUG: KASAN: slab-out-of-bounds in translate_table+0x1660/0x1a40 [ip6_tables]
Read of size 4 at addr ffff88800ed56ff8 by task rep/432

Call Trace:
 kasan_report+0xfa/0x120
 translate_table+0x1660/0x1a40 [ip6_tables]
 do_ip6t_set_ctl+0x667/0xa76 [ip6_tables]
 nf_setsockopt+0x77/0xd0
 do_sock_setsockopt+0x118/0x490
 __sys_setsockopt+0xe4/0x160
 __x64_sys_setsockopt+0xbd/0x190
 do_syscall_64+0xde/0x4f0
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Allocated by task 432:
 kasan_save_stack+0x2f/0x50
 __kasan_kmalloc+0x7f/0x90
 __kvmalloc_node_noprof+0x1b1/0x5c0
 xt_alloc_table_info+0x3c/0xa0
 do_ip6t_set_ctl+0x5ee/0xa76 [ip6_tables]
 nf_setsockopt+0x77/0xd0
 do_sock_setsockopt+0x118/0x490
 __sys_setsockopt+0xe4/0x160
 __x64_sys_setsockopt+0xbd/0x190
 do_syscall_64+0xde/0x4f0
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 net/ipv4/netfilter/arp_tables.c | 5 +++--
 net/ipv4/netfilter/ip_tables.c  | 5 +++--
 net/ipv6/netfilter/ip6_tables.c | 5 +++--
 3 files changed, 9 insertions(+), 6 deletions(-)
net/ipv4/netfilter/arp_tables.c +3 -2
index cf747e1e17a3..7ff3d1f0ffd4 100644
@@ -371,11 +371,12 @@ static int mark_source_chains(const struct xt_table_info *newinfo,
 				e->counters.pcnt = pos;
 				pos += size;
 			} else {
-				int newpos = t->verdict;
+				int newpos;
 
 				if (strcmp(t->target.u.user.name,
 					   XT_STANDARD_TARGET) == 0 &&
-				    newpos >= 0) {
+				    t->verdict >= 0) {
+					newpos = t->verdict;
 					/* This a jump; chase it. */
 					if (!xt_find_jump_offset(offsets, newpos,
 								 newinfo->number))
net/ipv4/netfilter/ip_tables.c +3 -2
index 809441cedced..b302bd77180a 100644
@@ -422,11 +422,12 @@ mark_source_chains(const struct xt_table_info *newinfo,
 				e->counters.pcnt = pos;
 				pos += size;
 			} else {
-				int newpos = t->verdict;
+				int newpos;
 
 				if (strcmp(t->target.u.user.name,
 					   XT_STANDARD_TARGET) == 0 &&
-				    newpos >= 0) {
+				    t->verdict >= 0) {
+					newpos = t->verdict;
 					/* This a jump; chase it. */
 					if (!xt_find_jump_offset(offsets, newpos,
 								 newinfo->number))
net/ipv6/netfilter/ip6_tables.c +3 -2
index 313c4aac377a..010baaa60665 100644
@@ -440,11 +440,12 @@ mark_source_chains(const struct xt_table_info *newinfo,
 				e->counters.pcnt = pos;
 				pos += size;
 			} else {
-				int newpos = t->verdict;
+				int newpos;
 
 				if (strcmp(t->target.u.user.name,
 					   XT_STANDARD_TARGET) == 0 &&
-				    newpos >= 0) {
+				    t->verdict >= 0) {
+					newpos = t->verdict;
 					/* This a jump; chase it. */
 					if (!xt_find_jump_offset(offsets, newpos,
 								 newinfo->number))
Signature · 1 line
2.47.3
author maintainer
#12 lore raw

PATCH v4 9/12 netfilter: nf_conntrack_sip: fix OOB read in ct_sip_parse_transport()

In reply to Pablo Neira Ayuso

From: Joas Antonio dos Santos <[email protected]>

ct_sip_parse_transport() compares the value of the "transport=" header parameter against "TCP"/"UDP" with strncasecmp(..., 3), but it never checks that the parsed value is at least 3 bytes long.

ct_sip_parse_param() returns matchlen = end - start, where end is the next ';' or, when there is no ';', the end of the payload buffer (limit = dptr + datalen). If the "transport=" value is only 1 or 2 bytes long and runs exactly to the end of the payload (e.g. a REGISTER request whose Contact header ends in ";transport=T" with no trailing CRLF), matchlen is less than 3 while strncasecmp() still reads up to 3 bytes, reading 1-2 bytes past the end of the linearized skb data.

Add a matchlen check before the comparison, mirroring the sdp_media_type() pattern a few lines below, so short values cannot reach strncasecmp().

The bug was found by LLM-assisted manual review of the SIP helper's parsers and confirmed with a userspace ASan harness built from the verbatim parser functions, which reports a heap-buffer-overflow read of size 2 in strncasecmp() called from ct_sip_parse_transport().

Fixes ea45f12a2766d ("[NETFILTER]: nf_conntrack_sip: parse SIP headers properly")
Assisted-by Claude:claude-opus-5-5
---
 net/netfilter/nf_conntrack_sip.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nf_conntrack_sip.c +2 -2
index 64bc440b1181..b05dc8858d09 100644
@@ -701,9 +701,9 @@ static int ct_sip_parse_transport(struct nf_conn *ct, const char *dptr,
 
 	if (ct_sip_parse_param(ct, dptr, dataoff, datalen, "transport=",
 			       &matchoff, &matchlen)) {
-		if (!strncasecmp(dptr + matchoff, "TCP", strlen("TCP")))
+		if (matchlen >= 3 && !strncasecmp(dptr + matchoff, "TCP", 3))
 			*proto = IPPROTO_TCP;
-		else if (!strncasecmp(dptr + matchoff, "UDP", strlen("UDP")))
+		else if (matchlen >= 3 && !strncasecmp(dptr + matchoff, "UDP", 3))
 			*proto = IPPROTO_UDP;
 		else
 			return 0;
Signature · 1 line
2.47.3
author maintainer
#13 lore raw

PATCH v4 10/12 netfilter: nf_tables: fix memleak when rule deletion fails with hardware offload

In reply to Pablo Neira Ayuso

Allocate flow rule object after transaction has been allocation and rule deactivation has been performed, otherwise memleak is possible. Let the transaction unwind the existing rule deactivation from the abort path, this needs to update nft_flow_rule_destroy() to skip release if flow_rule is null.

While at this, remove check for non-null flow_rule in newrule error path now that nft_flow_rule_destroy() is skipped if flow_rule is null.

Fixes 63b48c73ff56 ("netfilter: nf_tables_offload: undo updates if transaction fails")
---
 net/netfilter/nf_tables_api.c     | 21 +++++++++------------
 net/netfilter/nf_tables_offload.c |  3 +++
 2 files changed, 12 insertions(+), 12 deletions(-)
net/netfilter/nf_tables_api.c +9 -12
index 59ac623e6805..8b94b5e7dbdb 100644
@@ -760,16 +760,6 @@ static int nft_delrule(struct nft_ctx *ctx, struct nft_rule *rule)
 	if (trans == NULL)
 		return -ENOMEM;
 
-	if (ctx->chain->flags & NFT_CHAIN_HW_OFFLOAD) {
-		flow = nft_flow_rule_create(ctx->net, rule);
-		if (IS_ERR(flow)) {
-			nft_trans_destroy(trans);
-			return PTR_ERR(flow);
-		}
-
-		nft_trans_flow_rule(trans) = flow;
-	}
-
 	err = nf_tables_delrule_deactivate(ctx, rule);
 	if (err < 0) {
 		nft_trans_destroy(trans);
@@ -777,6 +767,14 @@ static int nft_delrule(struct nft_ctx *ctx, struct nft_rule *rule)
 	}
 	nft_rule_expr_deactivate(ctx, rule, NFT_TRANS_PREPARE);
 
+	if (ctx->chain->flags & NFT_CHAIN_HW_OFFLOAD) {
+		flow = nft_flow_rule_create(ctx->net, rule);
+		if (IS_ERR(flow))
+			return PTR_ERR(flow);
+
+		nft_trans_flow_rule(trans) = flow;
+	}
+
 	return 0;
 }
 
@@ -4570,8 +4568,7 @@ static int nf_tables_newrule(struct sk_buff *skb, const struct nfnl_info *info,
 err_destroy_flow_rule:
 	nft_use_dec_restore(&chain->use);
 err_destroy_flow:
-	if (flow)
-		nft_flow_rule_destroy(flow);
+	nft_flow_rule_destroy(flow);
 err_release_rule:
 	nft_rule_expr_deactivate(&ctx, rule, NFT_TRANS_PREPARE_ERROR);
 	nf_tables_rule_destroy(&ctx, rule);
net/netfilter/nf_tables_offload.c +3 -0
index 0ac3c26dfb3d..48b9e58e0c44 100644
@@ -148,6 +148,9 @@ void nft_flow_rule_destroy(struct nft_flow_rule *flow)
 	struct flow_action_entry *entry;
 	int i;
 
+	if (!flow)
+		return;
+
 	flow_action_for_each(i, entry, &flow->rule->action) {
 		switch (entry->id) {
 		case FLOW_ACTION_REDIRECT:
Signature · 1 line
2.47.3
author maintainer
#14 lore raw

PATCH v4 11/12 netfilter: xt_recent: do not call remove_proc_entry() under recent_lock

In reply to Pablo Neira Ayuso

From: "Cen Zhang (Microsoft)" <[email protected]>

recent_proc_net_exit() removes the /proc/net/xt_recent/<name> entries of a dying network namespace while holding spin_lock_bh(&recent_lock). remove_proc_entry() may sleep: proc_entry_rundown() waits until every task that is still inside the entry's file operations has left. A reader of such an entry is counted in by proc_reg_read() before recent_seq_start() takes recent_lock. So if a read is in flight when the namespace is torn down, cleanup_net() sleeps in atomic context holding the spinlock that the reader is spinning on, and neither side can ever make progress.

An unprivileged user can trigger this from a user namespace by adding a rule with the "recent" match and reading its proc file while the namespace is being destroyed. As recent_lock is global, every later attempt to take it spins forever too: the spinning can spread to all CPUs, and network namespace teardown stops system-wide.

  BUG: sleeping function called from invalid context at
    kernel/sched/completion.c:116
   #3: (recent_lock){+...}-{3:3}, at: recent_net_exit+0x2b/0x140
  Workqueue: netns cleanup_net
  Call Trace:
   proc_entry_rundown+0x185/0x1b0
   remove_proc_entry+0x21a/0x520
   recent_net_exit+0x7f/0x140
   cleanup_net+0x414/0x8f0
  ...
  rcu: INFO: rcu_preempt self-detected stall on CPU
  Call Trace:
   queued_spin_lock_slowpath+0x313/0xc20
   recent_seq_start+0x87/0x1b0
   seq_read_iter+0x265/0x11e0
   proc_reg_read+0x1ab/0x270

Fix by taking recent_mutex instead of recent_lock. According to commit a0e889bb1bdc ("[NETFILTER]: recent match: fix "sleeping function called from invalid context""), recent_mutex is the lock to use here: it protects recent_net->tables and was introduced so that proc entries are created and removed without recent_lock held, because those calls may sleep. hashlimit_proc_net_exit() does the same for xt_hashlimit.

Fixes 665e205c16c1 ("netfilter: xt_recent: fix namespace destroy path")
---
 net/netfilter/xt_recent.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
net/netfilter/xt_recent.c +4 -3
index 55f1f2d89952..00cccf003cff 100644
@@ -650,14 +650,15 @@ static void __net_exit recent_proc_net_exit(struct net *net)
 
 	/* recent_net_exit() is called before recent_mt_destroy(). Make sure
 	 * that the parent xt_recent proc entry is empty before trying to
-	 * remove it.
+	 * remove it. Use recent_mutex instead of recent_lock since
+	 * remove_proc_entry() may sleep.
 	 */
-	spin_lock_bh(&recent_lock);
+	mutex_lock(&recent_mutex);
 	list_for_each_entry(t, &recent_net->tables, list)
 	        remove_proc_entry(t->name, recent_net->xt_recent);
 
 	recent_net->xt_recent = NULL;
-	spin_unlock_bh(&recent_lock);
+	mutex_unlock(&recent_mutex);
 
 	remove_proc_entry("xt_recent", net->proc_net);
 }
Signature · 1 line
2.47.3
author maintainer
#15 lore raw

PATCH v4 12/12 netfilter: nat: zero newrange before filling it in

In reply to Pablo Neira Ayuso

From: Florian Westphal <[email protected]>

nf_nat_masquerade_ipv4(), nf_nat_masquerade_ipv6(), netmap_tg4() and netmap_tg6() each build a stack-local struct nf_nat_range2 from the caller-supplied range, inheriting range->flags unmodified. Two of them only memset() the min_addr/max_addr members, the other two don't memset() anything at all, so newrange.base_proto is left as stack garbage.

If the inherited flags include NF_NAT_RANGE_PROTO_OFFSET, nf_nat_l4proto_unique_tuple() reads range->base_proto.all to compute the NAT port offset. Neither the NETMAP nor the MASQUERADE targets mask the flags field in their checkentry callback, so this uninitialized stack value can end up feeding the NAT port selection.

The per-member memset()s are not enough: they have to enumerate every field that must be cleared, and base_proto was missed when NF_NAT_RANGE_PROTO_OFFSET/base_proto was added to the struct. memset() the whole struct instead, so every member is covered regardless of which ones get explicitly assigned afterwards.

There are other places that miss this, but those hardcode .flags so nat core won't read from the uninitialized fields.

C99 initializers would be preferrable, but this is a more intrusive change. Lets followup in nf-next and convert others as well.

This is an LLM finding.

Fixes 2eb0f624b709 ("netfilter: add NAT support for shifted portmap ranges")
---
 net/netfilter/nf_nat_masquerade.c | 4 ++--
 net/netfilter/xt_NETMAP.c         | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
net/netfilter/nf_nat_masquerade.c +2 -2
index 4de6e0a51701..c2a85bd84af1 100644
@@ -62,8 +62,7 @@ nf_nat_masquerade_ipv4(struct sk_buff *skb, unsigned int hooknum,
 		nat->masq_index = out->ifindex;
 
 	/* Transfer from original range. */
-	memset(&newrange.min_addr, 0, sizeof(newrange.min_addr));
-	memset(&newrange.max_addr, 0, sizeof(newrange.max_addr));
+	memset(&newrange, 0, sizeof(newrange));
 	newrange.flags       = range->flags | NF_NAT_RANGE_MAP_IPS;
 	newrange.min_addr.ip = newsrc;
 	newrange.max_addr.ip = newsrc;
@@ -242,6 +241,7 @@ nf_nat_masquerade_ipv6(struct sk_buff *skb, const struct nf_nat_range2 *range,
 	if (nat)
 		nat->masq_index = out->ifindex;
 
+	memset(&newrange, 0, sizeof(newrange));
 	newrange.flags		= range->flags | NF_NAT_RANGE_MAP_IPS;
 	newrange.min_addr.in6	= src;
 	newrange.max_addr.in6	= src;
net/netfilter/xt_NETMAP.c +2 -2
index 7da065a472e0..8bcb3f716d68 100644
@@ -44,6 +44,7 @@ netmap_tg6(struct sk_buff *skb, const struct xt_action_param *par)
 				   netmask.ip6[i];
 	}
 
+	memset(&newrange, 0, sizeof(newrange));
 	newrange.flags	= range->flags | NF_NAT_RANGE_MAP_IPS;
 	newrange.min_addr	= new_addr;
 	newrange.max_addr	= new_addr;
@@ -91,8 +92,7 @@ netmap_tg4(struct sk_buff *skb, const struct xt_action_param *par)
 		new_ip = ip_hdr(skb)->saddr & ~netmask;
 	new_ip |= mr->range[0].min_ip & netmask;
 
-	memset(&newrange.min_addr, 0, sizeof(newrange.min_addr));
-	memset(&newrange.max_addr, 0, sizeof(newrange.max_addr));
+	memset(&newrange, 0, sizeof(newrange));
 	newrange.flags	     = mr->range[0].flags | NF_NAT_RANGE_MAP_IPS;
 	newrange.min_addr.ip = new_ip;
 	newrange.max_addr.ip = new_ip;
Signature · 1 line
2.47.3
maintainer
#16 lore raw
In reply to Pablo Neira Ayuso
Quoted 10 lines · On Thu, 5 Nov 2026 13:45:24 +0100 Pablo Neira Ayuso wrote:

v4: - Drop "ipvs: do not create conns from packets with port 0".

This PR was already reviewed in its v2 by netdev-ai-bots. I have dropped all the patches that LLM flagged as needing more work even since.

But I really think v3 was good enough and a follow up for "ipvs: do not create conns from packets with port 0" was just fine to proceed.

Quoted 7 lines

Maybe patchbot will ban this pull request again, v3 was blocklisted for not fulfulling the 24 hours rule, that is why it was not reviewed.

But, as said, this was all reviewed in PR v2 already, this is just keeping back 3 patches included in PR v1 needing more work.

netdev CI keeps hitting a kmemleak since this morning, lines up with this series, tho TBH I have done 0 investigating...

$ cat /sys/kernel/debug/kmemleak
unreferenced object (percpu) 0xc0ffff86522458 (size 12):
  comm "modprobe", pid 17854, jiffies 4295218150
  hex dump (first 12 bytes on cpu 0):
    00 00 00 00 00 00 00 00 00 00 00 00              ............
  backtrace (crc 0):
    pcpu_alloc_noprof+0x76b/0xd70
    nf_flow_table_pernet_init+0x46/0x90 [nf_flow_table]
    ops_init+0x187/0x570
    register_pernet_operations+0x395/0x8e0
    register_pernet_subsys+0x28/0x40
    nft_masq_dump+0x66/0x190 [nft_masq]
    do_one_initcall+0x124/0x4f0
    do_init_module+0x2ad/0x8a0
    load_module+0x154b/0x1d60
    init_module_from_file+0x11f/0x1a0
    idempotent_init_module+0x37b/0x7c0
    __x64_sys_finit_module+0xdf/0x190
    do_syscall_64+0x10e/0x570
    entry_SYSCALL_64_after_hwframe+0x4b/0x53
author maintainer
#17 lore raw
Quoted 22 lines · Jakub Kicinski
Quoted 10 lines · On Thu, 5 Nov 2026 13:45:24 +0100 Pablo Neira Ayuso wrote:

v4: - Drop "ipvs: do not create conns from packets with port 0".

This PR was already reviewed in its v2 by netdev-ai-bots. I have dropped all the patches that LLM flagged as needing more work even since.

But I really think v3 was good enough and a follow up for "ipvs: do not create conns from packets with port 0" was just fine to proceed.

Quoted 7 lines

Maybe patchbot will ban this pull request again, v3 was blocklisted for not fulfulling the 24 hours rule, that is why it was not reviewed.

But, as said, this was all reviewed in PR v2 already, this is just keeping back 3 patches included in PR v1 needing more work.

netdev CI keeps hitting a kmemleak since this morning, lines up with this series, tho TBH I have done 0 investigating...

Quoted 8 lines
$ cat /sys/kernel/debug/kmemleak
unreferenced object (percpu) 0xc0ffff86522458 (size 12):
  comm "modprobe", pid 17854, jiffies 4295218150
  hex dump (first 12 bytes on cpu 0):
    00 00 00 00 00 00 00 00 00 00 00 00              ............
  backtrace (crc 0):
    pcpu_alloc_noprof+0x76b/0xd70
    nf_flow_table_pernet_init+0x46/0x90 [nf_flow_table]

This is not handled by this PR.

I will submit a patch for this asap.

Quoted 13 lines
    ops_init+0x187/0x570
    register_pernet_operations+0x395/0x8e0
    register_pernet_subsys+0x28/0x40
    nft_masq_dump+0x66/0x190 [nft_masq]
    do_one_initcall+0x124/0x4f0
    do_init_module+0x2ad/0x8a0
    load_module+0x154b/0x1d60
    init_module_from_file+0x11f/0x1a0
    idempotent_init_module+0x37b/0x7c0
    __x64_sys_finit_module+0xdf/0x190
    do_syscall_64+0x10e/0x570
    entry_SYSCALL_64_after_hwframe+0x4b/0x53
author maintainer
#18 lore raw
Quoted 16 lines · Pablo Neira Ayuso
Quoted 15 lines · Jakub Kicinski
Quoted 14 lines · On Thu, 5 Nov 2026 13:45:24 +0100 Pablo Neira Ayuso wrote:

v4: - Drop "ipvs: do not create conns from packets with port 0".

This PR was already reviewed in its v2 by netdev-ai-bots. I have dropped all the patches that LLM flagged as needing more work even since.

But I really think v3 was good enough and a follow up for "ipvs: do not create conns from packets with port 0" was just fine to proceed.

Maybe patchbot will ban this pull request again, v3 was blocklisted for not fulfulling the 24 hours rule, that is why it was not reviewed.

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

But, as said, this was all reviewed in PR v2 already, this is just keeping back 3 patches included in PR v1 needing more work.

netdev CI keeps hitting a kmemleak since this morning, lines up with this series, tho TBH I have done 0 investigating...

To clarify further: I think it is just a coincidence, I don't see anything in this PR related to this.

There is a known bug related to this in the pernetns exit path, I post a patch already but is flawed, I'm looking at improving the situation with a bug fix :-)

Quoted 27 lines
Quoted 8 lines
$ cat /sys/kernel/debug/kmemleak
unreferenced object (percpu) 0xc0ffff86522458 (size 12):
  comm "modprobe", pid 17854, jiffies 4295218150
  hex dump (first 12 bytes on cpu 0):
    00 00 00 00 00 00 00 00 00 00 00 00              ............
  backtrace (crc 0):
    pcpu_alloc_noprof+0x76b/0xd70
    nf_flow_table_pernet_init+0x46/0x90 [nf_flow_table]

This is not handled by this PR.

I will submit a patch for this asap.

Quoted 13 lines
    ops_init+0x187/0x570
    register_pernet_operations+0x395/0x8e0
    register_pernet_subsys+0x28/0x40
    nft_masq_dump+0x66/0x190 [nft_masq]
    do_one_initcall+0x124/0x4f0
    do_init_module+0x2ad/0x8a0
    load_module+0x154b/0x1d60
    init_module_from_file+0x11f/0x1a0
    idempotent_init_module+0x37b/0x7c0
    __x64_sys_finit_module+0xdf/0x190
    do_syscall_64+0x10e/0x570
    entry_SYSCALL_64_after_hwframe+0x4b/0x53