Netfilter/IPVS updates for net-next
Subsystems (8)
Pablo Neira Ayuso
maintainercover Netfilter/IPVS updates for net-next
Hi,
The following patchset contains Netfilter/IPVS updates for net-next:
1) Disable br_netfilter in userns and schedule it for removal in 2027, from Florian Westphal.
2) Prepare the flowtable to support for IPv4 over IPv6 tunneling and vice-versa, this includes 5 patches from Lorenzo Bianconi.
3) Update selftest nft_queue.sh to make it more stable on debug kernels, from Jakub Kicinski.
4) Fix a overflow in IPVS sync messages which can only happen in very old 2.6 kernels, from Julian Anastasov.
5) Flush conntrack gc worker when existing netns to address a unlikely UaF, from Florian Westphal.
6) Switch nf_tables chain types to use rcu, otherwise module removal can trigger UaF, also from Florian.
7) Add two new helper functions to validate that socket is of inet type, coming in 2 patches from Florian Westphal.
8) Remove redundant parsing in nft_exthdr for the tcp options case, from Fernando F. Mancera.
9) Remove redundant skb_header_pointer() calls in nft_exthdr for tcp options, from Fernando F. Mancera.
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next.git nf-next-26-10-11
Thanks.
----------------------------------------------------------------
The following changes since commit a5e7d8e446af9803e37a3b6a4d416fb41178348f:
Merge branch '100GbE' of git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/next-queue (2026-10-05 17:51:32 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next.git nf-next-26-10-11
for you to fetch changes up to b4074bbf5c23b05bd34022ade979f3d5f4e86516:
netfilter: nft_exthdr: avoid 60 bytes stack buffer in TCP option mangling (2026-10-11 23:29:26 +0200)
----------------------------------------------------------------
netfilter pull request 26-10-11
----------------------------------------------------------------
Fernando Fernandez Mancera (2):
netfilter: nft_exthdr: remove redundant op parsing in tcp_set_init
netfilter: nft_exthdr: avoid 60 bytes stack buffer in TCP option mangling
Florian Westphal (5):
netfilter: disable br_netfilter in user namespaces
netfilter: conntrack: fix unlikely UaF in gc worker
netfilter: nf_tables: switch chain_types array to rcu
netfilter: add nf_skb_sk helper and use it
netfilter: add nf_sk_to_full_sk helper and use it
Jakub Kicinski (1):
selftests: netfilter: nft_queue.sh: only queue icmp echo request/reply
Julian Anastasov (1):
ipvs: fix buffer overflow when sending sync messages
Lorenzo Bianconi (6):
netfilter: flowtable: recognize IPv4/IPv6 in tunnel proto matching
netfilter: flowtable: set inner protocol when popping tunnel header
netfilter: flowtable: populate tunnel tuple regardless of inner protocol
netfilter: flowtable: add encap_proto to flow_offload_tunnel
netfilter: flowtable: refactor MTU check for tunnel offload
netfilter: flowtable: unify tunnel push for IPv4 and IPv6
Documentation/networking/bridge.rst | 5 +- include/linux/netdevice.h | 1 + include/net/netfilter/nf_flow_table.h | 1 + include/net/netfilter/nf_socket.h | 35 ++++ net/bridge/br_netfilter_hooks.c | 33 +++- net/ipv4/ipip.c | 1 + net/ipv4/netfilter.c | 3 +- net/ipv6/ip6_tunnel.c | 1 + net/ipv6/netfilter.c | 3 +- net/netfilter/ipvs/ip_vs_sync.c | 23 ++- net/netfilter/nf_conntrack_core.c | 5 + net/netfilter/nf_flow_table_ip.c | 215 +++++++++++++-------- net/netfilter/nf_flow_table_path.c | 2 + net/netfilter/nf_tables_api.c | 94 ++++++--- net/netfilter/nft_chain_nat.c | 1 + net/netfilter/nft_exthdr.c | 34 ++-- net/netfilter/nft_socket.c | 16 +- net/netfilter/xt_socket.c | 26 +-- tools/testing/selftests/net/netfilter/nft_queue.sh | 2 +- 19 files changed, 336 insertions(+), 165 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/15 netfilter: disable br_netfilter in user namespaces
From: Florian Westphal <[email protected]>
br_netfilter has way too many bugs, schedule for removal and disable the feature in user namespaces.
In particular, we get more and more gadgets to have bridge ports escape rcu_read_lock() protection, then underlying device gets reconfigured (macvlan or something else), then reinject into network stack causes crash because net_device is assumed to still have bridge rx data associated with it.
br_netfilter is an ancient kludge that emulates ip stack from within the bridge and then calls into ipv4/ipv6 netfilter hooks to have bridged frames processed via iptables/ip6tables by setting the 'call-iptables' sysctls to 1. It is NOT related to ebtables or nftables 'bridge' family at all.
Note that in addition to call-iptables, sysctls, the bridge also exposes call-iptables per bridge device via netlink and sysfs ('BROPT_NF_CALL_IPTABLES') toggles.
Those are still available, the brnet structure is scoped to br_netfilter; exposing it bridge-wide is a big no-no.
This relies on brnf_device_event() no longer registering the base br_netfilter hooks, so while BROPT_NF_CALL_IPTABLES can be set, it has no effect because the hooks that evaluate this feature bit are never registered.
brnf_init_net can no longer depend on CONFIG_SYSCTL, else such builds never disable support in user namespaces.
--- Documentation/networking/bridge.rst | 5 +++-- net/bridge/br_netfilter_hooks.c | 33 ++++++++++++++++++++--------- 2 files changed, 26 insertions(+), 12 deletions(-)
Documentation/networking/bridge.rst +3 -2
@@ -277,8 +277,9 @@ Netfilter ========= The bridge netfilter module is a legacy feature that allows to filter bridged -packets with iptables and ip6tables. Its use is discouraged. Users should -consider using nftables for packet filtering. +packets with iptables and ip6tables. This feature is scheduled for removal and +not available in user namespaces. Consider using nftables for packet filtering +instead. The older ebtables tool is more feature-limited compared to nftables, but just like nftables it doesn't need this module either to function.
net/bridge/br_netfilter_hooks.c +23 -10
@@ -54,6 +54,7 @@ static unsigned int brnf_net_id __read_mostly;struct brnf_net {bool enabled; +bool in_userns;#ifdef CONFIG_SYSCTL struct ctl_table_header *ctl_hdr;
@@ -1100,7 +1101,7 @@ static int brnf_device_event(struct notifier_block *unused, unsigned long event, net =dev_net (dev); brnet =net_generic (net, brnf_net_id); -if (brnet->enabled) +if (brnet->enabled || brnet->in_userns)return NOTIFY_OK ; ret =nf_register_net_hooks (net, br_nf_ops,ARRAY_SIZE (br_nf_ops));
@@ -1229,9 +1230,11 @@ static inline void br_netfilter_sysctl_default(struct brnf_net *brnf) brnf->filter_pppoe_tagged =0 ; brnf->pass_vlan_indev = 0; } +#endif static int br_netfilter_sysctl_init_net (struct net *net) { +#ifdef CONFIG_SYSCTL struct ctl_table *table = brnf_table;struct brnf_net *brnet;
@@ -1259,25 +1262,39 @@ static int br_netfilter_sysctl_init_net(struct net *net)return -ENOMEM ; } - +#endif return 0 ; }static void br_netfilter_sysctl_exit_net (struct net *net,struct brnf_net *brnet) { -const struct ctl_table *table = brnet->ctl_hdr->ctl_table_arg; +#ifdef CONFIG_SYSCTL +struct ctl_table_header *header = brnet->ctl_hdr; +const struct ctl_table *table; -unregister_net_sysctl_table (brnet->ctl_hdr); +if (!header) +return ; + + table = header->ctl_table_arg; +unregister_net_sysctl_table (header);if (!net_eq (net, &init_net))kfree (table); +#endif }static int __net_init brnf_init_net (struct net *net) { +if (net->user_ns != &init_user_ns) { +struct brnf_net *brnet =net_generic (net, brnf_net_id); + + brnet->in_userns = true; +pr_warn_once ("br_netfilter no longer supported in user namespaces\n" ); +return 0 ; + } +return br_netfilter_sysctl_init_net (net); } -#endif static void __net_exit brnf_exit_net(struct net *net) {
@@ -1289,15 +1306,11 @@ static void __net_exit brnf_exit_net(struct net *net) brnet->enabled = false; } -#ifdef CONFIG_SYSCTL br_netfilter_sysctl_exit_net (net, brnet); -#endif }static struct pernet_operations brnf_net_ops__read_mostly = { -#ifdef CONFIG_SYSCTL .init = brnf_init_net, -#endif .exit = brnf_exit_net, .id = &brnf_net_id, .size =sizeof (struct brnf_net ),
@@ -1318,7 +1331,7 @@ static int __init br_netfilter_init(void) }RCU_INIT_POINTER (nf_br_ops, &br_ops); -printk (KERN_NOTICE "Bridge firewalling registered\n" ); +pr_warn ("br_netfilter is slated for removal in 2027.\n" );return 0 ; }
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 2/15 netfilter: flowtable: recognize IPv4/IPv6 in tunnel proto matching
In reply to Pablo Neira AyusoFrom: Lorenzo Bianconi <[email protected]>
Allow the flowtable to parse IPv4-in-IPv6 and IPv6-in-IPv4 tunnels by accepting both IPPROTO_IPIP and IPPROTO_IPV6 as the inner protocol when walking the outer header in nf_flow_ip4_tunnel_proto() and nf_flow_ip6_tunnel_proto(). This is a preliminary patch to support IPv4 over IPv6 and SIT tunnel flowtable offload.
Please note IPv4 over IPv6 and SIT tunnel flowtable offloading is not enabled yet.
--- net/netfilter/nf_flow_table_ip.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nf_flow_table_ip.c +2 -2
@@ -326,7 +326,7 @@ static bool nf_flow_ip4_tunnel_proto(struct nf_flowtable_ctx *ctx,if (iph->ttl <=1 )return false; -if (iph->protocol ==IPPROTO_IPIP ) { +if (iph->protocol ==IPPROTO_IPIP || iph->protocol ==IPPROTO_IPV6 ) { ctx->tun.inner_proto = iph->protocol; ctx->tun.hdr_size = size; ctx->offset += ctx->tun.hdr_size;
@@ -351,7 +351,7 @@ static bool nf_flow_ip6_tunnel_proto(struct nf_flowtable_ctx *ctx,if (ipv6_ext_hdr (ip6h->nexthdr))return false; -if (ip6h->nexthdr ==IPPROTO_IPV6 ) { +if (ip6h->nexthdr ==IPPROTO_IPIP || ip6h->nexthdr ==IPPROTO_IPV6 ) { ctx->tun.inner_proto = ip6h->nexthdr; ctx->tun.hdr_size =sizeof (*ip6h); ctx->offset += ctx->tun.hdr_size;
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 3/15 netfilter: flowtable: set inner protocol when popping tunnel header
In reply to Pablo Neira AyusoFrom: Lorenzo Bianconi <[email protected]>
Pop the outer tunnel header and set skb->protocol to the inner protocol derived from ctx->tun.inner_proto in nf_flow_ip_tunnel_pop(), instead of bailing out unless the tunnel carries IP-in-IP or IPv6-in-IPv6. This is a preliminary patch to support IPv4 over IPv6 and SIT tunnel flowtable offload.
--- net/netfilter/nf_flow_table_ip.c | 5 +++++ 1 file changed, 5 insertions(+)
net/netfilter/nf_flow_table_ip.c +5 -0
@@ -372,6 +372,11 @@ static void nf_flow_ip_tunnel_pop(struct nf_flowtable_ctx *ctx,skb_pull (skb, ctx->tun.hdr_size);skb_reset_network_header (skb); + +if (ctx->tun.inner_proto ==IPPROTO_IPIP ) + skb->protocol =htons (ETH_P_IP ); +else + skb->protocol =htons (ETH_P_IPV6 ); } static bool nf_flow_skb_encap_protocol(struct nf_flowtable_ctx *ctx,
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 4/15 netfilter: flowtable: populate tunnel tuple regardless of inner protocol
In reply to Pablo Neira AyusoFrom: Lorenzo Bianconi <[email protected]>
Store the outer tunnel addresses and inner protocol in the flow tuple unconditionally in nf_flow_tuple_encap(), instead of only when the tunnel is IP-in-IP or IPv6-in-IPv6. Bail out early when the inner protocol is neither IPPROTO_IPIP nor IPPROTO_IPV6.
This makes the tuple usable for cross-family tunnels such as IPv4-over-IPv6 and SIT, where the inner protocol differs from the outer address family.
This is a preliminary patch to support IPv4 over IPv6 and SIT tunnel flowtable offload.
Please note IPv4 over IPv6 and SIT tunnel flowtable offloading is not enabled yet.
--- net/netfilter/nf_flow_table_ip.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
net/netfilter/nf_flow_table_ip.c +10 -10
@@ -189,22 +189,22 @@ static void nf_flow_tuple_encap(struct nf_flowtable_ctx *ctx,break ; } +if (ctx->tun.inner_proto !=IPPROTO_IPIP && + ctx->tun.inner_proto !=IPPROTO_IPV6 ) +return ; +switch (ctx->ether_type) {case htons (ETH_P_IP ): iph = (struct iphdr *)(skb_network_header (skb) + offset); -if (ctx->tun.inner_proto ==IPPROTO_IPIP ) { - tuple->tun.dst_v4.s_addr = iph->daddr; - tuple->tun.src_v4.s_addr = iph->saddr; - tuple->tun.inner_proto =IPPROTO_IPIP ; - } + tuple->tun.dst_v4.s_addr = iph->daddr; + tuple->tun.src_v4.s_addr = iph->saddr; + tuple->tun.inner_proto = ctx->tun.inner_proto;break ;case htons (ETH_P_IPV6 ): ip6h = (struct ipv6hdr *)(skb_network_header (skb) + offset); -if (ctx->tun.inner_proto ==IPPROTO_IPV6 ) { - tuple->tun.dst_v6 = ip6h->daddr; - tuple->tun.src_v6 = ip6h->saddr; - tuple->tun.inner_proto =IPPROTO_IPV6 ; - } + tuple->tun.dst_v6 = ip6h->daddr; + tuple->tun.src_v6 = ip6h->saddr; + tuple->tun.inner_proto = ctx->tun.inner_proto;break ;default :break ;
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 5/15 netfilter: flowtable: add encap_proto to flow_offload_tunnel
In reply to Pablo Neira AyusoFrom: Lorenzo Bianconi <[email protected]>
Add encap_proto (AF_INET or AF_INET6) to struct flow_offload_tunnel to allow its use as part of the hash table key during flowtable entry lookup.
This is a preliminary change to support IPv4 over IPv6 tunneling via the flowtable infrastructure for software acceleration.
--- include/linux/netdevice.h | 1 + include/net/netfilter/nf_flow_table.h | 1 + net/ipv4/ipip.c | 1 + net/ipv6/ip6_tunnel.c | 1 + net/netfilter/nf_flow_table_ip.c | 2 ++ net/netfilter/nf_flow_table_path.c | 2 ++ 6 files changed, 8 insertions(+)
include/linux/netdevice.h +1 -0
@@ -911,6 +911,7 @@ struct net_device_path { };u8 inner_proto; +u8 encap_proto; } tun; struct { enum {
include/net/netfilter/nf_flow_table.h +1 -0
@@ -118,6 +118,7 @@ struct flow_offload_tunnel { };u8 inner_proto; +u8 encap_proto; };struct flow_offload_tuple {
net/ipv4/ipip.c +1 -0
@@ -379,6 +379,7 @@ static int ipip_fill_forward_path(struct net_device_path_ctx *ctx, path->tun.src_v4.s_addr = tiph->saddr; path->tun.dst_v4.s_addr = tiph->daddr; path->tun.inner_proto =IPPROTO_IPIP ; + path->tun.encap_proto =AF_INET ; path->tun.dst = &rt->dst; path->dev = ctx->dev;
net/ipv6/ip6_tunnel.c +1 -0
@@ -1868,6 +1868,7 @@ static int ip6_tnl_fill_forward_path(struct net_device_path_ctx *ctx, path->tun.src_v6 = fl6.saddr; path->tun.dst_v6 = fl6.daddr; path->tun.inner_proto =IPPROTO_IPV6 ; + path->tun.encap_proto =AF_INET6 ; path->tun.dst = dst; path->dev = ctx->dev; ctx->dev = dst->dev;
net/netfilter/nf_flow_table_ip.c +2 -0
@@ -199,12 +199,14 @@ static void nf_flow_tuple_encap(struct nf_flowtable_ctx *ctx, tuple->tun.dst_v4.s_addr = iph->daddr; tuple->tun.src_v4.s_addr = iph->saddr; tuple->tun.inner_proto = ctx->tun.inner_proto; + tuple->tun.encap_proto =AF_INET ;break ;case htons (ETH_P_IPV6 ): ip6h = (struct ipv6hdr *)(skb_network_header (skb) + offset); tuple->tun.dst_v6 = ip6h->daddr; tuple->tun.src_v6 = ip6h->saddr; tuple->tun.inner_proto = ctx->tun.inner_proto; + tuple->tun.encap_proto =AF_INET6 ;break ;default :break ;
net/netfilter/nf_flow_table_path.c +2 -0
@@ -138,6 +138,7 @@ static int nft_dev_path_info(struct net_device_path_stack *stack, info->tun.dst_v6 = path->tun.dst_v6; info->tun.inner_proto = path->tun.inner_proto; info->tun_dst = path->tun.dst; + info->tun.encap_proto = path->tun.encap_proto; info->num_tuns++; }else {if (info->num_encaps >=NF_FLOW_TABLE_ENCAP_MAX )
@@ -249,6 +250,7 @@ static int nft_dev_forward_path(const struct nft_pktinfo *pkt, route->tuple[!dir].in.tun.src_v6 = info.tun.dst_v6; route->tuple[!dir].in.tun.dst_v6 = info.tun.src_v6; route->tuple[!dir].in.tun.inner_proto = info.tun.inner_proto; + route->tuple[!dir].in.tun.encap_proto = info.tun.encap_proto; route->tuple[!dir].in.num_tuns = info.num_tuns;dst_release (route->tuple[dir].dst); route->tuple[dir].dst = info.tun_dst;
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 6/15 netfilter: flowtable: refactor MTU check for tunnel offload
In reply to Pablo Neira AyusoFrom: Lorenzo Bianconi <[email protected]>
Introduce nf_flow_offload_check_mtu() helper and use the encapsulated protocol (tun.encap_proto) to compute the tunnel overhead instead of relying on tun_num, so the correct inner header size (IPv4 vs IPv6) is accounted for. Use it in both the IPv4 and IPv6 forward paths. This is a preliminary patch to support IPv4 over IPv6 and SIT flowtable tunnel offload.
Please note IPv4 over IPv6 and SIT tunnel flowtable offloading is not enabled yet.
--- net/netfilter/nf_flow_table_ip.c | 41 ++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 12 deletions(-)
net/netfilter/nf_flow_table_ip.c +29 -12
@@ -472,6 +472,31 @@ nf_flow_offload_lookup(struct nf_flowtable_ctx *ctx,return flow_offload_lookup (flow_table, &tuple); } +static int nf_flow_offload_check_mtu (struct nf_flowtable_ctx *ctx, +struct flow_offload *flow, +enum flow_offload_tuple_dir dir, +struct sk_buff *skb) +{ +unsigned int mtu; + + mtu = flow->tuplehash[dir].tuple.mtu + ctx->offset; +switch (flow->tuplehash[!dir].tuple.tun.encap_proto) { +case AF_INET : + mtu -=sizeof (struct iphdr ); +break ; +case AF_INET6 : + mtu -=sizeof (struct ipv6hdr ); +break ; +default : +break ; + } + +if (unlikely (nf_flow_exceeds_mtu (skb, mtu))) +return -EINVAL ; + +return 0 ; +} + static int nf_flow_offload_forward(struct nf_flowtable_ctx *ctx, struct nf_flowtable *flow_table, struct flow_offload_tuple_rhash *tuplehash,
@@ -479,17 +504,13 @@ static int nf_flow_offload_forward(struct nf_flowtable_ctx *ctx, {enum flow_offload_tuple_dir dir;struct flow_offload *flow; -unsigned int thoff, mtu; +unsigned int thoff;struct iphdr *iph; dir = tuplehash->tuple.dir; flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]); - mtu = flow->tuplehash[dir].tuple.mtu + ctx->offset; -if (flow->tuplehash[!dir].tuple.tun_num) - mtu -=sizeof (*iph); - -if (unlikely (nf_flow_exceeds_mtu (skb, mtu))) +if (nf_flow_offload_check_mtu (ctx, flow, dir, skb))return 0 ; iph = (struct iphdr *)(skb_network_header (skb) + ctx->offset);
@@ -1075,17 +1096,13 @@ static int nf_flow_offload_ipv6_forward(struct nf_flowtable_ctx *ctx, {enum flow_offload_tuple_dir dir;struct flow_offload *flow; -unsigned int thoff, mtu;struct ipv6hdr *ip6h; +unsigned int thoff; dir = tuplehash->tuple.dir; flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]); - mtu = flow->tuplehash[dir].tuple.mtu + ctx->offset; -if (flow->tuplehash[!dir].tuple.tun_num) - mtu -=sizeof (*ip6h); - -if (unlikely (nf_flow_exceeds_mtu (skb, mtu))) +if (nf_flow_offload_check_mtu (ctx, flow, dir, skb))return 0 ; ip6h = (struct ipv6hdr *)(skb_network_header (skb) + ctx->offset);
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 7/15 netfilter: flowtable: unify tunnel push for IPv4 and IPv6
In reply to Pablo Neira AyusoFrom: Lorenzo Bianconi <[email protected]>
Refactor nf_flow_tunnel_ipip_push() and nf_flow_tunnel_ip6ip6_push() into nf_flow_tunnel_ip_push() and nf_flow_tunnel_ip6_push(), keying the inner header handling off tuple->tun.inner_proto so both IP-in-IP and IPv6-in-IPv6 inner protocols are supported regardless of the outer address family. Replace nf_flow_tunnel_v4_push() and nf_flow_tunnel_v6_push() with a single nf_flow_tunnel_push() that dispatches on tuple->tun.encap_proto, and set skb->protocol explicitly after pushing the outer header.
This is a preliminary patch to support IPv4 over IPv6 and SIT tunnel flowtable offload.
Please note IPv4 over IPv6 and SIT tunnel flowtable offloading is not enabled yet.
--- net/netfilter/nf_flow_table_ip.c | 143 +++++++++++++++++++------------ 1 file changed, 87 insertions(+), 56 deletions(-)
net/netfilter/nf_flow_table_ip.c +87 -56
@@ -608,23 +608,44 @@ static int nf_flow_pppoe_push(struct sk_buff *skb, u16 id,return 0 ; } -static int nf_flow_tunnel_ipip_push (struct net *net,struct sk_buff *skb, -struct flow_offload_tuple *tuple, -struct dst_entry *dst,__be32 *ip_daddr) +static int nf_flow_tunnel_ip_push (struct net *net,struct sk_buff *skb, +struct flow_offload_tuple *tuple, +struct dst_entry *dst, +union nf_inet_addr **ip_addr) { -struct iphdr *iph = (struct iphdr *)skb_network_header (skb); -struct rtable *rt =dst_rtable (dst); -u8 tos = iph->tos, ttl = iph->ttl; -__be16 frag_off = iph->frag_off; -u32 headroom =sizeof (*iph); +__be16 frag_off =0 ; +struct iphdr *iph; +u8 tos =0 , ttl; +u32 headroom;int err; +switch (tuple->tun.inner_proto) { +case IPPROTO_IPV6 : { +struct ipv6hdr *ip6h; + + ip6h = (struct ipv6hdr *)skb_network_header (skb); + tos =ipv6_get_dsfield (ip6h); + ttl = ip6h->hop_limit; + frag_off =htons (IP_DF ); +break ; + } +case IPPROTO_IPIP : + iph = (struct iphdr *)skb_network_header (skb); + frag_off = iph->frag_off; + tos = iph->tos; + ttl = iph->ttl; +break ; +default : +return 0 ; + } + err =iptunnel_handle_offloads (skb,SKB_GSO_IPXIP4 );if (err)return err; -skb_set_inner_ipproto (skb,IPPROTO_IPIP ); - headroom +=LL_RESERVED_SPACE (rt->dst.dev) + rt->dst.header_len; +skb_set_inner_ipproto (skb, tuple->tun.inner_proto); + headroom =sizeof (*iph) +LL_RESERVED_SPACE (dst->dev) + + dst->header_len; err =skb_cow_head (skb, headroom);if (err)return err;
@@ -635,11 +656,12 @@ static int nf_flow_tunnel_ipip_push(struct net *net, struct sk_buff *skb,/* Push down and install the IP header. */ skb_push (skb,sizeof (*iph));skb_reset_network_header (skb); + skb->protocol =htons (ETH_P_IP ); iph =ip_hdr (skb); iph->version =4 ; iph->ihl =sizeof (*iph) >>2 ; - iph->frag_off =ip_mtu_locked (&rt->dst) ?0 : frag_off; + iph->frag_off =ip_mtu_locked (dst) ?0 : frag_off; iph->protocol = tuple->tun.inner_proto; iph->tos = tos; iph->daddr = tuple->tun.src_v4.s_addr;
@@ -649,81 +671,91 @@ static int nf_flow_tunnel_ipip_push(struct net *net, struct sk_buff *skb,__ip_select_ident (net, iph,skb_shinfo (skb)->gso_segs ?:1 );ip_send_check (iph); - *ip_daddr = tuple->tun.src_v4.s_addr; - -return 0 ; -} - -static int nf_flow_tunnel_v4_push (struct net *net,struct sk_buff *skb, -struct flow_offload_tuple *tuple, -struct dst_entry *dst,__be32 *ip_daddr) -{ -if (tuple->tun_num) -return nf_flow_tunnel_ipip_push (net, skb, tuple, dst, ip_daddr); + *ip_addr = (union nf_inet_addr *)&tuple->tun.src_v4;return 0 ; } -static int nf_flow_tunnel_ip6ip6_push (struct net *net,struct sk_buff *skb, -struct flow_offload_tuple *tuple, -struct dst_entry *dst, -struct in6_addr **ip6_daddr) +static int nf_flow_tunnel_ip6_push (struct net *net,struct sk_buff *skb, +struct flow_offload_tuple *tuple, +struct dst_entry *dst, +union nf_inet_addr **ip_addr) { -struct ipv6hdr *ip6h = (struct ipv6hdr *)skb_network_header (skb); -__u8 dsfield =ipv6_get_dsfield (ip6h); -struct rtable *rt =dst_rtable (dst);struct flowi6 fl6 = { .daddr = tuple->tun.src_v6, .saddr = tuple->tun.dst_v6, - .flowi6_proto =IPPROTO_IPV6 , + .flowi6_proto = tuple->tun.inner_proto, }; -u8 hop_limit = ip6h->hop_limit; +u8 hop_limit, dsfield; +struct ipv6hdr *ip6h;int err, mtu;u32 headroom; +switch (tuple->tun.inner_proto) { +case IPPROTO_IPIP : { +struct iphdr *iph = (struct iphdr *)skb_network_header (skb); + + dsfield =ipv4_get_dsfield (iph); + hop_limit = iph->ttl; +break ; + } +case IPPROTO_IPV6 : + ip6h = (struct ipv6hdr *)skb_network_header (skb); + dsfield =ipv6_get_dsfield (ip6h); + hop_limit = ip6h->hop_limit; +break ; +default : +return 0 ; + } + err =iptunnel_handle_offloads (skb,SKB_GSO_IPXIP6 );if (err)return err; -skb_set_inner_ipproto (skb,IPPROTO_IPV6 ); - headroom =sizeof (*ip6h) +LL_RESERVED_SPACE (rt->dst.dev) + - rt->dst.header_len; +skb_set_inner_ipproto (skb, tuple->tun.inner_proto); + headroom =sizeof (*ip6h) +LL_RESERVED_SPACE (dst->dev) + + dst->header_len; err =skb_cow_head (skb, headroom);if (err)return err;skb_scrub_packet (skb, true); - mtu =dst_mtu (&rt->dst) -sizeof (*ip6h); + mtu =dst_mtu (dst) -sizeof (*ip6h); mtu =max (mtu,IPV6_MIN_MTU );skb_dst_update_pmtu_no_confirm (skb, mtu);skb_push (skb,sizeof (*ip6h));skb_reset_network_header (skb); + skb->protocol =htons (ETH_P_IPV6 ); ip6h =ipv6_hdr (skb);ip6_flow_hdr (ip6h, dsfield,ip6_make_flowlabel (net, skb, fl6.flowlabel, true, &fl6)); ip6h->hop_limit = hop_limit; - ip6h->nexthdr =IPPROTO_IPV6 ; + ip6h->nexthdr = tuple->tun.inner_proto; ip6h->daddr = tuple->tun.src_v6; ip6h->saddr = tuple->tun.dst_v6;ipv6_hdr (skb)->payload_len =htons (skb->len -sizeof (*ip6h));IP6CB (skb)->nhoff = offsetof(struct ipv6hdr , nexthdr); - *ip6_daddr = &tuple->tun.src_v6; + *ip_addr = (union nf_inet_addr *)&tuple->tun.src_v6;return 0 ; } -static int nf_flow_tunnel_v6_push (struct net *net,struct sk_buff *skb, -struct flow_offload_tuple *tuple, -struct dst_entry *dst, -struct in6_addr **ip6_daddr) +static int nf_flow_tunnel_push (struct net *net,struct sk_buff *skb, +struct flow_offload_tuple *tuple, +struct dst_entry *dst, +union nf_inet_addr **ip_addr) { -if (tuple->tun_num) -return nf_flow_tunnel_ip6ip6_push (net, skb, tuple, dst, ip6_daddr); - -return 0 ; +switch (tuple->tun.encap_proto) { +case AF_INET : +return nf_flow_tunnel_ip_push (net, skb, tuple, dst, ip_addr); +case AF_INET6 : +return nf_flow_tunnel_ip6_push (net, skb, tuple, dst, ip_addr); +default : +return 0 ; + } } static int nf_flow_encap_push(struct sk_buff *skb,
@@ -830,10 +862,10 @@ static int nf_flow_queue_xmit4(struct sk_buff *skb,struct flow_offload_tuple *other_tuple;enum flow_offload_tuple_dir dir;struct nf_flow_xmit xmit = {}; +union nf_inet_addr *ip_addr;struct flow_offload *flow;struct neighbour *neigh;struct rtable *rt; -__be32 ip_daddr;if (unlikely (tuplehash->tuple.xmit_type ==FLOW_OFFLOAD_XMIT_XFRM )) { rt =dst_rtable (tuplehash->tuple.dst_cache);
@@ -846,10 +878,10 @@ static int nf_flow_queue_xmit4(struct sk_buff *skb, dir = tuplehash->tuple.dir; flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]); other_tuple = &flow->tuplehash[!dir].tuple; - ip_daddr = other_tuple->src_v4.s_addr; + ip_addr = (union nf_inet_addr *)&other_tuple->src_v4; -if (nf_flow_tunnel_v4_push (state->net, skb, other_tuple, - tuplehash->tuple.dst_cache, &ip_daddr) <0 ) +if (nf_flow_tunnel_push (state->net, skb, other_tuple, + tuplehash->tuple.dst_cache, &ip_addr) <0 )return NF_DROP ;switch (tuplehash->tuple.xmit_type) {
@@ -860,7 +892,7 @@ static int nf_flow_queue_xmit4(struct sk_buff *skb,flow_offload_teardown (flow);return NF_DROP ; } - neigh =ip_neigh_gw4 (rt->dst.dev,rt_nexthop (rt, ip_daddr)); + neigh =ip_neigh_gw4 (rt->dst.dev,rt_nexthop (rt, ip_addr->ip));if (IS_ERR (neigh)) {flow_offload_teardown (flow);return NF_DROP ;
@@ -1154,7 +1186,7 @@ static int nf_flow_queue_xmit6(struct sk_buff *skb,struct flow_offload_tuple *other_tuple;enum flow_offload_tuple_dir dir;struct nf_flow_xmit xmit = {}; -struct in6_addr *ip6_daddr; +union nf_inet_addr *ip_addr;struct flow_offload *flow;struct neighbour *neigh;struct rt6_info *rt;
@@ -1170,11 +1202,10 @@ static int nf_flow_queue_xmit6(struct sk_buff *skb, dir = tuplehash->tuple.dir; flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]); other_tuple = &flow->tuplehash[!dir].tuple; - ip6_daddr = &other_tuple->src_v6; + ip_addr = (union nf_inet_addr *)&other_tuple->src_v6; -if (nf_flow_tunnel_v6_push (state->net, skb, other_tuple, - tuplehash->tuple.dst_cache, - &ip6_daddr) <0 ) +if (nf_flow_tunnel_push (state->net, skb, other_tuple, + tuplehash->tuple.dst_cache, &ip_addr) <0 )return NF_DROP ;switch (tuplehash->tuple.xmit_type) {
@@ -1185,7 +1216,7 @@ static int nf_flow_queue_xmit6(struct sk_buff *skb,flow_offload_teardown (flow);return NF_DROP ; } - neigh =ip_neigh_gw6 (rt->dst.dev,rt6_nexthop (rt, ip6_daddr)); + neigh =ip_neigh_gw6 (rt->dst.dev,rt6_nexthop (rt, &ip_addr->in6));if (IS_ERR (neigh)) {flow_offload_teardown (flow);return NF_DROP ;
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 8/15 selftests: netfilter: nft_queue.sh: only queue icmp echo request/reply
In reply to Pablo Neira AyusoFrom: Jakub Kicinski <[email protected]>
The bridge test flakes on debug kernels:
FAIL: Expected 10 packets total, but got 24 packets total hook 3 packets 00000008
hook 4 packets 00000010
The surplus are icmp fragment reassembly timeouts. The udp flood in the stress test leaves incomplete datagrams behind in ns2 and ns3, 30 seconds later their reassembly queues expire and both namespaces send icmp time exceeded to ns1's pre-bridge address. ns3 is not reconfigured when the router is turned into a bridge, so its messages arrive via veth2 and are then forwarded out of br0. Such packets are locally originated from the bridge point of view and are queued from the bridge output and postrouting hooks, which is why only those two counters are off.
Restrict the ipv4 rule to echo request/reply, the icmpv6 rule already does this.
We used to see 1 flake a day in NIPA before locally queuing this change, zero flakes since (over 9 days)
--- tools/testing/selftests/net/netfilter/nft_queue.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/net/netfilter/nft_queue.sh +1 -1
@@ -92,7 +92,7 @@ load_ruleset() { ip netns exec "$nsrouter" nft -f /dev/stdin <<EOF table $family $name { chain nfq { - ip protocol icmp queue bypass + icmp type { "echo-request", "echo-reply" } queue bypass icmpv6 type { "echo-request", "echo-reply" } queue num 1 bypass } chain pre {
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 9/15 ipvs: fix buffer overflow when sending sync messages
In reply to Pablo Neira AyusoFrom: Julian Anastasov <[email protected]>
Sashiko reports for possible heap buffer overflow when generating sync message for the v0 and v1 message formats. We should read the cp->flags only once because another CPU can concurrently set the SEQ_MASK between the two reads.
Note that IPVS does not set the SEQ_MASK anymore for the ip_vs_ftp.c helper starting from commit 7f1c40757951 ("IPVS: make FTP work with full NAT support") (2.6.36+), so the problem should not be reproducible.
--- net/netfilter/ipvs/ip_vs_sync.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
net/netfilter/ipvs/ip_vs_sync.c +14 -9
@@ -543,13 +543,15 @@ static void ip_vs_sync_conn_v0(struct netns_ipvs *ipvs, struct ip_vs_conn *cp,struct ip_vs_sync_conn_v0 *s;struct ip_vs_sync_buff *buff;struct ipvs_master_sync_state *ms; -int id; +u32 flags, seq_mask;unsigned int len; +int id;if (unlikely (cp->af !=AF_INET ))return ; + flags =READ_ONCE (cp->flags);/* Do not sync ONE PACKET */ -if (cp->flags &IP_VS_CONN_F_ONE_PACKET ) +if (flags &IP_VS_CONN_F_ONE_PACKET )return ;if (!ip_vs_sync_conn_needed (ipvs, cp, pkts))
@@ -564,8 +566,8 @@ static void ip_vs_sync_conn_v0(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, id =select_master_thread_id (ipvs, cp); ms = &ipvs->ms[id]; buff = ms->sync_buff; - len = (cp->flags &IP_VS_CONN_F_SEQ_MASK ) ?FULL_CONN_SIZE : -SIMPLE_CONN_SIZE ; + seq_mask = flags &IP_VS_CONN_F_SEQ_MASK ; + len = seq_mask ?FULL_CONN_SIZE :SIMPLE_CONN_SIZE ;if (buff) { m = (struct ip_vs_sync_mesg_v0 *) buff->mesg;/* Send buffer if it is for v1 */
@@ -597,9 +599,9 @@ static void ip_vs_sync_conn_v0(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, s->caddr = cp->caddr.ip; s->vaddr = cp->vaddr.ip; s->daddr = cp->daddr.ip; - s->flags =htons (cp->flags & ~IP_VS_CONN_F_HASHED ); + s->flags =htons (flags & ~IP_VS_CONN_F_HASHED ); s->state =htons (cp->state); -if (cp->flags &IP_VS_CONN_F_SEQ_MASK ) { +if (seq_mask) {struct ip_vs_sync_conn_options *opt = (struct ip_vs_sync_conn_options *)&s[1 ];memcpy (opt, &cp->sync_conn_opt,sizeof (*opt));
@@ -635,6 +637,7 @@ void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts)int id;__u8 *p;unsigned int len, pe_name_len, pad; +u32 flags, seq_mask;/* Handle old version of the protocol */ if (sysctl_sync_ver (ipvs) ==0 ) {
@@ -647,6 +650,7 @@ void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts) sloop:if (!ip_vs_sync_conn_needed (ipvs, cp, pkts)) goto control; + flags =READ_ONCE (cp->flags);/* Sanity checks */ pe_name_len =0 ;
@@ -674,7 +678,8 @@ void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts)#endif len =sizeof (struct ip_vs_sync_v4 ); -if (cp->flags &IP_VS_CONN_F_SEQ_MASK ) + seq_mask = flags &IP_VS_CONN_F_SEQ_MASK ; +if (seq_mask) len +=sizeof (struct ip_vs_sync_conn_options ) +2 ;if (cp->pe_data_len)
@@ -720,7 +725,7 @@ void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts)/* Set message type & copy members */ s->v4.type = (cp->af ==AF_INET6 ?STYPE_F_INET6 :0 ); s->v4.ver_size =htons (len &SVER_MASK );/* Version 0 */ - s->v4.flags =htonl (cp->flags & ~IP_VS_CONN_F_HASHED ); + s->v4.flags =htonl (flags & ~IP_VS_CONN_F_HASHED ); s->v4.state =htons (cp->state); s->v4.protocol = cp->protocol; s->v4.cport = cp->cport;
@@ -744,7 +749,7 @@ void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts) s->v4.vaddr = cp->vaddr.ip; s->v4.daddr = cp->daddr.ip; } -if (cp->flags &IP_VS_CONN_F_SEQ_MASK ) { +if (seq_mask) { *(p++) =IPVS_OPT_SEQ_DATA ; *(p++) =sizeof (struct ip_vs_sync_conn_options );hton_seq (&cp->in_seq, (struct ip_vs_seq *)p);
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 10/15 netfilter: conntrack: fix unlikely UaF in gc worker
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
When early-drop scan is enabled, gc_worker() reads tmp->ct_net, resolves cnet with nf_ct_pernet(), and reads cnet->count with RCU read lock held but before acquiring a reference to tmp.
Its unlikely but possible that the worker gets preempted before reading cnet->count while nf_conntrack_cleanup_net_list manages to unlink all conntracks and returns in the mean time.
This allows for the pernet memory to get free'd.
On resume, use after free would occur when the worker reads cnet->count.
This can be solved either via another synchronize_rcu() in nf_conntrack_cleanup_net_list or via cheaper flush_work(). If work wasn't running no race can happen as next call cannot observe already-unlinked conntrack objects.
This is an LLM finding with no reproducer, but it appears to be correct.
--- net/netfilter/nf_conntrack_core.c | 5 +++++ 1 file changed, 5 insertions(+)
net/netfilter/nf_conntrack_core.c +5 -0
@@ -2506,6 +2506,11 @@ void nf_conntrack_cleanup_net_list(struct list_head *net_exit_list) goto i_see_dead_people; } +/* must wait for current scan loop, worker also looks at +* struct nf_conntrack_net, which is about to be free'd. +*/ +flush_work (&conntrack_gc_work.dwork.work); +list_for_each_entry (net, net_exit_list, exit_list) {warn_on_keymap_list_leak (net);nf_conntrack_ecache_pernet_fini (net);
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 11/15 netfilter: nf_tables: switch chain_types array to rcu
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
LLM quote:
The global chain_type array is cleared under the nfnetlink subsystem mutex, but transaction processing reads it while holding only the pernet transaction mutex.
nf_tables_chain_type_lookup() and nft_chain_parse_hook() dereference type->name/hook_mask before try_module_get(type->owner).
Concurrent unloading of a separate provider such as nft_chain_nat can unregister and free its static nft_chain_type while a transaction is in the unprotected interval, causing a module-memory use-after-free.
LLM finding, not observed in practice. Move this under RCU and grab the module owner earlier.
Both nft_chain_route and nft_chain_filter are built into nf_tables.ko:
only nft_chain_nat needs an extra synchronize_rcu().
--- net/netfilter/nf_tables_api.c | 94 ++++++++++++++++++++++++----------- net/netfilter/nft_chain_nat.c | 1 + 2 files changed, 65 insertions(+), 30 deletions(-)
net/netfilter/nf_tables_api.c +64 -30
@@ -1036,32 +1036,67 @@ static inline u64 nf_tables_alloc_handle(struct nft_table *table)return ++table->hgenerator; } -static const struct nft_chain_type *chain_type[NFPROTO_NUMPROTO ][NFT_CHAIN_T_MAX ]; +static const struct nft_chain_type __rcu *chain_type[NFPROTO_NUMPROTO ][NFT_CHAIN_T_MAX ];static const struct nft_chain_type * -__nft_chain_type_get (u8 family,enum nft_chain_types type) +__nft_chain_type_peek (u8 family,enum nft_chain_types type) {if (family >=NFPROTO_NUMPROTO || type >=NFT_CHAIN_T_MAX )return NULL ; -return chain_type[family][type]; +return rcu_dereference_check (chain_type[family][type], +lockdep_nfnl_is_held (NFNL_SUBSYS_NFTABLES )); } +/** +* nft_chain_type_get - look up a chain type by family and id +* @family: netlink family +* @type: chain type (enum nft_chain_types) +* +* Return: chain type with a held module ref, or NULL. +*/ +static const struct nft_chain_type * +nft_chain_type_get (u8 family,enum nft_chain_types type) +{ +const struct nft_chain_type *t; + +rcu_read_lock (); + t =__nft_chain_type_peek (family, type); + +if (t && !try_module_get (t->owner)) + t =NULL ; + +rcu_read_unlock (); +return t; +} + +/** +* __nf_tables_chain_type_lookup - look up a chain type by name +* @nla: nlattr containing the chain-type name +* @family: netlink family +* +* Return: matching chain type with a held module ref, or NULL. +*/ static const struct nft_chain_type *__nf_tables_chain_type_lookup (const struct nlattr *nla,u8 family) { -const struct nft_chain_type *type; +const struct nft_chain_type *type =NULL , *t;int i; +rcu_read_lock ();for (i =0 ; i <NFT_CHAIN_T_MAX ; i++) { - type =__nft_chain_type_get (family, i); -if (!type) + t =__nft_chain_type_peek (family, i); +if (!t)continue ; -if (!nla_strcmp (nla, type->name)) -return type; + +if (!nla_strcmp (nla, t->name) &&try_module_get (t->owner)) { + type = t; +break ; + } } -return NULL ; +rcu_read_unlock (); +return type; }struct nft_module_request {
@@ -1837,11 +1872,11 @@ static void nf_tables_table_destroy(struct nft_table *table)void nft_register_chain_type (const struct nft_chain_type *ctype) {nfnl_lock (NFNL_SUBSYS_NFTABLES ); -if (WARN_ON (__nft_chain_type_get (ctype->family, ctype->type))) { +if (WARN_ON (__nft_chain_type_peek (ctype->family, ctype->type))) {nfnl_unlock (NFNL_SUBSYS_NFTABLES );return ; } - chain_type[ctype->family][ctype->type] = ctype; +rcu_assign_pointer (chain_type[ctype->family][ctype->type], ctype);nfnl_unlock (NFNL_SUBSYS_NFTABLES ); }EXPORT_SYMBOL_GPL (nft_register_chain_type);
@@ -1849,7 +1884,7 @@ EXPORT_SYMBOL_GPL(nft_register_chain_type);void nft_unregister_chain_type (const struct nft_chain_type *ctype) {nfnl_lock (NFNL_SUBSYS_NFTABLES ); - chain_type[ctype->family][ctype->type] =NULL ; +RCU_INIT_POINTER (chain_type[ctype->family][ctype->type],NULL );nfnl_unlock (NFNL_SUBSYS_NFTABLES ); }EXPORT_SYMBOL_GPL (nft_unregister_chain_type);
@@ -2581,10 +2616,6 @@ static int nft_chain_parse_hook(struct net *net, hook->num =ntohl (nla_get_be32 (ha[NFTA_HOOK_HOOKNUM ])); hook->priority =ntohl (nla_get_be32 (ha[NFTA_HOOK_PRIORITY ])); - type =__nft_chain_type_get (family,NFT_CHAIN_T_DEFAULT ); -if (!type) -return -EOPNOTSUPP ; -if (nla[NFTA_CHAIN_TYPE ]) { type =nf_tables_chain_type_lookup (net, nla[NFTA_CHAIN_TYPE ], family, true);
@@ -2592,13 +2623,19 @@ static int nft_chain_parse_hook(struct net *net,NL_SET_BAD_ATTR (extack, nla[NFTA_CHAIN_TYPE ]);return PTR_ERR (type); } + }else { + type =nft_chain_type_get (family,NFT_CHAIN_T_DEFAULT ); +if (!type) +return -EOPNOTSUPP ; } + + err = -EOPNOTSUPP ;if (hook->num >=NFT_MAX_HOOKS || !(type->hook_mask & (1 << hook->num))) -return -EOPNOTSUPP ; + goto out_put_type;if (type->type ==NFT_CHAIN_T_NAT && hook->priority <=NF_IP_PRI_CONNTRACK ) -return -EOPNOTSUPP ; + goto out_put_type; }else {if (ha[NFTA_HOOK_HOOKNUM ]) { hook->num =ntohl (nla_get_be32 (ha[NFTA_HOOK_HOOKNUM ]));
@@ -2620,30 +2657,27 @@ static int nft_chain_parse_hook(struct net *net, } }else { type = basechain->type; +__module_get (type->owner); } } -if (!try_module_get (type->owner)) { -if (nla[NFTA_CHAIN_TYPE ]) -NL_SET_BAD_ATTR (extack, nla[NFTA_CHAIN_TYPE ]); -return -ENOENT ; - } - hook->type = type;INIT_LIST_HEAD (&hook->list);if (nft_base_chain_netdev (family, hook->num)) { err =nft_chain_parse_netdev (net, ha, &hook->list, extack, flags); -if (err <0 ) { -module_put (type->owner); -return err; - } +if (err <0 ) + goto out_put_type; }else if (ha[NFTA_HOOK_DEV ] || ha[NFTA_HOOK_DEVS ]) { -module_put (type->owner); -return -EOPNOTSUPP ; + err = -EOPNOTSUPP ; + goto out_put_type; }return 0 ; + +out_put_type: +module_put (type->owner); +return err; }static void nft_chain_release_hook (struct nft_chain_hook *hook)
net/netfilter/nft_chain_nat.c +1 -0
@@ -131,6 +131,7 @@ static void __exit nft_chain_nat_exit(void)#ifdef CONFIG_NF_TABLES_INET nft_unregister_chain_type (&nft_chain_nat_inet);#endif +synchronize_rcu (); }module_init (nft_chain_nat_init);
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 12/15 netfilter: add nf_skb_sk helper and use it
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
nft and xt socket matching pass skb->sk to inet_sk_transparent(). On the LOCAL_OUT path an IP tunnel transmits while preserving the original skb owner, so a non-INET socket (e.g. PF_PACKET) can reach these code paths. This is reachable for nft_socket.c which does allow LOCAL_OUT. xt_socket only permits PREROUTING/LOCAL_IN.
nf_nat does this too, but there the inet_sk_transparent() call is explicitly restricted to the INPUT hook.
For a packet socket the INET-specific offset lands inside the packet statistics area.
Introduce nf_skb_sk() in nf_socket.h which returns skb->sk only when it belongs to the given net namespace and passes sk_is_inet().
While at it, replace the sk != skb->sk refcount test with an explicit refcounted flag that is set when the socket is obtained via the lookup helper (the path that takes a reference).
LLM finding, no reproducer, no out-of-bounds memory access.
--- include/net/netfilter/nf_socket.h | 20 ++++++++++++++++++++ net/netfilter/nft_socket.c | 16 +++++++++------- net/netfilter/xt_socket.c | 26 ++++++++++++++------------ 3 files changed, 43 insertions(+), 19 deletions(-)
include/net/netfilter/nf_socket.h +20 -0
@@ -10,4 +10,24 @@ struct sock *nf_sk_lookup_slow_v4(struct net *net, const struct sk_buff *skb,struct sock *nf_sk_lookup_slow_v6 (struct net *net,const struct sk_buff *skb,const struct net_device *indev); +/** +* nf_skb_sk - Return the inet socket associated with an skb +* @skb: The skb to fetch sk from. +* @net: The network namespace the socket must belong to. +* +* On the output path, skb->sk may be non-INET when the skb is passing +* through an IP tunnel. +* +* Return: +* *sk* if it is an INET socket that belongs to @net, %NULL otherwise. +*/ +static inline struct sock *nf_skb_sk (const struct sk_buff *skb,const struct net *net) +{ +struct sock *sk = skb->sk; + +if (sk &&net_eq (net,sock_net (sk)) &&sk_is_inet (sk)) +return sk; + +return NULL ; +}#endif
net/netfilter/nft_socket.c +9 -7
@@ -111,15 +111,17 @@ static void nft_socket_eval(const struct nft_expr *expr, const struct nft_pktinfo *pkt) {const struct nft_socket *priv =nft_expr_priv (expr); -struct sk_buff *skb = pkt->skb; -struct sock *sk = skb->sk;u32 *dest = ®s->data[priv->dreg]; +struct sk_buff *skb = pkt->skb; +bool refcounted = false; +struct sock *sk; -if (sk && !net_eq (nft_net (pkt),sock_net (sk))) - sk =NULL ; - -if (!sk) + sk =nf_skb_sk (skb,nft_net (pkt)); +if (!sk) { sk =nft_socket_do_lookup (pkt); +if (sk) + refcounted = true; + }if (!sk) { regs->verdict.code =NFT_BREAK ;
@@ -159,7 +161,7 @@ static void nft_socket_eval(const struct nft_expr *expr, } out_put_sk: -if (sk != skb->sk) +if (refcounted)sock_gen_put (sk); }
net/netfilter/xt_socket.c +14 -12
@@ -49,14 +49,15 @@ static bool socket_match(const struct sk_buff *skb, struct xt_action_param *par, const struct xt_socket_mtinfo1 *info) { + struct sock *sk = nf_skb_sk(skb, xt_net(par));struct sk_buff *pskb = (struct sk_buff *)skb; -struct sock *sk = skb->sk; +bool refcounted = false; -if (sk && !net_eq (xt_net (par),sock_net (sk))) - sk =NULL ; - -if (!sk) +if (!sk) { sk =nf_sk_lookup_slow_v4 (xt_net (par), skb,xt_in (par)); +if (sk) + refcounted = true; + }if (sk) {bool wildcard;
@@ -79,7 +80,7 @@ socket_match(const struct sk_buff *skb, struct xt_action_param *par, transparent && sk_fullsock(sk)) pskb->mark =READ_ONCE (sk->sk_mark); -if (sk != skb->sk) +if (refcounted)sock_gen_put (sk);if (wildcard || !transparent)
@@ -110,14 +111,15 @@ static bool socket_mt6_v1_v2_v3(const struct sk_buff *skb, struct xt_action_param *par) { const struct xt_socket_mtinfo1 *info = (struct xt_socket_mtinfo1 *) par->matchinfo; +struct sock *sk =nf_skb_sk (skb,xt_net (par));struct sk_buff *pskb = (struct sk_buff *)skb; -struct sock *sk = skb->sk; +bool refcounted = false; -if (sk && !net_eq (xt_net (par),sock_net (sk))) - sk =NULL ; - -if (!sk) +if (!sk) { sk =nf_sk_lookup_slow_v6 (xt_net (par), skb,xt_in (par)); +if (sk) + refcounted = true; + }if (sk) {bool wildcard;
@@ -140,7 +142,7 @@ socket_mt6_v1_v2_v3(const struct sk_buff *skb, struct xt_action_param *par) transparent && sk_fullsock(sk)) pskb->mark =READ_ONCE (sk->sk_mark); -if (sk != skb->sk) +if (refcounted)sock_gen_put (sk);if (wildcard || !transparent)
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 13/15 netfilter: add nf_sk_to_full_sk helper and use it
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Some callers of these helpers pass skb->sk as sk_partial argument, but for LOCAL_OUT path an IP tunnel transmits while preserving the original skb owner, so a non-INET socket (e.g. PF_PACKET) can reach these.
Like previous patch, add a helper to also check for this case. Related to LLM finding in the earlier patch when querying the agent about other possible scenarios.
--- include/net/netfilter/nf_socket.h | 15 +++++++++++++++ net/ipv4/netfilter.c | 3 ++- net/ipv6/netfilter.c | 3 ++- 3 files changed, 19 insertions(+), 2 deletions(-)
include/net/netfilter/nf_socket.h +15 -0
@@ -3,6 +3,7 @@#define _NF_SOCK_H_#include <net/sock.h> +#include <net/inet_sock.h> struct sock *nf_sk_lookup_slow_v4 (struct net *net,const struct sk_buff *skb,const struct net_device *indev);
@@ -30,4 +31,18 @@ static inline struct sock *nf_skb_sk(const struct sk_buff *skb, const struct net return NULL; } + +/** +* nf_sk_to_full_sk - Careful access to a full socket +* @sk: pointer to a socket +* +* %sk_to_full_sk for use when sk might not be an inet socket. +*/ +static inline struct sock *nf_sk_to_full_sk (struct sock *sk) +{ +if (sk &&sk_is_inet (sk)) +return sk_to_full_sk (sk); + +return NULL ; +}#endif
net/ipv4/netfilter.c +2 -1
@@ -17,6 +17,7 @@#include <net/xfrm.h> #include <net/ip.h> #include <net/netfilter/nf_queue.h> +#include <net/netfilter/nf_socket.h> /* route_me_harder function, used by iptable_nat, iptable_mangle + ip_queue */ int ip_route_me_harder (struct net *net,struct sock *sk,struct sk_buff *skb,unsigned int addr_type)
@@ -30,7 +31,7 @@ int ip_route_me_harder(struct net *net, struct sock *sk, struct sk_buff *skb, unstruct flow_keys flkeys;unsigned int hh_len; - sk =sk_to_full_sk (sk); + sk =nf_sk_to_full_sk (sk); flags = sk ?inet_sk_flowi_flags (sk) :0 ;if (addr_type ==RTN_UNSPEC )
net/ipv6/netfilter.c +2 -1
@@ -17,14 +17,15 @@#include <net/ip6_route.h> #include <net/xfrm.h> #include <net/netfilter/nf_queue.h> +#include <net/netfilter/nf_socket.h> #include <net/netfilter/nf_conntrack_bridge.h> #include <net/netfilter/ipv6/nf_defrag_ipv6.h> #include "../bridge/br_private.h" int ip6_route_me_harder (struct net *net,struct sock *sk_partial,struct sk_buff *skb) { +struct sock *sk =nf_sk_to_full_sk (sk_partial);const struct ipv6hdr *iph =ipv6_hdr (skb); -struct sock *sk =sk_to_full_sk (sk_partial);struct net_device *dev =skb_dst_dev (skb);struct flow_keys flkeys;unsigned int hh_len;
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 14/15 netfilter: nft_exthdr: remove redundant op parsing in tcp_set_init
In reply to Pablo Neira AyusoFrom: Fernando Fernandez Mancera <[email protected]>
The nft_exthdr_tcp_set_init() function is exclusively used for TCP options. Therefore, parsing the NFTA_EXTHDR_OP attribute from user space is redundant, as the operation type must always be NFT_EXTHDR_OP_TCPOPT.
Remove the unnecessary netlink attribute parsing and hardcode priv->op to NFT_EXTHDR_OP_TCPOPT, which simplifies the code and reduces the object size.
./scripts/bloat-o-meter exthdr_before.o exthdr_after.o add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-54 (-54)
Function old new delta nft_exthdr_tcp_set_init 412 358 -54
Total: Before=6581, After=6527, chg -0.82%
--- net/netfilter/nft_exthdr.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
net/netfilter/nft_exthdr.c +2 -6
@@ -551,7 +551,7 @@ static int nft_exthdr_tcp_set_init(const struct nft_ctx *ctx, const struct nlattr * const tb[]) {struct nft_exthdr *priv =nft_expr_priv (expr); -u32 offset, len, flags =0 , op =NFT_EXTHDR_OP_IPV6 ; +u32 offset, len, flags =0 ;int err; if (!tb[NFTA_EXTHDR_SREG] ||
@@ -581,15 +581,11 @@ static int nft_exthdr_tcp_set_init(const struct nft_ctx *ctx,return -EOPNOTSUPP ; } - err =nft_parse_u32_check (tb[NFTA_EXTHDR_OP ],U8_MAX , &op); -if (err <0 ) -return err; - priv->type =nla_get_u8 (tb[NFTA_EXTHDR_TYPE ]); priv->offset = offset; priv->len = len; priv->flags = flags; - priv->op = op; + priv->op =NFT_EXTHDR_OP_TCPOPT ;return nft_parse_register_load (ctx, tb[NFTA_EXTHDR_SREG ], &priv->sreg, priv->len);
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 15/15 netfilter: nft_exthdr: avoid 60 bytes stack buffer in TCP option mangling
In reply to Pablo Neira AyusoFrom: Fernando Fernandez Mancera <[email protected]>
nft_exthdr_tcp_set_eval() and nft_exthdr_tcp_strip_eval() fetched the TCP header and options through nft_tcp_header_pointer(), which calls skb_header_pointer() a second time for the full tcphdr_len into a 60 bytes stack buffer. Since commit 28427f368f0e ("netfilter: nft_exthdr:
Fix non-linear header modification") both functions then call skb_ensure_writable() and re-read the header from skb->data, so the buffer was never used.
Only the 20 bytes fixed header is needed to learn tcphdr_len, so fetch just that, validate the length as before, and let skb_ensure_writable() pull the rest. This also drops the 60 bytes stack buffer from both functions.
Comparison of performance in mpps:
op linear/non-linear before after delta
==================================================================
set, non-linear 4.193 4.348 +3.7% mpps strip, non-linear 4.184 4.434 +6.0% mpps set, linear 5.302 5.427 +2.4% mpps strip, linear 5.452 5.527 +1.4% mpss
Comparison of performance in ns/expression:
op linear/non-linear before after delta
==================================================================
set, non-linear 34.6 25.3 -9.4 ns strip, non-linear 35.2 20.8 -14.3 ns set, linear 23.6 19.7 -3.9 ns strip, linear 22.9 19.8 -3.1 ns
./scripts/bloat-o-meter exthdr_before.o exthdr_after.o add/remove: 0/1 grow/shrink: 3/0 up/down: 233/-207 (26)
Function old new delta nft_exthdr_tcp_eval 792 946 +154 nft_exthdr_tcp_strip_eval 825 891 +66 nft_exthdr_tcp_set_eval 602 615 +13 nft_tcp_header_pointer.part.constprop 207 - -207
Total: Before=6527, After=6553, chg +0.40%
This also allow the compiler to inline nft_tcp_header_pointer inside nft_exthdr_tcp_eval() which could yield some minimal performance gain.
--- net/netfilter/nft_exthdr.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-)
net/netfilter/nft_exthdr.c +20 -6
@@ -233,16 +233,23 @@ static void nft_exthdr_tcp_set_eval(const struct nft_expr *expr,struct nft_regs *regs, const struct nft_pktinfo *pkt) { - u8 buff[sizeof(struct tcphdr) + MAX_TCP_OPTION_SPACE]; struct nft_exthdr *priv = nft_expr_priv(expr);unsigned int i, optl, tcphdr_len, offset; -struct tcphdr *tcph; +struct tcphdr *tcph, _tcph;u8 *opt; - tcph =nft_tcp_header_pointer (pkt,sizeof (buff), buff, &tcphdr_len); +if (pkt->tprot !=IPPROTO_TCP || pkt->fragoff) + goto err; + + tcph =skb_header_pointer (pkt->skb,nft_thoff (pkt),sizeof (_tcph), &_tcph);if (!tcph) goto err; + tcphdr_len =__tcp_hdrlen (tcph); +if (tcphdr_len <sizeof (*tcph) || + tcphdr_len >sizeof (*tcph) +MAX_TCP_OPTION_SPACE ) + goto err; +if (skb_ensure_writable (pkt->skb,nft_thoff (pkt) + tcphdr_len)) goto err;
@@ -313,16 +320,23 @@ static void nft_exthdr_tcp_strip_eval(const struct nft_expr *expr,struct nft_regs *regs, const struct nft_pktinfo *pkt) { - u8 buff[sizeof(struct tcphdr) + MAX_TCP_OPTION_SPACE]; struct nft_exthdr *priv = nft_expr_priv(expr);unsigned int i, tcphdr_len, optl; -struct tcphdr *tcph; +struct tcphdr *tcph, _tcph;u8 *opt; - tcph =nft_tcp_header_pointer (pkt,sizeof (buff), buff, &tcphdr_len); +if (pkt->tprot !=IPPROTO_TCP || pkt->fragoff) + goto err; + + tcph =skb_header_pointer (pkt->skb,nft_thoff (pkt),sizeof (_tcph), &_tcph);if (!tcph) goto err; + tcphdr_len =__tcp_hdrlen (tcph); +if (tcphdr_len <sizeof (*tcph) || + tcphdr_len >sizeof (*tcph) +MAX_TCP_OPTION_SPACE ) + goto err; +if (skb_ensure_writable (pkt->skb,nft_thoff (pkt) + tcphdr_len)) goto drop;
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerHi,
+Cc: [email protected]
This is a report on sashiko's findings:
https://sashiko.dev/#/patchset/20261011215953.1334630-1-pablo%40netfilter.org
Quoted 9 lines · Pablo Neira Ayuso
Hi,
The following patchset contains Netfilter/IPVS updates for net-next:
1) Disable
br_netfilterin userns and schedule it for removal in 2027, from Florian Westphal.2) Prepare the flowtable to support for IPv4 over IPv6 tunneling and vice-versa, this includes 5 patches from Lorenzo Bianconi.
I am afraid this preparation series is enabling more than it should, sashiko reports type confusion is possible, for example:
1/5 netfilter: flowtable: recognize IPv4/IPv6 in tunnel proto matching
this adds the initial pre-processing of IPv6-over-IPv4.
But then, nf_flow_offload_lookup() expects to handle IPv4, not an IPv6 packet.
I will repost this PR keeping them back.
Quoted 6 lines
3) Update selftest
nft_queue.shto make it more stable on debug kernels, from Jakub Kicinski.4) Fix a overflow in IPVS sync messages which can only happen in very old 2.6 kernels, from Julian Anastasov.
Quoted 8 lines
5) Flush conntrack gc worker when existing netns to address a unlikely UaF, from Florian Westphal.
6) Switch
nf_tableschain types to use rcu, otherwise module removal can trigger UaF, also from Florian.7) Add two new helper functions to validate that socket is of inet type, coming in 2 patches from Florian Westphal.
sashiko reports:
"If an IPv4 packet from an AF_INET socket is encapsulated by an IPv6 tunnel, the tunnel preserves the AF_INET socket in skb->sk while transmitting the outer IPv6 packet on the LOCAL_OUT path."
This sounds like an unrelated issue, I don't know yet how that can happen TBH.
Quoted 5 lines
8) Remove redundant parsing in
nft_exthdrfor the tcp options case, from Fernando F. Mancera.9) Remove redundant
skb_header_pointer()calls innft_exthdrfor tcp options, from Fernando F. Mancera.
Sashiko here reports this now drops malformed packets instead of NFT_BREAK, which is fine, maybe just extend it to tell about this in the patch description.
I plan to drop the flowtable preparation patches and resubmit.
Quoted 70 lines
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next.gitnf-next-26-10-11Thanks.
----------------------------------------------------------------
The following changes since commit
a5e7d8e446af9803e37a3b6a4d416fb41178348f:Merge branch '100GbE' of
git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/next-queue(2026-10-05 17:51:32 -0700)are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next.gitnf-next-26-10-11for you to fetch changes up to
b4074bbf5c23b05bd34022ade979f3d5f4e86516:netfilter:
nft_exthdr: avoid 60 bytes stack buffer in TCP option mangling (2026-10-11 23:29:26 +0200)----------------------------------------------------------------
netfilter pull request 26-10-11----------------------------------------------------------------
Fernando Fernandez Mancera (2):
netfilter:nft_exthdr: remove redundant op parsing intcp_set_init
netfilter:nft_exthdr: avoid 60 bytes stack buffer in TCP option manglingFlorian Westphal (5):
netfilter: disablebr_netfilterin user namespaces
netfilter: conntrack: fix unlikely UaF in gc worker
netfilter:nf_tables: switchchain_typesarray to rcu
netfilter: addnf_skb_skhelper and use it
netfilter: addnf_sk_to_full_skhelper and use itJakub Kicinski (1):
selftests: netfilter:nft_queue.sh: only queue icmp echo request/replyJulian Anastasov (1):
ipvs: fix buffer overflow when sending sync messagesLorenzo Bianconi (6):
netfilter: flowtable: recognize IPv4/IPv6 in tunnel proto matching
netfilter: flowtable: set inner protocol when popping tunnel header
netfilter: flowtable: populate tunnel tuple regardless of inner protocol
netfilter: flowtable: addencap_prototoflow_offload_tunnel
netfilter: flowtable: refactor MTU check for tunnel offload
netfilter: flowtable: unify tunnel push for IPv4 and IPv6Documentation/networking/bridge.rst | 5 +- include/linux/netdevice.h | 1 + include/net/netfilter/nf_flow_table.h | 1 + include/net/netfilter/nf_socket.h | 35 ++++ net/bridge/br_netfilter_hooks.c | 33 +++- net/ipv4/ipip.c | 1 + net/ipv4/netfilter.c | 3 +- net/ipv6/ip6_tunnel.c | 1 + net/ipv6/netfilter.c | 3 +- net/netfilter/ipvs/ip_vs_sync.c | 23 ++- net/netfilter/nf_conntrack_core.c | 5 + net/netfilter/nf_flow_table_ip.c | 215 +++++++++++++-------- net/netfilter/nf_flow_table_path.c | 2 + net/netfilter/nf_tables_api.c | 94 ++++++--- net/netfilter/nft_chain_nat.c | 1 + net/netfilter/nft_exthdr.c | 34 ++-- net/netfilter/nft_socket.c | 16 +- net/netfilter/xt_socket.c | 26 +-- tools/testing/selftests/net/netfilter/nft_queue.sh | 2 +- 19 files changed, 336 insertions(+), 165 deletions(-)
Florian Westphal
maintainerQuoted 8 lines · Pablo Neira Ayuso
sashiko reports:
"If an IPv4 packet from an
AF_INETsocket is encapsulated by an IPv6 tunnel, the tunnel preserves theAF_INETsocket inskb->skwhile transmitting the outer IPv6 packet on theLOCAL_OUTpath."This sounds like an unrelated issue, I don't know yet how that can happen TBH.
I'm stupid and I don't understand why this would be a regression.
This change makes things stricter, so it doesn't enable anything that wasn't allowed before, how does this add a new crash regression? :-(
Florian Westphal
maintainerQuoted 7 lines · Florian Westphal
Quoted 6 lines · Pablo Neira Ayuso
sashiko reports:
"If an IPv4 packet from an
AF_INETsocket is encapsulated by an IPv6 tunnel, the tunnel preserves theAF_INETsocket inskb->skwhile transmitting the outer IPv6 packet on theLOCAL_OUTpath."
Quoted 7 lines
Quoted 2 lines
This sounds like an unrelated issue, I don't know yet how that can happen TBH.
I'm stupid and I don't understand why this would be a regression.
This change makes things stricter, so it doesn't enable anything that wasn't allowed before, how does this add a new crash regression? :-(
Please toss this patch. Lets ignore this problem.
Pablo Neira Ayuso
maintainerQuoted 11 lines · Florian Westphal
Quoted 10 lines · Florian Westphal
Quoted 8 lines · Pablo Neira Ayuso
sashiko reports:
"If an IPv4 packet from an
AF_INETsocket is encapsulated by an IPv6 tunnel, the tunnel preserves theAF_INETsocket inskb->skwhile transmitting the outer IPv6 packet on theLOCAL_OUTpath."This sounds like an unrelated issue, I don't know yet how that can happen TBH.
Quoted 6 lines
Quoted 4 lines
I'm stupid and I don't understand why this would be a regression.
This change makes things stricter, so it doesn't enable anything that wasn't allowed before, how does this add a new crash regression? :-(
Please toss this patch. Lets ignore this problem.
I really think LLM is just getting confused, because the series contains flowtable support for IPv4-over-IPv6 and vice-versa.
Then, the LLM tries to find the same pattern in the patches coming in this PR batch !:-D
Quoted 58 lines · Pablo Neira Ayuso
Hi,
+Cc: [email protected]
This is a report on sashiko's findings:
https://sashiko.dev/#/patchset/20261011215953.1334630-1-pablo%40netfilter.org
Quoted 9 lines · Pablo Neira Ayuso
Hi,
The following patchset contains Netfilter/IPVS updates for net-next:
1) Disable
br_netfilterin userns and schedule it for removal in 2027, from Florian Westphal.2) Prepare the flowtable to support for IPv4 over IPv6 tunneling and vice-versa, this includes 5 patches from Lorenzo Bianconi.
I am afraid this preparation series is enabling more than it should, sashiko reports type confusion is possible, for example:
1/5 netfilter: flowtable: recognize IPv4/IPv6 in tunnel proto matching
this adds the initial pre-processing of IPv6-over-IPv4.
But then,
nf_flow_offload_lookup()expects to handle IPv4, not an IPv6 packet.I will repost this PR keeping them back.
Quoted 6 lines
3) Update selftest
nft_queue.shto make it more stable on debug kernels, from Jakub Kicinski.4) Fix a overflow in IPVS sync messages which can only happen in very old 2.6 kernels, from Julian Anastasov.
Quoted 8 lines
5) Flush conntrack gc worker when existing netns to address a unlikely UaF, from Florian Westphal.
6) Switch
nf_tableschain types to use rcu, otherwise module removal can trigger UaF, also from Florian.7) Add two new helper functions to validate that socket is of inet type, coming in 2 patches from Florian Westphal.
sashiko reports:
"If an IPv4 packet from an
AF_INETsocket is encapsulated by an IPv6 tunnel, the tunnel preserves theAF_INETsocket inskb->skwhile transmitting the outer IPv6 packet on theLOCAL_OUTpath."This sounds like an unrelated issue, I don't know yet how that can happen TBH.
Quoted 3 lines
8) Remove redundant parsing in
nft_exthdrfor the tcp options case, from Fernando F. Mancera.
Quoted 6 lines
Quoted 2 lines
9) Remove redundant
skb_header_pointer()calls innft_exthdrfor tcp options, from Fernando F. Mancera.Sashiko here reports this now drops malformed packets instead of
NFT_BREAK, which is fine, maybe just extend it to tell about this in the patch description.
Hi Pablo,
Should I re-post a v2 of this patch or will you ammend the commit message to add this bit?
Thanks,
Fernando.
Quoted 74 lines
I plan to drop the flowtable preparation patches and resubmit.
Quoted 70 lines
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next.git nf-next-26-10-11Thanks.
----------------------------------------------------------------
The following changes since commit
a5e7d8e446af9803e37a3b6a4d416fb41178348f:Merge branch '100GbE' of git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/next-queue (2026-10-05 17:51:32 -0700)are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next.git nf-next-26-10-11for you to fetch changes up to
b4074bbf5c23b05bd34022ade979f3d5f4e86516:netfilter:
nft_exthdr: avoid 60 bytes stack buffer in TCP option mangling (2026-10-11 23:29:26 +0200)----------------------------------------------------------------
netfilter pull request 26-10-11----------------------------------------------------------------
Fernando Fernandez Mancera (2):
netfilter:nft_exthdr: remove redundant op parsing intcp_set_init
netfilter:nft_exthdr: avoid 60 bytes stack buffer in TCP option manglingFlorian Westphal (5):
netfilter: disablebr_netfilterin user namespaces
netfilter: conntrack: fix unlikely UaF in gc worker
netfilter:nf_tables: switchchain_typesarray to rcu
netfilter: addnf_skb_skhelper and use it
netfilter: addnf_sk_to_full_skhelper and use itJakub Kicinski (1):
selftests: netfilter:nft_queue.sh: only queue icmp echo request/replyJulian Anastasov (1):
ipvs: fix buffer overflow when sending sync messagesLorenzo Bianconi (6):
netfilter: flowtable: recognize IPv4/IPv6 in tunnel proto matching
netfilter: flowtable: set inner protocol when popping tunnel header
netfilter: flowtable: populate tunnel tuple regardless of inner protocol
netfilter: flowtable: addencap_prototoflow_offload_tunnel
netfilter: flowtable: refactor MTU check for tunnel offload
netfilter: flowtable: unify tunnel push for IPv4 and IPv6Documentation/networking/bridge.rst | 5 +- include/linux/netdevice.h | 1 + include/net/netfilter/nf_flow_table.h | 1 + include/net/netfilter/nf_socket.h | 35 ++++ net/bridge/br_netfilter_hooks.c | 33 +++- net/ipv4/ipip.c | 1 + net/ipv4/netfilter.c | 3 +- net/ipv6/ip6_tunnel.c | 1 + net/ipv6/netfilter.c | 3 +- net/netfilter/ipvs/ip_vs_sync.c | 23 ++- net/netfilter/nf_conntrack_core.c | 5 + net/netfilter/nf_flow_table_ip.c | 215 +++++++++++++-------- net/netfilter/nf_flow_table_path.c | 2 + net/netfilter/nf_tables_api.c | 94 ++++++--- net/netfilter/nft_chain_nat.c | 1 + net/netfilter/nft_exthdr.c | 34 ++-- net/netfilter/nft_socket.c | 16 +- net/netfilter/xt_socket.c | 26 +-- tools/testing/selftests/net/netfilter/nft_queue.sh | 2 +- 19 files changed, 336 insertions(+), 165 deletions(-)
Pablo Neira Ayuso
maintainerQuoted 62 lines · Fernando Fernandez Mancera
Quoted 61 lines · Pablo Neira Ayuso
Hi,
+Cc: [email protected]
This is a report on sashiko's findings:
https://sashiko.dev/#/patchset/20261011215953.1334630-1-pablo%40netfilter.org
Quoted 9 lines · Pablo Neira Ayuso
Hi,
The following patchset contains Netfilter/IPVS updates for net-next:
1) Disable
br_netfilterin userns and schedule it for removal in 2027, from Florian Westphal.2) Prepare the flowtable to support for IPv4 over IPv6 tunneling and vice-versa, this includes 5 patches from Lorenzo Bianconi.
I am afraid this preparation series is enabling more than it should, sashiko reports type confusion is possible, for example:
1/5 netfilter: flowtable: recognize IPv4/IPv6 in tunnel proto matching
this adds the initial pre-processing of IPv6-over-IPv4.
But then,
nf_flow_offload_lookup()expects to handle IPv4, not an IPv6 packet.I will repost this PR keeping them back.
Quoted 6 lines
3) Update selftest
nft_queue.shto make it more stable on debug kernels, from Jakub Kicinski.4) Fix a overflow in IPVS sync messages which can only happen in very old 2.6 kernels, from Julian Anastasov.
Quoted 8 lines
5) Flush conntrack gc worker when existing netns to address a unlikely UaF, from Florian Westphal.
6) Switch
nf_tableschain types to use rcu, otherwise module removal can trigger UaF, also from Florian.7) Add two new helper functions to validate that socket is of inet type, coming in 2 patches from Florian Westphal.
sashiko reports:
"If an IPv4 packet from an
AF_INETsocket is encapsulated by an IPv6 tunnel, the tunnel preserves theAF_INETsocket inskb->skwhile transmitting the outer IPv6 packet on theLOCAL_OUTpath."This sounds like an unrelated issue, I don't know yet how that can happen TBH.
Quoted 5 lines
8) Remove redundant parsing in
nft_exthdrfor the tcp options case, from Fernando F. Mancera.9) Remove redundant
skb_header_pointer()calls innft_exthdrfor tcp options, from Fernando F. Mancera.
Quoted 8 lines
Quoted 3 lines
Sashiko here reports this now drops malformed packets instead of
NFT_BREAK, which is fine, maybe just extend it to tell about this in the patch description.Hi Pablo,
Should I re-post a v2 of this patch or will you ammend the commit message to add this bit?
I will amend the commit message here, no problem.