netfilter: updates for net
Subsystems (4)
Florian Westphal
maintainercover netfilter: updates for net
Hi,
The following patchset contains Netfilter fixes for *net*, all for ancient problems. Patch 7 raised drive-by sashiko findings, but those are not related to the change itself.
1) Rebuild the nf_nat_sip data pointer to prevent stale access after SKB reallocation. Restrict UDP mangling to UDP streams to avoid TCP packet corruption.
2) Prevent undefined behavior in xt_u32 caused by invalid shift counts. From Wyatt Feng.
3) Use u64 variables to prevent incorrect comparisons on links exceeding 34 Gbps in xt_rateest. From Feng Wu.
4) Cap the number of expectations per master during nfnetlink_cthelper updates. From Pablo Neira Ayuso.
5) Mark malformed IPv6 extension headers for hotdrop in ip6tables. From Zhixing Chen.
6) Skip the end element of an open interval during the get command when its closest match is the interval's start element. Also from Pablo Neira Ayuso.
7) Fix PMTU calculation for GUE/GRE tunnels in IPVS during ICMP fragmentation error handling. Include additional tunnel header length when computing the new MTU. From Yizhou Zhao.
8) Reset full ip_vs_seq structures in ip_vs_conn_new. Also from Yizhou Zhao.
9) Reject invalid shift parameters in xt_connmark. Also from Wyatt Feng.
Please, pull these changes from:
The following changes since commit d335dcc6f521571d57117b8deeebc940836e5450:
gue: validate REMCSUM private option length (2026-07-03 09:34:53 +0100)
are available in the Git repository at:
https://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git tags/nf-26-07-03
for you to fetch changes up to 1b47026fb4b35bac850ad6e8a4ad7fc018e09ebc:
netfilter: xt_connmark: reject invalid shift parameters (2026-07-03 14:45:21 +0200)
----------------------------------------------------------------
netfilter pull request nf-26-07-03
----------------------------------------------------------------
Feng Wu (1):
netfilter: xt_rateest: fix u64 truncation in xt_rateest_mt()
Florian Westphal (1):
netfilter: nf_nat_sip: reload possible stale data pointer
Pablo Neira Ayuso (2):
netfilter: nfnetlink_cthelper: cap to maximum number of expectation
per master on updates
netfilter: nft_set_rbtree: get command skips end element with open
interval
Wyatt Feng (2):
netfilter: xt_u32: reject invalid shift counts
netfilter: xt_connmark: reject invalid shift parameters
Yizhou Zhao (2):
ipvs: fix PMTU for GUE/GRE tunnel ICMP errors
ipvs: reset full ip_vs_seq structs in ip_vs_conn_new
Zhixing Chen (1):
netfilter: ip6tables: mark malformed IPv6 extension headers for hotdrop
net/ipv6/netfilter/ip6t_ah.c | 5 +++++ net/ipv6/netfilter/ip6t_hbh.c | 1 + net/ipv6/netfilter/ip6t_rt.c | 3 ++- net/netfilter/ipvs/ip_vs_conn.c | 4 ++-- net/netfilter/ipvs/ip_vs_core.c | 6 +++--- net/netfilter/nf_nat_sip.c | 11 +++++++++++ net/netfilter/nf_tables_api.c | 3 +++ net/netfilter/nfnetlink_cthelper.c | 2 ++ net/netfilter/nft_set_rbtree.c | 8 ++++++-- net/netfilter/xt_connmark.c | 14 ++++++++++++-- net/netfilter/xt_rateest.c | 2 +- net/netfilter/xt_u32.c | 12 +++++++++++- 12 files changed, 59 insertions(+), 12 deletions(-)
Signature · 1 line
2.54.0
Florian Westphal
maintainerPATCH 1/9 netfilter: nf_nat_sip: reload possible stale data pointer
quoting sashiko:
------------------------------------------------------------------------
[..] noticed a potential memory bug and header corruption involving the SIP NAT helper.
In net/netfilter/nf_nat_sip.c:nf_nat_sip():
if (skb_ensure_writable(skb, skb->len)) {
nf_ct_helper_log(skb, ct, "cannot mangle packet");
return NF_DROP;
}
uh = (void *)skb->data + protoff;
uh->dest = ct_sip_info->forced_dport;
if (!nf_nat_mangle_udp_packet(skb, ct, ctinfo, protoff,
0, 0, NULL, 0)) { If a cloned or fragmented SKB is reallocated by skb_ensure_writable(), the old data buffer is freed. However, nf_nat_sip() fails to update *dptr to point to the new buffer.
It also appears to use nf_nat_mangle_udp_packet() on what could be a TCP packet, which would overwrite the sequence number with a checksum update.
------------------------------------------------------------------------
nf_conntrack_sip linerizes skbs, hence no fragmented skb can be seen. But clones are possible, so rebuild dptr.
Disable nf_nat_mangle_udp_packet() branch for TCP streams. It doesn't look like this can ever happen, else we should have received bug reports about this, so just check the conntrack is UDP and drop otherwise.
The calling conntrack_sip set ->forced_dport for SIP_HDR_VIA_UDP messages, so I don't think this is ever expected to be true for a TCP stream.
--- net/netfilter/nf_nat_sip.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
net/netfilter/nf_nat_sip.c +11 -0
@@ -289,13 +289,24 @@ static unsigned int nf_nat_sip(struct sk_buff *skb, unsigned int protoff,/* Mangle destination port for Cisco phones, then fix up checksums */ if (dir ==IP_CT_DIR_REPLY && ct_sip_info->forced_dport) { +int doff = *dptr - (const char *)skb->data;struct udphdr *uh; +if (doff <=0 ) { +DEBUG_NET_WARN_ON_ONCE (1 ); +return NF_DROP ; + } + +/* ct_sip_info->forced_dport only expected with UDP */ +if (nf_ct_protonum (ct) !=IPPROTO_UDP ) +return NF_DROP ; +if (skb_ensure_writable (skb, skb->len)) {nf_ct_helper_log (skb, ct,"cannot mangle packet" );return NF_DROP ; } + *dptr = skb->data + doff; uh = (void *)skb->data + protoff; uh->dest = ct_sip_info->forced_dport;
Signature · 1 line
2.54.0
Re: [PATCH net 1/9] netfilter: nf_nat_sip: reload possible stale data pointer
This series was applied to netdev/net.git (main) by Florian Westphal <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Florian Westphal <[email protected]>:
Quoted 15 lines · On Fri, 3 Jul 2026 14:57:01 +0200 you wrote:
quoting sashiko:
------------------------------------------------------------------------
[..] noticed a potential memory bug and header corruption involving the SIP NAT helper.In net/netfilter/nf_nat_sip.c:nf_nat_sip():
if (skb_ensure_writable(skb, skb->len)) { nf_ct_helper_log(skb, ct, "cannot mangle packet"); return NF_DROP; } uh = (void *)skb->data + protoff; uh->dest = ct_sip_info->forced_dport; if (!nf_nat_mangle_udp_packet(skb, ct, ctinfo, protoff, 0, 0, NULL, 0)) {
Quoted 1 line
[...]
Here is the summary with links:
- [net,1/9] netfilter: nf_nat_sip: reload possible stale data pointer
https://git.kernel.org/netdev/net/c/77e43bcb7ec1 - [net,2/9] netfilter: xt_u32: reject invalid shift counts https://git.kernel.org/netdev/net/c/64cdf7d30ac1 - [net,3/9] netfilter: xt_rateest: fix u64 truncation in xt_rateest_mt() https://git.kernel.org/netdev/net/c/444853cd4382 - [net,4/9] netfilter: nfnetlink_cthelper: cap to maximum number of expectation per master on updates https://git.kernel.org/netdev/net/c/278296b69fae - [net,5/9] netfilter: ip6tables: mark malformed IPv6 extension headers for hotdrop https://git.kernel.org/netdev/net/c/43ccc20b5a73 - [net,6/9] netfilter: nft_set_rbtree: get command skips end element with open interval https://git.kernel.org/netdev/net/c/d63611cbe8af - [net,7/9] ipvs: fix PMTU for GUE/GRE tunnel ICMP errors https://git.kernel.org/netdev/net/c/6b335af0d0d1 - [net,8/9] ipvs: reset full ip_vs_seq structs in ip_vs_conn_new https://git.kernel.org/netdev/net/c/2975324d164c - [net,9/9] netfilter: xt_connmark: reject invalid shift parameters https://git.kernel.org/netdev/net/c/1b47026fb4b3
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Florian Westphal
maintainerPATCH 2/9 netfilter: xt_u32: reject invalid shift counts
In reply to Florian WestphalFrom: Wyatt Feng <[email protected]>
u32_match_it() executes rule-supplied shift operands on a 32-bit value. A malformed u32 rule can provide a shift count of 32 or more, triggering an undefined shift out-of-bounds during packet evaluation.
Validate XT_U32_LEFTSH and XT_U32_RIGHTSH operands in u32_mt_checkentry() and reject malformed rules before they reach the packet path.
--- net/netfilter/xt_u32.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
net/netfilter/xt_u32.c +11 -1
@@ -100,7 +100,7 @@ static int u32_mt_checkentry(const struct xt_mtchk_param *par) {const struct xt_u32 *data = par->matchinfo;const struct xt_u32_test *ct; -unsigned int i; +unsigned int i, j;if (data->ntests >ARRAY_SIZE (data->tests))return -EINVAL ;
@@ -111,6 +111,16 @@ static int u32_mt_checkentry(const struct xt_mtchk_param *par)if (ct->nnums >ARRAY_SIZE (ct->location) || ct->nvalues >ARRAY_SIZE (ct->value))return -EINVAL ; + +for (j =1 ; j < ct->nnums; ++j) { +switch (ct->location[j].nextop) { +case XT_U32_LEFTSH : +case XT_U32_RIGHTSH : +if (ct->location[j].number >=32 ) +return -EINVAL ; +break ; + } + } }return 0 ;
Signature · 1 line
2.54.0
Florian Westphal
maintainerPATCH 3/9 netfilter: xt_rateest: fix u64 truncation in xt_rateest_mt()
In reply to Florian WestphalFrom: Feng Wu <[email protected]>
On links faster than ~34 Gbps, where byte rate may exceed 2^32-1 (~ 4.3 GBps), the comparison result becomes incorrect because the truncated value no longer reflects the actual estimator rate.
Fix by changing the local variables to u64.
--- net/netfilter/xt_rateest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/xt_rateest.c +1 -1
@@ -16,7 +16,7 @@ xt_rateest_mt(const struct sk_buff *skb, struct xt_action_param *par) {const struct xt_rateest_match_info *info = par->matchinfo;struct gnet_stats_rate_est64 sample = {0 }; -u_int32_t bps1, bps2, pps1, pps2; +u64 bps1, bps2, pps1, pps2;bool ret = true;gen_estimator_read (&info->est1->rate_est, &sample);
Signature · 1 line
2.54.0
Florian Westphal
maintainerPATCH 4/9 netfilter: nfnetlink_cthelper: cap to maximum number of expectation per master on updates
In reply to Florian WestphalFrom: Pablo Neira Ayuso <[email protected]>
Really cap it to NF_CT_EXPECT_MAX_CNT (255) on updates.
The commit ("netfilter: nfnetlink_cthelper: cap to maximum number of expectation per master") only covers creation of helpers, not updates.
--- net/netfilter/nfnetlink_cthelper.c | 2 ++ 1 file changed, 2 insertions(+)
net/netfilter/nfnetlink_cthelper.c +2 -0
@@ -316,6 +316,8 @@ nfnl_cthelper_update_policy_one(const struct nf_conntrack_expect_policy *policy, new_policy->max_expected =ntohl (nla_get_be32 (tb[NFCTH_POLICY_EXPECT_MAX ])); +if (!new_policy->max_expected) + new_policy->max_expected =NF_CT_EXPECT_MAX_CNT ;if (new_policy->max_expected >NF_CT_EXPECT_MAX_CNT )return -EINVAL ;
Signature · 1 line
2.54.0
Florian Westphal
maintainerPATCH 5/9 netfilter: ip6tables: mark malformed IPv6 extension headers for hotdrop
In reply to Florian WestphalFrom: Zhixing Chen <[email protected]>
The ah, hbh and rt matches check that the fixed extension header is present, then use the header length field to derive the advertised extension header length for matching.
For the ah match, add the missing advertised-length check. For hbh and rt, update the existing advertised-length checks. In all three cases, set hotdrop to true before returning false when the advertised extension header length exceeds the available skb data.
Returning false treats the packet as a rule mismatch. Set hotdrop to true and drop malformed packets so they cannot bypass rules intended to drop packets with these IPv6 extension headers.
--- net/ipv6/netfilter/ip6t_ah.c | 5 +++++ net/ipv6/netfilter/ip6t_hbh.c | 1 + net/ipv6/netfilter/ip6t_rt.c | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-)
net/ipv6/netfilter/ip6t_ah.c +5 -0
@@ -56,6 +56,11 @@ static bool ah_mt6(const struct sk_buff *skb, struct xt_action_param *par) } hdrlen =ipv6_authlen (ah); +if (skb->len - ptr < hdrlen) { +/* Packet smaller than its length field */ + par->hotdrop = true; +return false; + }pr_debug ("IPv6 AH LEN %u %u " , hdrlen, ah->hdrlen);pr_debug ("RES %04X " , ah->reserved);
net/ipv6/netfilter/ip6t_hbh.c +1 -0
@@ -75,6 +75,7 @@ hbh_mt6(const struct sk_buff *skb, struct xt_action_param *par) hdrlen =ipv6_optlen (oh);if (skb->len - ptr < hdrlen) {/* Packet smaller than it's length field */ + par->hotdrop = true;return false; }
net/ipv6/netfilter/ip6t_rt.c +2 -1
@@ -56,7 +56,8 @@ static bool rt_mt6(const struct sk_buff *skb, struct xt_action_param *par) hdrlen =ipv6_optlen (rh);if (skb->len - ptr < hdrlen) { -/* Pcket smaller than its length field */ +/* Packet smaller than its length field */ + par->hotdrop = true;return false; }
Signature · 1 line
2.54.0
Florian Westphal
maintainerPATCH 6/9 netfilter: nft_set_rbtree: get command skips end element with open interval
In reply to Florian WestphalFrom: Pablo Neira Ayuso <[email protected]>
The get command on intervals provide partial matches such as subranges for usability reasons. However, an open interval has no closing end element. If the closing element matches within the range of the open internal, ie. its closest match is the start element of the open range, then, return 0 but offer no matching element to userspace through netlink as a special case. Userspace provides at least a matching start element in this case and the closing end element matching the open interal is ignored.
Another possibility is to report the matching start element of the open interval for this end interval. However, this results in duplicated matching being listed in userspace because userspace does not expect a start element as response to a end element.
--- net/netfilter/nf_tables_api.c | 3 +++ net/netfilter/nft_set_rbtree.c | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-)
net/netfilter/nf_tables_api.c +3 -0
@@ -6563,6 +6563,9 @@ static int nft_get_set_elem(struct nft_ctx *ctx, const struct nft_set *set,if (err <0 )return err; +if (!elem.priv) +return 0 ; + err = -ENOMEM ; skb =nlmsg_new (NLMSG_GOODSIZE ,GFP_ATOMIC );if (skb ==NULL )
net/netfilter/nft_set_rbtree.c +6 -2
@@ -184,10 +184,14 @@ nft_rbtree_get(const struct net *net, const struct nft_set *set,if (!interval ||nft_set_elem_expired (interval->from))return ERR_PTR (-ENOENT ); -if (flags &NFT_SET_ELEM_INTERVAL_END ) +if (flags &NFT_SET_ELEM_INTERVAL_END ) { +if (!interval->to) +return NULL ; + rbe = container_of(interval->to, struct nft_rbtree_elem, ext); -else + }else { rbe = container_of(interval->from, struct nft_rbtree_elem, ext); + }return &rbe->priv; }
Signature · 1 line
2.54.0
Florian Westphal
maintainerPATCH 7/9 ipvs: fix PMTU for GUE/GRE tunnel ICMP errors
In reply to Florian WestphalFrom: Yizhou Zhao <[email protected]>
When an ICMP Fragmentation Needed error is received for a tunneled IPVS connection, ip_vs_in_icmp() recomputes the MTU that the original packet can use by subtracting the tunnel overhead from the reported next-hop MTU.
The current code always subtracts sizeof(struct iphdr), which is only the IPIP overhead. For GUE and GRE tunnels, ipvs_udp_decap() and ipvs_gre_decap() already compute the additional tunnel header length, but that value is scoped to the decapsulation block and is lost before the ICMP_FRAG_NEEDED handling. As a result, the ICMP error sent back to the client advertises an MTU that is too large, so PMTUD can fail to converge for GUE/GRE-tunneled real servers.
With a reported next-hop MTU of 1400, a GUE tunnel currently returns 1380 to the client. The correct value is 1368:
1400 - sizeof(struct iphdr) - sizeof(struct udphdr) - sizeof(struct guehdr)
Hoist the tunnel header length into the main ip_vs_in_icmp() scope and subtract sizeof(struct iphdr) + ulen in the Fragmentation Needed path. The IPIP path keeps ulen as 0, so its existing 1400 - 20 = 1380 result is unchanged.
--- net/netfilter/ipvs/ip_vs_core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +3 -3
@@ -1767,6 +1767,7 @@ ip_vs_in_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb, int *related,bool tunnel, new_cp = false;union nf_inet_addr *raddr;char *outer_proto ="IPIP" ; +int ulen =0 ; *related =1 ;
@@ -1831,7 +1832,6 @@ ip_vs_in_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb, int *related,/* Error for our tunnel must arrive at LOCAL_IN */ (skb_rtable(skb)->rt_flags & RTCF_LOCAL)) {__u8 iproto; -int ulen;/* Non-first fragment has no UDP/GRE header */ if (unlikely (cih->frag_off &htons (IP_OFFSET )))
@@ -1936,8 +1936,8 @@ ip_vs_in_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb, int *related,if (dest_dst) mtu =dst_mtu (dest_dst->dst_cache); } -if (mtu >68 +sizeof (struct iphdr )) - mtu -=sizeof (struct iphdr ); +if (mtu >68 +sizeof (struct iphdr ) + ulen) + mtu -=sizeof (struct iphdr ) + ulen; info =htonl (mtu); }/* Strip outer IP, ICMP and IPIP/UDP/GRE, go to IP header of
Signature · 1 line
2.54.0
Florian Westphal
maintainerPATCH 8/9 ipvs: reset full ip_vs_seq structs in ip_vs_conn_new
In reply to Florian WestphalFrom: Yizhou Zhao <[email protected]>
Commit 9a05475cebdd ("ipvs: avoid kmem_cache_zalloc in ip_vs_conn_new") changed ip_vs_conn_new() to allocate an ip_vs_conn object with kmem_cache_alloc(). The function then initializes many fields explicitly, but only resets in_seq.delta and out_seq.delta in the two struct ip_vs_seq members.
That leaves init_seq and previous_delta uninitialized. This is normally harmless while the corresponding IP_VS_CONN_F_IN_SEQ or IP_VS_CONN_F_OUT_SEQ flag is clear. For connections learned from a sync message, however, ip_vs_proc_conn() preserves those flags from IP_VS_CONN_F_BACKUP_MASK and passes opt=NULL when the message omits IPVS_OPT_SEQ_DATA. In that case the new connection can be hashed with SEQ flags set but with the rest of in_seq/out_seq still containing stale slab data.
When a packet for such a connection is later handled by an IPVS application helper, vs_fix_seq() and vs_fix_ack_seq() use previous_delta and init_seq to rewrite TCP sequence numbers. A malformed sync message can therefore make forwarded packets carry stale slab bytes in their TCP seq/ack numbers, and can also corrupt the forwarded TCP flow.
Reset both struct ip_vs_seq members completely before publishing the connection. This matches the existing "reset struct ip_vs_seq" comment and keeps the sequence-adjustment gates inactive unless valid sequence data is installed later.
--- net/netfilter/ipvs/ip_vs_conn.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/ipvs/ip_vs_conn.c +2 -2
@@ -1420,8 +1420,8 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af, cp->app =NULL ; cp->app_data =NULL ;/* reset struct ip_vs_seq */ - cp->in_seq.delta =0 ; - cp->out_seq.delta =0 ; +memset (&cp->in_seq,0 ,sizeof (cp->in_seq)); +memset (&cp->out_seq,0 ,sizeof (cp->out_seq));if (unlikely (flags &IP_VS_CONN_F_NO_CPORT )) {int af_id =ip_vs_af_index (cp->af);
Signature · 1 line
2.54.0
Florian Westphal
maintainerPATCH 9/9 netfilter: xt_connmark: reject invalid shift parameters
In reply to Florian WestphalFrom: Wyatt Feng <[email protected]>
Revision 2 of the CONNMARK target accepts user-controlled shift parameters and applies them to 32-bit mark values in connmark_tg_shift().
A shift_bits value of 32 or more triggers an undefined-shift bug when the rule is evaluated. Invalid shift_dir values are also accepted and silently fall back to the left-shift path.
Reject invalid revision-2 shift parameters in connmark_tg_check() so malformed rules fail at installation time, before they can reach the packet path.
--- net/netfilter/xt_connmark.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
net/netfilter/xt_connmark.c +12 -2
@@ -112,6 +112,16 @@ static int connmark_tg_check(const struct xt_tgchk_param *par)return ret; } +static int connmark_tg_check_v2 (const struct xt_tgchk_param *par) +{ +const struct xt_connmark_tginfo2 *info = par->targinfo; + +if (info->shift_dir >D_SHIFT_RIGHT || info->shift_bits >=32 ) +return -EINVAL ; + +return connmark_tg_check (par); +} +static void connmark_tg_destroy (const struct xt_tgdtor_param *par) {nf_ct_netns_put (par->net, par->family);
@@ -162,7 +172,7 @@ static struct xt_target connmark_tg_reg[] __read_mostly = { .name = "CONNMARK", .revision = 2, .family = NFPROTO_IPV4, - .checkentry = connmark_tg_check, + .checkentry = connmark_tg_check_v2, .target = connmark_tg_v2, .targetsize = sizeof(struct xt_connmark_tginfo2), .destroy = connmark_tg_destroy,
@@ -183,7 +193,7 @@ static struct xt_target connmark_tg_reg[] __read_mostly = { .name = "CONNMARK", .revision = 2, .family = NFPROTO_IPV6, - .checkentry = connmark_tg_check, + .checkentry = connmark_tg_check_v2, .target = connmark_tg_v2, .targetsize = sizeof(struct xt_connmark_tginfo2), .destroy = connmark_tg_destroy,
Signature · 1 line
2.54.0
Florian Westphal
maintainerQuoted 3 lines · Florian Westphal
The following patchset contains Netfilter fixes for *net*, all for ancient problems. Patch 7 raised drive-by sashiko findings, but those are not related to the change itself.
There more unrelated findings, those will be addressed in a future PR.