FAILED: patch "[PATCH] net: advertise TCP MSS from the configured MTU, not the" failed to apply to 5.10-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x 2640e64195948a601430d230c9864f5426574cde
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026083120-unmoral-bovine-2668@gregkh' --subject-prefix 'PATCH 5.10.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 2640e64195948a601430d230c9864f5426574cde Mon Sep 17 00:00:00 2001
From: Jiayuan Chen <[email protected]>
Date: Sat, 15 Aug 2026 15:03:36 +0800
Subject: [PATCH] net: advertise TCP MSS from the configured MTU, not the
learned PMTU
The MSS a host puts in its SYN tells the peer how big a segment it may send us. Right now we can shrink it with a PMTU we learned on our own send path, which is the wrong direction entirely.
On asymmetric paths this bites - think DSR load balancers, where the request side goes through a smaller-MTU overlay. We learn a small PMTU going out, then advertise a small MSS, and the peer stays capped for the whole connection even though its path back to us is wide. MSS only shows up in the SYN and never grows back.
On symmetric paths we lose nothing by dropping it either: the peer runs its own PMTU discovery and usually already knows the real path MTU.
So work out the advertised MSS from the configured route or device MTU and ignore the learned PMTU. Our send side is unchanged, still clamped by tcp_current_mss(). Add ip_dst_mtu_configured()/ip6_dst_mtu_configured() and use them from the two default_advmss() paths.
include/net/ip.h +25 -0
@@ -506,6 +506,31 @@ static inline unsigned int ip_dst_mtu_maybe_forward(const struct dst_entry *dst,return res; } +/* Configured/administrative MTU of a route, for advertising the TCP MSS. +* +* Unlike ip_dst_mtu_maybe_forward(), this deliberately ignores the +* ICMP-learned path MTU (rt->rt_pmtu). The advertised MSS bounds what the +* peer may send to us and must reflect our receive capability (the device or +* route-configured MTU), not a path MTU learned on the reverse (send) +* direction, which may not apply to the peer->us path and outlives the fnhe +* for the whole connection. See RFC 2923 section 2.3 and the comment above +* tcp_advertise_mss(). +*/ +static inline unsigned int ip_dst_mtu_configured (const struct dst_entry *dst) +{ +unsigned int mtu, res; + +rcu_read_lock (); + mtu =dst_metric_raw (dst,RTAX_MTU ); +if (!mtu) + mtu =READ_ONCE (dst_dev_rcu (dst)->mtu); + mtu = min_t(unsigned int, mtu, IP_MAX_MTU); + res = mtu -lwtunnel_headroom (dst->lwtstate, mtu); +rcu_read_unlock (); + +return res; +} +static inline unsigned int ip_skb_dst_mtu (struct sock *sk,const struct sk_buff *skb) {
include/net/ip6_route.h +37 -0
@@ -387,6 +387,43 @@ static inline unsigned int ip6_dst_mtu_maybe_forward(const struct dst_entry *dstreturn mtu -lwtunnel_headroom (dst->lwtstate, mtu); } +/* Configured/administrative MTU of a route, for advertising the TCP MSS. +* +* Unlike ip6_dst_mtu_maybe_forward(), this ignores any ICMPv6-learned path +* MTU (which is kept on the RTF_CACHE exception route) and returns the MTU of +* the underlying route (fib6_pmtu) or the egress device. The advertised MSS +* bounds what the peer may send to us and must reflect our receive +* capability, not a path MTU learned on the reverse (send) direction. See +* RFC 2923 section 2.3 and the comment above tcp_advertise_mss(). +*/ +static inline unsigned int ip6_dst_mtu_configured (const struct dst_entry *dst) +{ +const struct rt6_info *rt =dst_rt6_info (dst); +const struct fib6_info *from; +struct inet6_dev *idev; +unsigned int mtu =0 ; + +rcu_read_lock (); +/* IPv6 keeps the learned PMTU and the configured MTU in the same +* RTAX_MTU slot: the learned value sits on this (possibly RTF_CACHE) +* dst, the configured one on the underlying route. Reach the latter +* via ->from (fib6_pmtu), populated by ip6_route_info_create(). +*/ + from =rcu_dereference (rt->from); +if (from) + mtu = from->fib6_pmtu; +if (!mtu) { + mtu =IPV6_MIN_MTU ; + idev =__in6_dev_get (dst_dev_rcu (dst)); +if (idev) + mtu = max_t(unsigned int, mtu, READ_ONCE(idev->cnf.mtu6)); + } +rcu_read_unlock (); + + mtu = min_t(unsigned int, mtu, IP6_MAX_MTU); +return mtu -lwtunnel_headroom (dst->lwtstate, mtu); +} +u32 ip6_mtu_from_fib6 (const struct fib6_result *res,const struct in6_addr *daddr,const struct in6_addr *saddr);
net/ipv4/route.c +2 -2
@@ -1363,8 +1363,8 @@ static unsigned int ipv4_default_advmss(const struct dst_entry *dst)rcu_read_lock (); net =dst_dev_net_rcu (dst); - advmss = max_t(unsigned int, ipv4_mtu(dst) - header_size, - net->ipv4.ip_rt_min_advmss); + advmss = max_t(unsigned int, ip_dst_mtu_configured(dst) - header_size, + net->ipv4.ip_rt_min_advmss);rcu_read_unlock ();return min (advmss,IPV4_MAX_PMTU - header_size);
net/ipv6/route.c +1 -1
@@ -3261,7 +3261,7 @@ void ip6_sk_redirect(struct sk_buff *skb, struct sock *sk)static unsigned int ip6_default_advmss (const struct dst_entry *dst) { -unsigned int mtu =dst6_mtu (dst); +unsigned int mtu =ip6_dst_mtu_configured (dst);struct net *net; mtu -=sizeof (struct ipv6hdr ) +sizeof (struct tcphdr );
Sasha Levin
maintainerPATCH 1/5 net: Add locking to protect skb->dev access in ip_output
From: Sharath Chandra Vurukala <[email protected]>
[ Upstream commit 1dbf1d590d10a6d1978e8184f8dfe20af22d680a ]
In ip_output() skb->dev is updated from the skb_dst(skb)->dev this can become invalid when the interface is unregistered and freed,
Introduced new skb_dst_dev_rcu() function to be used instead of skb_dst_dev() within rcu_locks in ip_output.This will ensure that all the skb's associated with the dev being deregistered will be transnmitted out first, before freeing the dev.
Given that ip_output() is called within an rcu_read_lock() critical section or from a bottom-half context, it is safe to introduce an RCU read-side critical section within it.
Multiple panic call stacks were observed when UL traffic was run in concurrency with device deregistration from different functions, pasting one sample for reference.
[496733.627565][T13385] Call trace: [496733.627570][T13385] bpf_prog_ce7c9180c3b128ea_cgroupskb_egres+0x24c/0x7f0 [496733.627581][T13385] __cgroup_bpf_run_filter_skb+0x128/0x498 [496733.627595][T13385] ip_finish_output+0xa4/0xf4 [496733.627605][T13385] ip_output+0x100/0x1a0 [496733.627613][T13385] ip_send_skb+0x68/0x100 [496733.627618][T13385] udp_send_skb+0x1c4/0x384 [496733.627625][T13385] udp_sendmsg+0x7b0/0x898 [496733.627631][T13385] inet_sendmsg+0x5c/0x7c [496733.627639][T13385] __sys_sendto+0x174/0x1e4 [496733.627647][T13385] __arm64_sys_sendto+0x28/0x3c [496733.627653][T13385] invoke_syscall+0x58/0x11c [496733.627662][T13385] el0_svc_common+0x88/0xf4 [496733.627669][T13385] do_el0_svc+0x2c/0xb0 [496733.627676][T13385] el0_svc+0x2c/0xa4 [496733.627683][T13385] el0t_64_sync_handler+0x68/0xb4 [496733.627689][T13385] el0t_64_sync+0x1a4/0x1a8
Changes in v3:
- Replaced WARN_ON() with WARN_ON_ONCE(), as suggested by Willem de Bruijn.
- Dropped legacy lines mistakenly pulled in from an outdated branch.
Changes in v2:
- Addressed review comments from Eric Dumazet
- Used READ_ONCE() to prevent potential load/store tearing
- Added skb_dst_dev_rcu() and used along with rcu_read_lock() in ip_output
Stable-dep-of: 2640e6419594 ("net: advertise TCP MSS from the configured MTU, not the learned PMTU")
--- include/net/dst.h | 12 ++++++++++++ net/ipv4/ip_output.c | 16 +++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-)
include/net/dst.h +12 -0
@@ -547,6 +547,18 @@ static inline void skb_dst_update_pmtu_no_confirm(struct sk_buff *skb, u32 mtu) dst->ops->update_pmtu (dst,NULL , skb, mtu, false); } +static inline struct net_device *dst_dev_rcu (const struct dst_entry *dst) +{ +/* In the future, use rcu_dereference(dst->dev) */ +WARN_ON_ONCE (!rcu_read_lock_held ()); +return READ_ONCE (dst->dev); +} + +static inline struct net_device *skb_dst_dev_rcu (const struct sk_buff *skb) +{ +return dst_dev_rcu (skb_dst (skb)); +} +struct dst_entry *dst_blackhole_check (struct dst_entry *dst,u32 cookie);void dst_blackhole_update_pmtu (struct dst_entry *dst,struct sock *sk,struct sk_buff *skb,u32 mtu,bool confirm_neigh);
net/ipv4/ip_output.c +11 -5
@@ -429,17 +429,23 @@ int ip_mc_output(struct net *net, struct sock *sk, struct sk_buff *skb)int ip_output (struct net *net,struct sock *sk,struct sk_buff *skb) { -struct net_device *dev =skb_dst (skb)->dev, *indev = skb->dev; +struct net_device *dev, *indev = skb->dev; +int ret_val; + +rcu_read_lock (); + dev =skb_dst_dev_rcu (skb);IP_UPD_PO_STATS (net,IPSTATS_MIB_OUT , skb->len); skb->dev = dev; skb->protocol =htons (ETH_P_IP ); -return NF_HOOK_COND (NFPROTO_IPV4 ,NF_INET_POST_ROUTING , - net, sk, skb, indev, dev, - ip_finish_output, - !(IPCB (skb)->flags &IPSKB_REROUTED )); + ret_val =NF_HOOK_COND (NFPROTO_IPV4 ,NF_INET_POST_ROUTING , + net, sk, skb, indev, dev, + ip_finish_output, + !(IPCB (skb)->flags &IPSKB_REROUTED )); +rcu_read_unlock (); +return ret_val; }EXPORT_SYMBOL (ip_output);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/5 net: dst: introduce dst->dev_rcu
From: Eric Dumazet <[email protected]>
[ Upstream commit caedcc5b6df1b2e2b5f39079e3369c1d4d5c5f50 ]
Followup of commit 88fe14253e18 ("net: dst: add four helpers to annotate data-races around dst->dev").
We want to gradually add explicit RCU protection to dst->dev, including lockdep support.
Add an union to alias dst->dev_rcu and dst->dev.
Add dst_dev_net_rcu() helper.
Stable-dep-of: 2640e6419594 ("net: advertise TCP MSS from the configured MTU, not the learned PMTU")
--- include/net/dst.h | 11 +++++++---- include/net/ip6_route.h | 2 ++ include/net/netns/ipv4.h | 1 + net/core/dst.c | 2 +- net/ipv4/route.c | 15 +++++++++++---- net/ipv6/route.c | 9 ++++----- 6 files changed, 26 insertions(+), 14 deletions(-)
include/net/dst.h +7 -4
@@ -23,7 +23,10 @@struct sk_buff ;struct dst_entry { -struct net_device *dev; +union { +struct net_device *dev; +struct net_device __rcu *dev_rcu; + };struct dst_ops *ops;unsigned long _metrics;unsigned long expires;
@@ -549,11 +552,11 @@ static inline void skb_dst_update_pmtu_no_confirm(struct sk_buff *skb, u32 mtu)static inline struct net_device *dst_dev_rcu (const struct dst_entry *dst) { -/* In the future, use rcu_dereference(dst->dev) */ -WARN_ON_ONCE (!rcu_read_lock_held ()); -return READ_ONCE (dst->dev); +return rcu_dereference (dst->dev_rcu); } +#define dst_dev_net_rcu (dst) dev_net_rcu(dst_dev_rcu(dst)) +static inline struct net_device *skb_dst_dev_rcu (const struct sk_buff *skb) {return dst_dev_rcu (skb_dst (skb));
include/net/ip6_route.h +2 -0
@@ -262,6 +262,8 @@ static inline bool ipv6_anycast_destination(const struct dst_entry *dst,int ip6_fragment (struct net *net,struct sock *sk,struct sk_buff *skb,int (*output)(struct net *,struct sock *,struct sk_buff *)); +#define dst6_mtu (dst) dst_mtu(dst) +static inline unsigned int ip6_skb_dst_mtu (struct sk_buff *skb) {unsigned int mtu;
include/net/netns/ipv4.h +1 -0
@@ -69,6 +69,7 @@ struct netns_ipv4 {struct sock *__percpu *icmp_sk;struct sock *mc_autojoin_sk; +int ip_rt_min_advmss;struct inet_peer_base *peers;struct fqdir *fqdir;
net/core/dst.c +1 -1
@@ -151,7 +151,7 @@ void dst_dev_put(struct dst_entry *dst) dst->ops->ifdown (dst, dev, true); dst->input = dst_discard; dst->output = dst_discard_out; - dst->dev = blackhole_netdev; +rcu_assign_pointer (dst->dev_rcu, blackhole_netdev);dev_hold (dst->dev);dev_put (dev); }
net/ipv4/route.c +11 -4
@@ -126,7 +126,7 @@ static int ip_rt_error_cost __read_mostly = HZ;static int ip_rt_error_burst__read_mostly =5 *HZ ;static int ip_rt_mtu_expires__read_mostly =10 *60 *HZ ;static u32 ip_rt_min_pmtu__read_mostly =512 +20 +20 ; -static int ip_rt_min_advmss__read_mostly =256 ; +#define DEFAULT_MIN_ADVMSS 256static int ip_rt_gc_timeout__read_mostly =RT_GC_TIMEOUT ;
@@ -1377,8 +1377,14 @@ static void set_class_tag(struct rtable *rt, u32 tag)static unsigned int ipv4_default_advmss (const struct dst_entry *dst) {unsigned int header_size =sizeof (struct tcphdr ) +sizeof (struct iphdr ); - unsigned int advmss = max_t(unsigned int, ipv4_mtu(dst) - header_size, - ip_rt_min_advmss); +unsigned int advmss; +struct net *net; + +rcu_read_lock (); + net =dst_dev_net_rcu (dst); + advmss = max_t(unsigned int, ipv4_mtu(dst) - header_size, + net->ipv4.ip_rt_min_advmss); +rcu_read_unlock ();return min (advmss,IPV4_MAX_PMTU - header_size); }
@@ -3490,7 +3496,7 @@ static struct ctl_table ipv4_route_table[] = { }, { .procname = "min_adv_mss", - .data = &ip_rt_min_advmss, + .data = &init_net.ipv4.ip_rt_min_advmss, .maxlen = sizeof(int), .mode = 0644, .proc_handler = proc_dointvec,
@@ -3558,6 +3564,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {static __net_init int rt_genid_init (struct net *net) { + net->ipv4.ip_rt_min_advmss =DEFAULT_MIN_ADVMSS ;atomic_set (&net->ipv4.rt_genid,0 );atomic_set (&net->fnhe_genid,0 );atomic_set (&net->ipv4.dev_addr_genid,get_random_int ());
net/ipv6/route.c +4 -5
@@ -3055,17 +3055,16 @@ EXPORT_SYMBOL_GPL(ip6_sk_redirect);static unsigned int ip6_default_advmss (const struct dst_entry *dst) { -struct net_device *dev = dst->dev; -unsigned int mtu =dst_mtu (dst); +unsigned int mtu =dst6_mtu (dst);struct net *net; mtu -=sizeof (struct ipv6hdr ) +sizeof (struct tcphdr );rcu_read_lock (); - net =dev_net_rcu (dev); -if (mtu < net->ipv6.sysctl.ip6_rt_min_advmss) - mtu = net->ipv6.sysctl.ip6_rt_min_advmss; + net =dst_dev_net_rcu (dst); + mtu = max_t(unsigned int, mtu, +READ_ONCE (net->ipv6.sysctl.ip6_rt_min_advmss));rcu_read_unlock ();
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/5 ipv6: pass proto by value to ipv6_push_nfrag_opts() and ipv6_push_frag_opts()
In reply to Sasha LevinFrom: Eric Dumazet <[email protected]>
[ Upstream commit 1bc46dd209667346c5aa56c351995e7c260696d0 ]
With CONFIG_STACKPROTECTOR_STRONG=y, it is better to avoid passing a pointer to an automatic variable.
Change these exported functions to return 'u8 proto' instead of void.
- ipv6_push_nfrag_opts()
- ipv6_push_frag_opts()
For instance, replace
ipv6_push_frag_opts(skb, opt, &proto); with: proto = ipv6_push_frag_opts(skb, opt, proto);
Note that even after this change, ip6_xmit() has to use a stack canary because of @first_hop variable.
[ stable backport note: Retain the older final_dst buffer in __ip6_make_skb(), since b60d4e58c615 ("ipv6: remove daddr temp buffer in __ip6_make_skb") is not present. Also make the existing ip_dst_mtu_maybe_forward() RCU-safe so the follow-up MSS fix has its expected insertion context. ]
Stable-dep-of: 2640e6419594 ("net: advertise TCP MSS from the configured MTU, not the learned PMTU")
--- include/net/ip.h | 24 ++++++++++++++----- include/net/ipv6.h | 10 ++++---- net/ipv6/exthdrs.c | 55 +++++++++++++++++++++++-------------------- net/ipv6/ip6_output.c | 13 +++++----- net/ipv6/ip6_tunnel.c | 2 +- 5 files changed, 60 insertions(+), 44 deletions(-)
include/net/ip.h +18 -6
@@ -440,20 +440,32 @@ static inline bool ip_sk_ignore_df(const struct sock *sk)static inline unsigned int ip_dst_mtu_maybe_forward (const struct dst_entry *dst,bool forwarding) { -struct net *net =dev_net (dst->dev); -unsigned int mtu; +const struct net_device *dev; +unsigned int mtu, res; +struct net *net; + +rcu_read_lock (); + dev =dst_dev_rcu (dst); + net =dev_net_rcu (dev);if (READ_ONCE (net->ipv4.sysctl_ip_fwd_use_pmtu) ||ip_mtu_locked (dst) || - !forwarding) -return dst_mtu (dst); + !forwarding) { + mtu =dst_mtu (dst); + goto out; + }/* 'forwarding = true' case should always honour route mtu */ mtu =dst_metric_raw (dst,RTAX_MTU );if (!mtu) - mtu =min (READ_ONCE (dst->dev->mtu),IP_MAX_MTU ); + mtu =min (READ_ONCE (dev->mtu),IP_MAX_MTU ); + +out: + res = mtu -lwtunnel_headroom (dst->lwtstate, mtu); + +rcu_read_unlock (); -return mtu -lwtunnel_headroom (dst->lwtstate, mtu); +return res; } static inline unsigned int ip_skb_dst_mtu(struct sock *sk,
include/net/ipv6.h +5 -5
@@ -1046,11 +1046,11 @@ int ip6_local_out(struct net *net, struct sock *sk, struct sk_buff *skb);* Extension header (options) processing */ -void ipv6_push_nfrag_opts (struct sk_buff *skb,struct ipv6_txoptions *opt, -u8 *proto,struct in6_addr **daddr_p, -struct in6_addr *saddr); -void ipv6_push_frag_opts (struct sk_buff *skb,struct ipv6_txoptions *opt, -u8 *proto); +u8 ipv6_push_nfrag_opts (struct sk_buff *skb,struct ipv6_txoptions *opt, +u8 proto,struct in6_addr **daddr_p, +struct in6_addr *saddr); +u8 ipv6_push_frag_opts (struct sk_buff *skb,struct ipv6_txoptions *opt, +u8 proto);int ipv6_skip_exthdr (const struct sk_buff *,int start,u8 *nexthdrp,__be16 *frag_offp);
net/ipv6/exthdrs.c +29 -26
109 lines not on this page · raw message
net/ipv6/ip6_output.c +7 -6
@@ -290,11 +290,12 @@ int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6, seg_len += opt->opt_nflen + opt->opt_flen;if (opt->opt_flen) -ipv6_push_frag_opts (skb, opt, &proto); + proto =ipv6_push_frag_opts (skb, opt, proto);if (opt->opt_nflen) -ipv6_push_nfrag_opts (skb, opt, &proto, &first_hop, - &fl6->saddr); + proto =ipv6_push_nfrag_opts (skb, opt, proto, + &first_hop, + &fl6->saddr); }skb_push (skb,sizeof (struct ipv6hdr ));
@@ -1824,10 +1825,10 @@ struct sk_buff *__ip6_make_skb(struct sock *sk, *final_dst = fl6->daddr;__skb_pull (skb,skb_network_header_len (skb));if (opt && opt->opt_flen) -ipv6_push_frag_opts (skb, opt, &proto); + proto =ipv6_push_frag_opts (skb, opt, proto);if (opt && opt->opt_nflen) -ipv6_push_nfrag_opts (skb, opt, &proto, &final_dst, &fl6->saddr); - + proto =ipv6_push_nfrag_opts (skb, opt, proto, &final_dst, + &fl6->saddr);skb_push (skb,sizeof (struct ipv6hdr ));skb_reset_network_header (skb); hdr =ipv6_hdr (skb);
net/ipv6/ip6_tunnel.c +1 -1
@@ -1293,7 +1293,7 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,if (encap_limit >=0 ) {init_tel_txopt (&opt, encap_limit); -ipv6_push_frag_opts (skb, &opt.ops, &proto); + proto =ipv6_push_frag_opts (skb, &opt.ops, proto); }skb_push (skb,sizeof (struct ipv6hdr ));
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 4/5 ipv6: use dst6_mtu() instead of dst_mtu()
In reply to Sasha LevinFrom: Eric Dumazet <[email protected]>
[ Upstream commit b40f0130a23b6bab8b359e158a40af81f11f14be ]
When we expect an IPv6 dst, use dst6_mtu() instead of dst_mtu() to save some code space.
Due to current dst6_mtu() implementation, only convert users in IPv6 stack.
Stable-dep-of: 2640e6419594 ("net: advertise TCP MSS from the configured MTU, not the learned PMTU")
--- net/ipv6/ip6_gre.c | 2 +- net/ipv6/ip6_output.c | 6 +++--- net/ipv6/ip6_tunnel.c | 4 ++-- net/ipv6/ipv6_sockglue.c | 4 ++-- net/ipv6/route.c | 8 +++++--- net/ipv6/tcp_ipv6.c | 9 +++++---- 6 files changed, 18 insertions(+), 15 deletions(-)
net/ipv6/ip6_gre.c +1 -1
@@ -1071,7 +1071,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,gre_build_header (skb,8 ,TUNNEL_SEQ , proto,0 ,htonl (atomic_fetch_inc (&t->o_seqno)));/* TooBig packet may have updated dst->dev's mtu */ -if (!t->parms.collect_md && dst &&dst_mtu (dst) > dst->dev->mtu) +if (!t->parms.collect_md && dst &&dst6_mtu (dst) > dst->dev->mtu) dst->ops->update_pmtu (dst,NULL , skb, dst->dev->mtu, false); err = ip6_tnl_xmit(skb, dev, dsfield, &fl6, encap_limit, &mtu,
net/ipv6/ip6_output.c +3 -3
@@ -324,7 +324,7 @@ int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6, skb->priority = priority; skb->mark = mark; - mtu =dst_mtu (dst); + mtu =dst6_mtu (dst);if ((skb->len <= mtu) || skb->ignore_df ||skb_is_gso (skb)) {IP6_UPD_PO_STATS (net, idev,IPSTATS_MIB_OUT , skb->len);
@@ -1353,10 +1353,10 @@ static int ip6_setup_cork(struct sock *sk, struct inet_cork_full *cork, v6_cork->tclass = ipc6->tclass;if (rt->dst.flags &DST_XFRM_TUNNEL ) mtu = np->pmtudisc >=IPV6_PMTUDISC_PROBE ? -READ_ONCE (rt->dst.dev->mtu) :dst_mtu (&rt->dst); +READ_ONCE (rt->dst.dev->mtu) :dst6_mtu (&rt->dst);else mtu = np->pmtudisc >=IPV6_PMTUDISC_PROBE ? -READ_ONCE (rt->dst.dev->mtu) :dst_mtu (xfrm_dst_path (&rt->dst)); +READ_ONCE (rt->dst.dev->mtu) :dst6_mtu (xfrm_dst_path (&rt->dst));if (np->frag_size < mtu) {if (np->frag_size) mtu = np->frag_size;
net/ipv6/ip6_tunnel.c +2 -2
@@ -674,7 +674,7 @@ ip4ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,/* change mtu on this route */ if (rel_type ==ICMP_DEST_UNREACH && rel_code ==ICMP_FRAG_NEEDED ) { -if (rel_info >dst_mtu (skb_dst (skb2))) +if (rel_info >dst6_mtu (skb_dst (skb2))) goto out;skb_dst_update_pmtu_no_confirm (skb2, rel_info);
@@ -1215,7 +1215,7 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield, t->parms.name); goto tx_err_dst_release; } - mtu =dst_mtu (dst) - eth_hlen - psh_hlen - t->tun_hlen; + mtu =dst6_mtu (dst) - eth_hlen - psh_hlen - t->tun_hlen;if (encap_limit >=0 ) { max_headroom +=8 ; mtu -=8 ;
net/ipv6/ipv6_sockglue.c +2 -2
@@ -1210,7 +1210,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,rcu_read_lock (); dst =__sk_dst_get (sk);if (dst) - val =dst_mtu (dst); + val =dst6_mtu (dst);rcu_read_unlock ();if (!val)return -ENOTCONN ;
@@ -1309,7 +1309,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,rcu_read_lock (); dst =__sk_dst_get (sk);if (dst) - mtuinfo.ip6m_mtu =dst_mtu (dst); + mtuinfo.ip6m_mtu =dst6_mtu (dst);rcu_read_unlock ();if (!mtuinfo.ip6m_mtu)return -ENOTCONN ;
net/ipv6/route.c +5 -3
@@ -1988,6 +1988,8 @@ static void rt6_update_exception_stamp_rt(struct rt6_info *rt)static bool rt6_mtu_change_route_allowed (struct inet6_dev *idev,struct rt6_info *rt,int mtu) { +u32 dmtu =dst6_mtu (&rt->dst); +/* If the new MTU is lower than the route PMTU, this new MTU will be the * lowest MTU in the path: always allow updating the route PMTU to * reflect PMTU decreases.
@@ -1998,10 +2000,10 @@ static bool rt6_mtu_change_route_allowed(struct inet6_dev *idev,* handle this. */ -if (dst_mtu (&rt->dst) >= mtu) +if (dmtu >= mtu)return true; -if (dst_mtu (&rt->dst) == idev->cnf.mtu6) +if (dmtu == idev->cnf.mtu6)return true;return false;
@@ -2739,7 +2741,7 @@ static void __ip6_rt_update_pmtu(struct dst_entry *dst, const struct sock *sk,if (mtu <IPV6_MIN_MTU )return ; -if (mtu >=dst_mtu (dst)) +if (mtu >=dst6_mtu (dst))return ;if (!rt6_cache_allowed_for_pmtu (rt6)) {
net/ipv6/tcp_ipv6.c +5 -4
@@ -354,7 +354,7 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,static void tcp_v6_mtu_reduced (struct sock *sk) {struct dst_entry *dst; -u32 mtu; +u32 mtu, dmtu;if ((1 << sk->sk_state) & (TCPF_LISTEN |TCPF_CLOSE ))return ;
@@ -371,8 +371,9 @@ static void tcp_v6_mtu_reduced(struct sock *sk)if (!dst)return ; -if (inet_csk (sk)->icsk_pmtu_cookie >dst_mtu (dst)) { -tcp_sync_mss (sk,dst_mtu (dst)); + dmtu =dst6_mtu (dst); +if (inet_csk (sk)->icsk_pmtu_cookie > dmtu) { +tcp_sync_mss (sk, dmtu);tcp_simple_retransmit (sk); } }
@@ -1377,7 +1378,7 @@ static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff *tcp_ca_openreq_child (newsk, dst); -tcp_sync_mss (newsk,dst_mtu (dst)); +tcp_sync_mss (newsk,dst6_mtu (dst)); newtp->advmss =tcp_mss_clamp (tcp_sk (sk),dst_metric_advmss (dst));tcp_initialize_rcv_mss (newsk);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 5/5 net: advertise TCP MSS from the configured MTU, not the learned PMTU
In reply to Sasha LevinFrom: Jiayuan Chen <[email protected]>
[ Upstream commit 2640e64195948a601430d230c9864f5426574cde ]
The MSS a host puts in its SYN tells the peer how big a segment it may send us. Right now we can shrink it with a PMTU we learned on our own send path, which is the wrong direction entirely.
On asymmetric paths this bites - think DSR load balancers, where the request side goes through a smaller-MTU overlay. We learn a small PMTU going out, then advertise a small MSS, and the peer stays capped for the whole connection even though its path back to us is wide. MSS only shows up in the SYN and never grows back.
On symmetric paths we lose nothing by dropping it either: the peer runs its own PMTU discovery and usually already knows the real path MTU.
So work out the advertised MSS from the configured route or device MTU and ignore the learned PMTU. Our send side is unchanged, still clamped by tcp_current_mss(). Add ip_dst_mtu_configured()/ip6_dst_mtu_configured() and use them from the two default_advmss() paths.
--- include/net/ip.h | 25 +++++++++++++++++++++++++ include/net/ip6_route.h | 37 +++++++++++++++++++++++++++++++++++++ net/ipv4/route.c | 4 ++-- net/ipv6/route.c | 2 +- 4 files changed, 65 insertions(+), 3 deletions(-)
include/net/ip.h +25 -0
@@ -468,6 +468,31 @@ static inline unsigned int ip_dst_mtu_maybe_forward(const struct dst_entry *dst,return res; } +/* Configured/administrative MTU of a route, for advertising the TCP MSS. +* +* Unlike ip_dst_mtu_maybe_forward(), this deliberately ignores the +* ICMP-learned path MTU (rt->rt_pmtu). The advertised MSS bounds what the +* peer may send to us and must reflect our receive capability (the device or +* route-configured MTU), not a path MTU learned on the reverse (send) +* direction, which may not apply to the peer->us path and outlives the fnhe +* for the whole connection. See RFC 2923 section 2.3 and the comment above +* tcp_advertise_mss(). +*/ +static inline unsigned int ip_dst_mtu_configured (const struct dst_entry *dst) +{ +unsigned int mtu, res; + +rcu_read_lock (); + mtu =dst_metric_raw (dst,RTAX_MTU ); +if (!mtu) + mtu =READ_ONCE (dst_dev_rcu (dst)->mtu); + mtu = min_t(unsigned int, mtu, IP_MAX_MTU); + res = mtu -lwtunnel_headroom (dst->lwtstate, mtu); +rcu_read_unlock (); + +return res; +} +static inline unsigned int ip_skb_dst_mtu (struct sock *sk,const struct sk_buff *skb) {
include/net/ip6_route.h +37 -0
@@ -339,6 +339,43 @@ static inline unsigned int ip6_dst_mtu_forward(const struct dst_entry *dst)return mtu -lwtunnel_headroom (dst->lwtstate, mtu); } +/* Configured/administrative MTU of a route, for advertising the TCP MSS. +* +* Unlike ip6_dst_mtu_maybe_forward(), this ignores any ICMPv6-learned path +* MTU (which is kept on the RTF_CACHE exception route) and returns the MTU of +* the underlying route (fib6_pmtu) or the egress device. The advertised MSS +* bounds what the peer may send to us and must reflect our receive +* capability, not a path MTU learned on the reverse (send) direction. See +* RFC 2923 section 2.3 and the comment above tcp_advertise_mss(). +*/ +static inline unsigned int ip6_dst_mtu_configured (const struct dst_entry *dst) +{ +const struct rt6_info *rt = (const struct rt6_info *)dst; +const struct fib6_info *from; +struct inet6_dev *idev; +unsigned int mtu =0 ; + +rcu_read_lock (); +/* IPv6 keeps the learned PMTU and the configured MTU in the same +* RTAX_MTU slot: the learned value sits on this (possibly RTF_CACHE) +* dst, the configured one on the underlying route. Reach the latter +* via ->from (fib6_pmtu), populated by ip6_route_info_create(). +*/ + from =rcu_dereference (rt->from); +if (from) + mtu = from->fib6_pmtu; +if (!mtu) { + mtu =IPV6_MIN_MTU ; + idev =__in6_dev_get (dst_dev_rcu (dst)); +if (idev) + mtu = max_t(unsigned int, mtu, READ_ONCE(idev->cnf.mtu6)); + } +rcu_read_unlock (); + + mtu = min_t(unsigned int, mtu, IP6_MAX_MTU); +return mtu -lwtunnel_headroom (dst->lwtstate, mtu); +} +u32 ip6_mtu_from_fib6 (const struct fib6_result *res,const struct in6_addr *daddr,const struct in6_addr *saddr);
net/ipv4/route.c +2 -2
@@ -1382,8 +1382,8 @@ static unsigned int ipv4_default_advmss(const struct dst_entry *dst)rcu_read_lock (); net =dst_dev_net_rcu (dst); - advmss = max_t(unsigned int, ipv4_mtu(dst) - header_size, - net->ipv4.ip_rt_min_advmss); + advmss = max_t(unsigned int, ip_dst_mtu_configured(dst) - header_size, + net->ipv4.ip_rt_min_advmss);rcu_read_unlock ();return min (advmss,IPV4_MAX_PMTU - header_size);
net/ipv6/route.c +1 -1
@@ -3057,7 +3057,7 @@ EXPORT_SYMBOL_GPL(ip6_sk_redirect);static unsigned int ip6_default_advmss (const struct dst_entry *dst) { -unsigned int mtu =dst6_mtu (dst); +unsigned int mtu =ip6_dst_mtu_configured (dst);struct net *net; mtu -=sizeof (struct ipv6hdr ) +sizeof (struct tcphdr );
Signature · 1 line
2.53.0