Netfilter/IPVS fixes for net
Subsystems (4)
Pablo Neira Ayuso
maintainercover Netfilter/IPVS fixes for net
Hi,
The following batch contains Netfilter/IPVS fixes for net:
1) nft_osf actually only supports IPv4, restrict it.
2) Address possible division by zero in nfnetlink_osf, from Xiang Mei.
3) Remove unsafe use of sprintf to fix possible buffer overflow in the SIP NAT helper, from Florian Westphal.
4) Restrict xt_mac, xt_owner and xt_physdev to inet families only; xt_realm is only for ipv4, otherwise null-pointer-deref is possible.
5) Use kfree_rcu() in nat core to release hooks, this can be an issue once nfnetlink_hook gets support to dump NAT hook information, not currently a real issue but better fix it now. From Florian Westphal.
6) Fix MTU checks in IPVS, from Yingnan Zhang.
7) Fix possible out-of-bounds when matching TCP options in nfnetlink_osf, from Fernando Fernandez Mancera.
8) Fix potential nul-ptr-deref in ttl check in nfnetlink_osf, remove useless loop to fix this, also from Fernando.
This is a smaller batch, there are more patches pending in the queue to arm another pull request as soon as this is considered good enough.
AI might complain again about one more issue regarding osf and big-endian arches in osf but this batch is targetting crash fixes for osf at this stage.
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git nf-26-04-20
Thanks.
----------------------------------------------------------------
The following changes since commit a663bac71a2f0b3ac6c373168ca57b2a6e6381aa:
net: mctp: fix don't require received header reserved bits to be zero (2026-04-20 11:46:57 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git tags/nf-26-04-20
for you to fetch changes up to 711987ba281fd806322a7cd244e98e2a81903114:
netfilter: nfnetlink_osf: fix potential NULL dereference in ttl check (2026-04-20 23:45:44 +0200)
----------------------------------------------------------------
netfilter pull request 26-04-20
----------------------------------------------------------------
Fernando Fernandez Mancera (2):
netfilter: nfnetlink_osf: fix out-of-bounds read on option matching
netfilter: nfnetlink_osf: fix potential NULL dereference in ttl check
Florian Westphal (1):
netfilter: conntrack: remove sprintf usage
Pablo Neira Ayuso (3):
netfilter: nft_osf: restrict it to ipv4
netfilter: xtables: restrict several matches to inet family
netfilter: nat: use kfree_rcu to release ops
Xiang Mei (1):
netfilter: nfnetlink_osf: fix divide-by-zero in OSF_WSS_MODULO
Yingnan Zhang (1):
ipvs: fix MTU check for GSO packets in tunnel mode
net/ipv4/netfilter/iptable_nat.c | 4 ++-- net/ipv6/netfilter/ip6table_nat.c | 4 ++-- net/netfilter/ipvs/ip_vs_xmit.c | 19 +++++++++++++---- net/netfilter/nf_nat_amanda.c | 2 +- net/netfilter/nf_nat_core.c | 10 +++++---- net/netfilter/nf_nat_sip.c | 33 +++++++++++++++------------- net/netfilter/nfnetlink_osf.c | 45 +++++++++++++++++---------------------- net/netfilter/nft_osf.c | 6 +++++- net/netfilter/xt_mac.c | 34 +++++++++++++++++++---------- net/netfilter/xt_owner.c | 37 +++++++++++++++++++++----------- net/netfilter/xt_physdev.c | 29 ++++++++++++++++--------- net/netfilter/xt_realm.c | 2 +- 12 files changed, 136 insertions(+), 89 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/8 netfilter: nft_osf: restrict it to ipv4
This expression only supports for ipv4, restrict it.
--- net/netfilter/nft_osf.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/netfilter/nft_osf.c +5 -1
@@ -28,6 +28,11 @@ static void nft_osf_eval(const struct nft_expr *expr, struct nft_regs *regs,struct nf_osf_data data;struct tcphdr _tcph; +if (nft_pf (pkt) !=NFPROTO_IPV4 ) { + regs->verdict.code =NFT_BREAK ; +return ; + } +if (pkt->tprot !=IPPROTO_TCP ) { regs->verdict.code =NFT_BREAK ;return ;
@@ -114,7 +119,6 @@ static int nft_osf_validate(const struct nft_ctx *ctx,switch (ctx->family) {case NFPROTO_IPV4 : -case NFPROTO_IPV6 :case NFPROTO_INET : hooks = (1 <<NF_INET_LOCAL_IN ) | (1 << NF_INET_PRE_ROUTING) |
Signature · 1 line
2.47.3
Re: [PATCH net 1/8] netfilter: nft_osf: restrict it to ipv4
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 Tue, 21 Apr 2026 00:02:08 +0200 you wrote:
This expression only supports for ipv4, restrict it.
Fixes b96af92d6eaf ("netfilter: nf_tables: implement Passive OS fingerprint module in nft_osf")Acked-by Florian Westphal <[email protected]>Reviewed-by Fernando Fernandez Mancera <[email protected]>Signed-off-by Pablo Neira Ayuso <[email protected]>[...]
Here is the summary with links:
- [net,1/8] netfilter: nft_osf: restrict it to ipv4
https://git.kernel.org/netdev/net/c/b336fdbb7103 - [net,2/8] netfilter: nfnetlink_osf: fix divide-by-zero in OSF_WSS_MODULO https://git.kernel.org/netdev/net/c/2195574dc6d9 - [net,3/8] netfilter: conntrack: remove sprintf usage https://git.kernel.org/netdev/net/c/6e7066bdb481 - [net,4/8] netfilter: xtables: restrict several matches to inet family https://git.kernel.org/netdev/net/c/b6fe26f86a16 - [net,5/8] netfilter: nat: use kfree_rcu to release ops https://git.kernel.org/netdev/net/c/6eda0d771f94 - [net,6/8] ipvs: fix MTU check for GSO packets in tunnel mode https://git.kernel.org/netdev/net/c/67bf42cae41d - [net,7/8] netfilter: nfnetlink_osf: fix out-of-bounds read on option matching https://git.kernel.org/netdev/net/c/f5ca450087c3 - [net,8/8] netfilter: nfnetlink_osf: fix potential NULL dereference in ttl check https://git.kernel.org/netdev/net/c/711987ba281f
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Pablo Neira Ayuso
maintainerPATCH 2/8 netfilter: nfnetlink_osf: fix divide-by-zero in OSF_WSS_MODULO
In reply to Pablo Neira AyusoFrom: Xiang Mei <[email protected]>
nf_osf_match_one() computes ctx->window % f->wss.val in the OSF_WSS_MODULO branch with no guard for f->wss.val == 0. A CAP_NET_ADMIN user can add such a fingerprint via nfnetlink; a subsequent matching TCP SYN divides by zero and panics the kernel.
Reject the bogus fingerprint in nfnl_osf_add_callback() above the per-option for-loop. f->wss is per-fingerprint, not per-option, so the check must run regardless of f->opt_num (including 0). Also reject wss.wc >= OSF_WSS_MAX; nf_osf_match_one() already treats that as "should not happen".
Crash:
Oops: divide error: 0000 [#1] SMP KASAN NOPTI RIP: 0010:nf_osf_match_one (net/netfilter/nfnetlink_osf.c:98) Call Trace: <IRQ> nf_osf_match (net/netfilter/nfnetlink_osf.c:220) xt_osf_match_packet (net/netfilter/xt_osf.c:32) ipt_do_table (net/ipv4/netfilter/ip_tables.c:348) nf_hook_slow (net/netfilter/core.c:622) ip_local_deliver (net/ipv4/ip_input.c:265) ip_rcv (include/linux/skbuff.h:1162) __netif_receive_skb_one_core (net/core/dev.c:6181) process_backlog (net/core/dev.c:6642) __napi_poll (net/core/dev.c:7710) net_rx_action (net/core/dev.c:7945) handle_softirqs (kernel/softirq.c:622)
--- net/netfilter/nfnetlink_osf.c | 4 ++++ 1 file changed, 4 insertions(+)
net/netfilter/nfnetlink_osf.c +4 -0
@@ -320,6 +320,10 @@ static int nfnl_osf_add_callback(struct sk_buff *skb,if (f->opt_num >ARRAY_SIZE (f->opt))return -EINVAL ; +if (f->wss.wc >=OSF_WSS_MAX || + (f->wss.wc ==OSF_WSS_MODULO && f->wss.val ==0 )) +return -EINVAL ; +for (i =0 ; i < f->opt_num; i++) {if (!f->opt[i].length || f->opt[i].length >MAX_IPOPTLEN )return -EINVAL ;
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 3/8 netfilter: conntrack: remove sprintf usage
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Replace it with scnprintf, the buffer sizes are expected to be large enough to hold the result, no need for snprintf+overflow check.
Increase buffer size in mangle_content_len() while at it.
BUG: KASAN: stack-out-of-bounds in vsnprintf+0xea5/0x1270 Write of size 1 at addr [..] vsnprintf+0xea5/0x1270 sprintf+0xb1/0xe0 mangle_content_len+0x1ac/0x280 nf_nat_sdp_session+0x1cc/0x240 process_sdp+0x8f8/0xb80 process_invite_request+0x108/0x2b0 process_sip_msg+0x5da/0xf50 sip_help_tcp+0x45e/0x780 nf_confirm+0x34d/0x990 [..]
--- net/netfilter/nf_nat_amanda.c | 2 +- net/netfilter/nf_nat_sip.c | 33 ++++++++++++++++++--------------- 2 files changed, 19 insertions(+), 16 deletions(-)
net/netfilter/nf_nat_amanda.c +1 -1
@@ -50,7 +50,7 @@ static unsigned int help(struct sk_buff *skb,return NF_DROP ; } -sprintf (buffer,"%u" , port); +snprintf (buffer,sizeof (buffer),"%u" , port);if (!nf_nat_mangle_udp_packet (skb, exp->master, ctinfo, protoff, matchoff, matchlen, buffer,strlen (buffer))) {
net/netfilter/nf_nat_sip.c +18 -15
@@ -68,25 +68,27 @@ static unsigned int mangle_packet(struct sk_buff *skb, unsigned int protoff, }static int sip_sprintf_addr (const struct nf_conn *ct,char *buffer, +size_t size,const union nf_inet_addr *addr,bool delim) {if (nf_ct_l3num (ct) ==NFPROTO_IPV4 ) -return sprintf (buffer,"%pI4" , &addr->ip); +return scnprintf (buffer, size,"%pI4" , &addr->ip);else {if (delim) -return sprintf (buffer,"[%pI6c]" , &addr->ip6); +return scnprintf (buffer, size,"[%pI6c]" , &addr->ip6);else -return sprintf (buffer,"%pI6c" , &addr->ip6); +return scnprintf (buffer, size,"%pI6c" , &addr->ip6); } }static int sip_sprintf_addr_port (const struct nf_conn *ct,char *buffer, +size_t size,const union nf_inet_addr *addr,u16 port) {if (nf_ct_l3num (ct) ==NFPROTO_IPV4 ) -return sprintf (buffer,"%pI4:%u" , &addr->ip, port); +return scnprintf (buffer, size,"%pI4:%u" , &addr->ip, port);else -return sprintf (buffer,"[%pI6c]:%u" , &addr->ip6, port); +return scnprintf (buffer, size,"[%pI6c]:%u" , &addr->ip6, port); } static int map_addr(struct sk_buff *skb, unsigned int protoff,
@@ -119,7 +121,7 @@ static int map_addr(struct sk_buff *skb, unsigned int protoff,if (nf_inet_addr_cmp (&newaddr, addr) && newport == port)return 1 ; - buflen =sip_sprintf_addr_port (ct, buffer, &newaddr,ntohs (newport)); + buflen =sip_sprintf_addr_port (ct, buffer,sizeof (buffer), &newaddr,ntohs (newport));return mangle_packet (skb, protoff, dataoff, dptr, datalen, matchoff, matchlen, buffer, buflen); }
@@ -212,7 +214,7 @@ static unsigned int nf_nat_sip(struct sk_buff *skb, unsigned int protoff, &addr, true) > 0 && nf_inet_addr_cmp(&addr, &ct->tuplehash[dir].tuple.src.u3) && !nf_inet_addr_cmp(&addr, &ct->tuplehash[!dir].tuple.dst.u3)) { - buflen = sip_sprintf_addr(ct, buffer, + buflen = sip_sprintf_addr(ct, buffer, sizeof(buffer), &ct->tuplehash[!dir].tuple.dst.u3, true); if (!mangle_packet(skb, protoff, dataoff, dptr, datalen,
@@ -229,7 +231,7 @@ static unsigned int nf_nat_sip(struct sk_buff *skb, unsigned int protoff, &addr, false) > 0 && nf_inet_addr_cmp(&addr, &ct->tuplehash[dir].tuple.dst.u3) && !nf_inet_addr_cmp(&addr, &ct->tuplehash[!dir].tuple.src.u3)) { - buflen = sip_sprintf_addr(ct, buffer, + buflen = sip_sprintf_addr(ct, buffer, sizeof(buffer), &ct->tuplehash[!dir].tuple.src.u3, false); if (!mangle_packet(skb, protoff, dataoff, dptr, datalen,
@@ -247,7 +249,7 @@ static unsigned int nf_nat_sip(struct sk_buff *skb, unsigned int protoff, htons(n) == ct->tuplehash[dir].tuple.dst.u.udp.port && htons(n) != ct->tuplehash[!dir].tuple.src.u.udp.port) {__be16 p = ct->tuplehash[!dir].tuple.src.u.udp.port; - buflen =sprintf (buffer,"%u" ,ntohs (p)); + buflen =scnprintf (buffer,sizeof (buffer),"%u" ,ntohs (p));if (!mangle_packet (skb, protoff, dataoff, dptr, datalen, poff, plen, buffer, buflen)) {nf_ct_helper_log (skb, ct,"cannot mangle rport" );
@@ -418,7 +420,8 @@ static unsigned int nf_nat_sip_expect(struct sk_buff *skb, unsigned int protoff,if (!nf_inet_addr_cmp (&exp->tuple.dst.u3, &exp->saved_addr) || exp->tuple.dst.u.udp.port != exp->saved_proto.udp.port) { - buflen =sip_sprintf_addr_port (ct, buffer, &newaddr, port); + buflen =sip_sprintf_addr_port (ct, buffer,sizeof (buffer), + &newaddr, port);if (!mangle_packet (skb, protoff, dataoff, dptr, datalen, matchoff, matchlen, buffer, buflen)) {nf_ct_helper_log (skb, ct,"cannot mangle packet" );
@@ -438,8 +441,8 @@ static int mangle_content_len(struct sk_buff *skb, unsigned int protoff, {enum ip_conntrack_info ctinfo;struct nf_conn *ct =nf_ct_get (skb, &ctinfo); +char buffer[sizeof ("4294967295" )];unsigned int matchoff, matchlen; -char buffer[sizeof ("65536" )];int buflen, c_len;/* Get actual SDP length */
@@ -454,7 +457,7 @@ static int mangle_content_len(struct sk_buff *skb, unsigned int protoff, &matchoff, &matchlen) <= 0)return 0 ; - buflen =sprintf (buffer,"%u" , c_len); + buflen =scnprintf (buffer,sizeof (buffer),"%u" , c_len);return mangle_packet (skb, protoff, dataoff, dptr, datalen, matchoff, matchlen, buffer, buflen); }
@@ -491,7 +494,7 @@ static unsigned int nf_nat_sdp_addr(struct sk_buff *skb, unsigned int protoff,char buffer[INET6_ADDRSTRLEN ];unsigned int buflen; - buflen =sip_sprintf_addr (ct, buffer, addr, false); + buflen =sip_sprintf_addr (ct, buffer,sizeof (buffer), addr, false);if (mangle_sdp_packet (skb, protoff, dataoff, dptr, datalen, sdpoff, type, term, buffer, buflen))return 0 ;
@@ -509,7 +512,7 @@ static unsigned int nf_nat_sdp_port(struct sk_buff *skb, unsigned int protoff,char buffer[sizeof ("nnnnn" )];unsigned int buflen; - buflen =sprintf (buffer,"%u" , port); + buflen =scnprintf (buffer,sizeof (buffer),"%u" , port);if (!mangle_packet (skb, protoff, dataoff, dptr, datalen, matchoff, matchlen, buffer, buflen))return 0 ;
@@ -529,7 +532,7 @@ static unsigned int nf_nat_sdp_session(struct sk_buff *skb, unsigned int protoffunsigned int buflen;/* Mangle session description owner and contact addresses */ - buflen =sip_sprintf_addr (ct, buffer, addr, false); + buflen =sip_sprintf_addr (ct, buffer,sizeof (buffer), addr, false);if (mangle_sdp_packet (skb, protoff, dataoff, dptr, datalen, sdpoff,SDP_HDR_OWNER ,SDP_HDR_MEDIA , buffer, buflen))return 0 ;
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 4/8 netfilter: xtables: restrict several matches to inet family
In reply to Pablo Neira AyusoThis is a partial revert of:
commit ab4f21e6fb1c ("netfilter: xtables: use NFPROTO_UNSPEC in more extensions")
to allow ipv4 and ipv6 only.
- xt_mac
- xt_owner
- xt_physdev
These extensions are not used by ebtables in userspace.
Moreover, xt_realm is only for ipv4, since dst->tclassid is ipv4 specific.
--- net/netfilter/xt_mac.c | 34 +++++++++++++++++++++++----------- net/netfilter/xt_owner.c | 37 +++++++++++++++++++++++++------------ net/netfilter/xt_physdev.c | 29 +++++++++++++++++++---------- net/netfilter/xt_realm.c | 2 +- 4 files changed, 68 insertions(+), 34 deletions(-)
net/netfilter/xt_mac.c +23 -11
@@ -36,25 +36,37 @@ static bool mac_mt(const struct sk_buff *skb, struct xt_action_param *par)return ret; } -static struct xt_match mac_mt_reg__read_mostly = { - .name ="mac" , - .revision =0 , - .family =NFPROTO_UNSPEC , - .match = mac_mt, - .matchsize =sizeof (struct xt_mac_info ), - .hooks = (1 <<NF_INET_PRE_ROUTING ) | (1 <<NF_INET_LOCAL_IN ) | - (1 <<NF_INET_FORWARD ), - .me =THIS_MODULE , +static struct xt_match mac_mt_reg[]__read_mostly = { + { + .name ="mac" , + .family =NFPROTO_IPV4 , + .match = mac_mt, + .matchsize =sizeof (struct xt_mac_info ), + .hooks = (1 <<NF_INET_PRE_ROUTING ) | + (1 <<NF_INET_LOCAL_IN ) | + (1 <<NF_INET_FORWARD ), + .me =THIS_MODULE , + }, + { + .name ="mac" , + .family =NFPROTO_IPV6 , + .match = mac_mt, + .matchsize =sizeof (struct xt_mac_info ), + .hooks = (1 <<NF_INET_PRE_ROUTING ) | + (1 <<NF_INET_LOCAL_IN ) | + (1 <<NF_INET_FORWARD ), + .me =THIS_MODULE , + }, };static int __init mac_mt_init (void ) { -return xt_register_match (&mac_mt_reg); +return xt_register_matches (mac_mt_reg,ARRAY_SIZE (mac_mt_reg)); } static void __exit mac_mt_exit(void) { -xt_unregister_match (&mac_mt_reg); +xt_unregister_matches (mac_mt_reg,ARRAY_SIZE (mac_mt_reg)); }module_init (mac_mt_init);
net/netfilter/xt_owner.c +25 -12
@@ -127,26 +127,39 @@ owner_mt(const struct sk_buff *skb, struct xt_action_param *par)return true; } -static struct xt_match owner_mt_reg__read_mostly = { - .name ="owner" , - .revision =1 , - .family =NFPROTO_UNSPEC , - .checkentry = owner_check, - .match = owner_mt, - .matchsize =sizeof (struct xt_owner_match_info ), - .hooks = (1 <<NF_INET_LOCAL_OUT ) | - (1 <<NF_INET_POST_ROUTING ), - .me =THIS_MODULE , +static struct xt_match owner_mt_reg[]__read_mostly = { + { + .name ="owner" , + .revision =1 , + .family =NFPROTO_IPV4 , + .checkentry = owner_check, + .match = owner_mt, + .matchsize =sizeof (struct xt_owner_match_info ), + .hooks = (1 <<NF_INET_LOCAL_OUT ) | + (1 <<NF_INET_POST_ROUTING ), + .me =THIS_MODULE , + }, + { + .name ="owner" , + .revision =1 , + .family =NFPROTO_IPV6 , + .checkentry = owner_check, + .match = owner_mt, + .matchsize =sizeof (struct xt_owner_match_info ), + .hooks = (1 <<NF_INET_LOCAL_OUT ) | + (1 <<NF_INET_POST_ROUTING ), + .me =THIS_MODULE , + } };static int __init owner_mt_init (void ) { -return xt_register_match (&owner_mt_reg); +return xt_register_matches (owner_mt_reg,ARRAY_SIZE (owner_mt_reg)); } static void __exit owner_mt_exit(void) { -xt_unregister_match (&owner_mt_reg); +xt_unregister_matches (owner_mt_reg,ARRAY_SIZE (owner_mt_reg)); }module_init (owner_mt_init);
net/netfilter/xt_physdev.c +19 -10
@@ -137,24 +137,33 @@ static int physdev_mt_check(const struct xt_mtchk_param *par)return 0 ; } -static struct xt_match physdev_mt_reg__read_mostly = { - .name ="physdev" , - .revision =0 , - .family =NFPROTO_UNSPEC , - .checkentry = physdev_mt_check, - .match = physdev_mt, - .matchsize =sizeof (struct xt_physdev_info ), - .me =THIS_MODULE , +static struct xt_match physdev_mt_reg[]__read_mostly = { + { + .name ="physdev" , + .family =NFPROTO_IPV4 , + .checkentry = physdev_mt_check, + .match = physdev_mt, + .matchsize =sizeof (struct xt_physdev_info ), + .me =THIS_MODULE , + }, + { + .name ="physdev" , + .family =NFPROTO_IPV6 , + .checkentry = physdev_mt_check, + .match = physdev_mt, + .matchsize =sizeof (struct xt_physdev_info ), + .me =THIS_MODULE , + }, };static int __init physdev_mt_init (void ) { -return xt_register_match (&physdev_mt_reg); +return xt_register_matches (physdev_mt_reg,ARRAY_SIZE (physdev_mt_reg)); } static void __exit physdev_mt_exit(void) { -xt_unregister_match (&physdev_mt_reg); +xt_unregister_matches (physdev_mt_reg,ARRAY_SIZE (physdev_mt_reg)); }module_init (physdev_mt_init);
net/netfilter/xt_realm.c +1 -1
@@ -33,7 +33,7 @@ static struct xt_match realm_mt_reg __read_mostly = { .matchsize = sizeof(struct xt_realm_info), .hooks = (1 <<NF_INET_POST_ROUTING ) | (1 <<NF_INET_FORWARD ) | (1 << NF_INET_LOCAL_OUT) | (1 << NF_INET_LOCAL_IN), - .family = NFPROTO_UNSPEC, + .family = NFPROTO_IPV4, .me =THIS_MODULE };
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 5/8 netfilter: nat: use kfree_rcu to release ops
In reply to Pablo Neira AyusoFlorian Westphal says:
"Historically this is not an issue, even for normal base hooks: the data path doesn't use the original nf_hook_ops that are used to register the callbacks.
However, in v5.14 I added the ability to dump the active netfilter hooks from userspace.
This code will peek back into the nf_hook_ops that are available at the tail of the pointer-array blob used by the datapath.
The nat hooks are special, because they are called indirectly from the central nat dispatcher hook. They are currently invisible to the nfnl hook dump subsystem though.
But once that changes the nat ops structures have to be deferred too."
Update nf_nat_register_fn() to deal with partial exposition of the hooks from error path which can be also an issue for nfnetlink_hook.
--- net/ipv4/netfilter/iptable_nat.c | 4 ++-- net/ipv6/netfilter/ip6table_nat.c | 4 ++-- net/netfilter/nf_nat_core.c | 10 ++++++---- 3 files changed, 10 insertions(+), 8 deletions(-)
net/ipv4/netfilter/iptable_nat.c +2 -2
@@ -79,7 +79,7 @@ static int ipt_nat_register_lookups(struct net *net)while (i)nf_nat_ipv4_unregister_fn (net, &ops[--i]); -kfree (ops); +kfree_rcu (ops, rcu);return ret; } }
@@ -100,7 +100,7 @@ static void ipt_nat_unregister_lookups(struct net *net)for (i =0 ; i <ARRAY_SIZE (nf_nat_ipv4_ops); i++)nf_nat_ipv4_unregister_fn (net, &ops[i]); -kfree (ops); +kfree_rcu (ops, rcu); }static int iptable_nat_table_init (struct net *net)
net/ipv6/netfilter/ip6table_nat.c +2 -2
@@ -81,7 +81,7 @@ static int ip6t_nat_register_lookups(struct net *net)while (i)nf_nat_ipv6_unregister_fn (net, &ops[--i]); -kfree (ops); +kfree_rcu (ops, rcu);return ret; } }
@@ -102,7 +102,7 @@ static void ip6t_nat_unregister_lookups(struct net *net)for (i =0 ; i <ARRAY_SIZE (nf_nat_ipv6_ops); i++)nf_nat_ipv6_unregister_fn (net, &ops[i]); -kfree (ops); +kfree_rcu (ops, rcu); }static int ip6table_nat_table_init (struct net *net)
net/netfilter/nf_nat_core.c +6 -4
@@ -1222,9 +1222,11 @@ int nf_nat_register_fn(struct net *net, u8 pf, const struct nf_hook_ops *ops, ret =nf_register_net_hooks (net, nat_ops, ops_count);if (ret <0 ) {mutex_unlock (&nf_nat_proto_mutex); -for (i =0 ; i < ops_count; i++) -kfree (nat_ops[i].priv); -kfree (nat_ops); +for (i =0 ; i < ops_count; i++) { + priv = nat_ops[i].priv; +kfree_rcu (priv, rcu_head); + } +kfree_rcu (nat_ops, rcu);return ret; }
@@ -1288,7 +1290,7 @@ void nf_nat_unregister_fn(struct net *net, u8 pf, const struct nf_hook_ops *ops, } nat_proto_net->nat_hook_ops =NULL ; -kfree (nat_ops); +kfree_rcu (nat_ops, rcu); } unlock:mutex_unlock (&nf_nat_proto_mutex);
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 6/8 ipvs: fix MTU check for GSO packets in tunnel mode
In reply to Pablo Neira AyusoFrom: Yingnan Zhang <[email protected]>
Currently, IPVS skips MTU checks for GSO packets by excluding them with the !skb_is_gso(skb) condition. This creates problems when IPVS tunnel mode encapsulates GSO packets with IPIP headers.
The issue manifests in two ways:
1. MTU violation after encapsulation:
When a GSO packet passes through IPVS tunnel mode, the original MTU check is bypassed. After adding the IPIP tunnel header, the packet size may exceed the outgoing interface MTU, leading to unexpected fragmentation at the IP layer.
2. Fragmentation with problematic IP IDs:
When net.ipv4.vs.pmtu_disc=1 and a GSO packet with multiple segments is fragmented after encapsulation, each segment gets a sequentially incremented IP ID (0, 1, 2, ...). This happens because:
a) The GSO packet bypasses MTU check and gets encapsulated
b) At __ip_finish_output, the oversized GSO packet is split into separate SKBs (one per segment), with IP IDs incrementing
c) Each SKB is then fragmented again based on the actual MTU
This sequential IP ID allocation differs from the expected behavior and can cause issues with fragment reassembly and packet tracking.
Fix this by properly validating GSO packets using skb_gso_validate_network_len(). This function correctly validates whether the GSO segments will fit within the MTU after segmentation. If validation fails, send an ICMP Fragmentation Needed message to enable proper PMTU discovery.
--- net/netfilter/ipvs/ip_vs_xmit.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
net/netfilter/ipvs/ip_vs_xmit.c +15 -4
@@ -102,6 +102,18 @@ __ip_vs_dst_check(struct ip_vs_dest *dest)return dest_dst; } +/* Based on ip_exceeds_mtu(). */ +static bool ip_vs_exceeds_mtu (const struct sk_buff *skb,unsigned int mtu) +{ +if (skb->len <= mtu) +return false; + +if (skb_is_gso (skb) &&skb_gso_validate_network_len (skb, mtu)) +return false; + +return true; +} +static inline bool __mtu_check_toobig_v6 (const struct sk_buff *skb,u32 mtu) {
@@ -111,10 +123,9 @@ __mtu_check_toobig_v6(const struct sk_buff *skb, u32 mtu)*/ if (IP6CB (skb)->frag_max_size > mtu)return true;/* largest fragment violate MTU */ - } -else if (skb->len > mtu && !skb_is_gso (skb)) { + }else if (ip_vs_exceeds_mtu (skb, mtu))return true;/* Packet size violate MTU size */ - } +return false; }
@@ -232,7 +243,7 @@ static inline bool ensure_mtu_is_adequate(struct netns_ipvs *ipvs, int skb_af,return true;if (unlikely (ip_hdr (skb)->frag_off &htons (IP_DF ) && - skb->len > mtu && !skb_is_gso (skb) && +ip_vs_exceeds_mtu (skb, mtu) && !ip_vs_iph_icmp (ipvsh))) {icmp_send (skb,ICMP_DEST_UNREACH ,ICMP_FRAG_NEEDED ,htonl (mtu));
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 7/8 netfilter: nfnetlink_osf: fix out-of-bounds read on option matching
In reply to Pablo Neira AyusoFrom: Fernando Fernandez Mancera <[email protected]>
In nf_osf_match(), the nf_osf_hdr_ctx structure is initialized once and passed by reference to nf_osf_match_one() for each fingerprint checked. During TCP option parsing, nf_osf_match_one() advances the shared ctx->optp pointer.
If a fingerprint perfectly matches, the function returns early without restoring ctx->optp to its initial state. If the user has configured NF_OSF_LOGLEVEL_ALL, the loop continues to the next fingerprint. However, because ctx->optp was not restored, the next call to nf_osf_match_one() starts parsing from the end of the options buffer. This causes subsequent matches to read garbage data and fail immediately, making it impossible to log more than one match or logging incorrect matches.
Instead of using a shared ctx->optp pointer, pass the context as a constant pointer and use a local pointer (optp) for TCP option traversal. This makes nf_osf_match_one() strictly stateless from the caller's perspective, ensuring every fingerprint check starts at the correct option offset.
--- net/netfilter/nfnetlink_osf.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)
net/netfilter/nfnetlink_osf.c +8 -11
@@ -64,9 +64,9 @@ struct nf_osf_hdr_ctx {static bool nf_osf_match_one (const struct sk_buff *skb,const struct nf_osf_user_finger *f,int ttl_check, -struct nf_osf_hdr_ctx *ctx) +const struct nf_osf_hdr_ctx *ctx) { -const __u8 *optpinit = ctx->optp; +const __u8 *optp = ctx->optp;unsigned int check_WSS =0 ;int fmatch =FMATCH_WRONG ;int foptsize, optnum;
@@ -95,17 +95,17 @@ static bool nf_osf_match_one(const struct sk_buff *skb, check_WSS = f->wss.wc;for (optnum =0 ; optnum < f->opt_num; ++optnum) { -if (f->opt[optnum].kind == *ctx->optp) { +if (f->opt[optnum].kind == *optp) {__u32 len = f->opt[optnum].length; -const __u8 *optend = ctx->optp + len; +const __u8 *optend = optp + len; fmatch =FMATCH_OK ; -switch (*ctx->optp) { +switch (*optp) {case OSFOPT_MSS : - mss = ctx->optp[3 ]; + mss = optp[3 ]; mss <<=8 ; - mss |= ctx->optp[2 ]; + mss |= optp[2 ]; mss =ntohs ((__force __be16 )mss);break ;
@@ -113,7 +113,7 @@ static bool nf_osf_match_one(const struct sk_buff *skb,break ; } - ctx->optp = optend; + optp = optend; }else fmatch =FMATCH_OPT_WRONG ;
@@ -156,9 +156,6 @@ static bool nf_osf_match_one(const struct sk_buff *skb, } } -if (fmatch !=FMATCH_OK ) - ctx->optp = optpinit; -return fmatch ==FMATCH_OK ; }
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerPATCH 8/8 netfilter: nfnetlink_osf: fix potential NULL dereference in ttl check
In reply to Pablo Neira AyusoFrom: Fernando Fernandez Mancera <[email protected]>
The nf_osf_ttl() function accessed skb->dev to perform a local interface address lookup without verifying that the device pointer was valid.
Additionally, the implementation utilized an in_dev_for_each_ifa_rcu loop to match the packet source address against local interface addresses. It assumed that packets from the same subnet should not see a decrement on the initial TTL. A packet might appear it is from the same subnet but it actually isn't especially in modern environments with containers and virtual switching.
Remove the device dereference and interface loop. Replace the logic with a switch statement that evaluates the TTL according to the ttl_check.
--- net/netfilter/nfnetlink_osf.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-)
net/netfilter/nfnetlink_osf.c +7 -15
@@ -31,26 +31,18 @@ EXPORT_SYMBOL_GPL(nf_osf_fingers);static inline int nf_osf_ttl (const struct sk_buff *skb,int ttl_check,unsigned char f_ttl) { -struct in_device *in_dev =__in_dev_get_rcu (skb->dev);const struct iphdr *ip =ip_hdr (skb); -const struct in_ifaddr *ifa; -int ret =0 ; -if (ttl_check ==NF_OSF_TTL_TRUE ) +switch (ttl_check) { +case NF_OSF_TTL_TRUE :return ip->ttl == f_ttl; -if (ttl_check ==NF_OSF_TTL_NOCHECK ) -return 1 ; -else if (ip->ttl <= f_ttl) +break ; +case NF_OSF_TTL_NOCHECK :return 1 ; - -in_dev_for_each_ifa_rcu (ifa, in_dev) { -if (inet_ifa_match (ip->saddr, ifa)) { - ret = (ip->ttl == f_ttl); -break ; - } +case NF_OSF_TTL_LESS : +default : +return ip->ttl <= f_ttl; } - -return ret; }struct nf_osf_hdr_ctx {
Signature · 1 line
2.47.3