GSO_BY_FRAGS correctness improvements
Subsystems (6)
v2 cover GSO_BY_FRAGS correctness improvements
As requested [1], I went through and had a look at users of gso_size to see if there were things that need to be fixed to consider GSO_BY_FRAGS, and I have tried to improve our helper functions to deal with this case.
I found a few. This fixes bugs relating to the use of skb_gso_*_seglen() where GSO_BY_FRAGS is not considered.
Patch 1 renames skb_gso_validate_mtu to skb_gso_validate_network_len. This is follow-up to my earlier patch 2b16f048729b ("net: create skb_gso_validate_mac_len()"), and just makes everything a bit clearer.
Patches 2 and 3 replace the final users of skb_gso_network_seglen() - which doesn't consider GSO_BY_FRAGS - with skb_gso_validate_network_len(), which does. This allows me to make the skb_gso_*_seglen functions private in patch 4 - now future users won't accidentally do the wrong comparison.
Two things remain. One is qdisc_pkt_len_init, which is discussed at
[2] - it's caught up in the GSO_DODGY mess. I don't have any expertise in GSO_DODGY, and it looks like a good clean fix will involve unpicking the whole validation mess, so I have left it for now.
Secondly, there are 3 eBPF opcodes that change the gso_size of an SKB and don't consider GSO_BY_FRAGS. This is going through the bpf tree.
Regards,
Daniel
[1] https://patchwork.ozlabs.org/comment/1852414/
[2] https://www.spinics.net/lists/netdev/msg482397.html
PS: This is all in the core networking stack. For a driver to be affected by this it would need to support NETIF_F_GSO_SCTP / NETIF_F_GSO_SOFTWARE and then either use gso_size or not be a purely virtual device. (Many drivers look at gso_size, but do not support SCTP segmentation, so the core network will segment an SCTP gso before it hits them.) Based on that, the only driver that may be affected is sunvnet, but I have no way of testing it, so I haven't looked at it.
v2: split out bpf stuff
fix review comments from Dave Miller
Daniel Axtens (4):
net: rename skb_gso_validate_mtu -> skb_gso_validate_network_len
net: sched: tbf: handle GSO_BY_FRAGS case in enqueue
net: xfrm: use skb_gso_validate_network_len() to check gso sizes
net: make skb_gso_*_seglen functions private
include/linux/skbuff.h | 35 +----------------------- net/core/skbuff.c | 48 ++++++++++++++++++++++++++++----- net/ipv4/ip_forward.c | 2 +- net/ipv4/ip_output.c | 2 +- net/ipv4/netfilter/nf_flow_table_ipv4.c | 2 +- net/ipv4/xfrm4_output.c | 3 ++- net/ipv6/ip6_output.c | 2 +- net/ipv6/netfilter/nf_flow_table_ipv6.c | 2 +- net/ipv6/xfrm6_output.c | 2 +- net/mpls/af_mpls.c | 2 +- net/sched/sch_tbf.c | 3 ++- net/xfrm/xfrm_device.c | 2 +- 12 files changed, 54 insertions(+), 51 deletions(-)
Signature · 1 line
2.14.1
PATCH v2 1/4 net: rename skb_gso_validate_mtu -> skb_gso_validate_network_len
If you take a GSO skb, and split it into packets, will the network length (L3 headers + L4 headers + payload) of those packets be small enough to fit within a given MTU?
skb_gso_validate_mtu gives you the answer to that question. However, we recently added to add a way to validate the MAC length of a split GSO skb (L2+L3+L4+payload), and the names get confusing, so rename skb_gso_validate_mtu to skb_gso_validate_network_len
--- include/linux/skbuff.h | 2 +- net/core/skbuff.c | 11 ++++++----- net/ipv4/ip_forward.c | 2 +- net/ipv4/ip_output.c | 2 +- net/ipv4/netfilter/nf_flow_table_ipv4.c | 2 +- net/ipv6/ip6_output.c | 2 +- net/ipv6/netfilter/nf_flow_table_ipv6.c | 2 +- net/mpls/af_mpls.c | 2 +- net/xfrm/xfrm_device.c | 2 +- 9 files changed, 14 insertions(+), 13 deletions(-)
include/linux/skbuff.h +1 -1
@@ -3286,7 +3286,7 @@ void skb_split(struct sk_buff *skb, struct sk_buff *skb1, const u32 len);int skb_shift (struct sk_buff *tgt,struct sk_buff *skb,int shiftlen);void skb_scrub_packet (struct sk_buff *skb,bool xnet);unsigned int skb_gso_transport_seglen (const struct sk_buff *skb); -bool skb_gso_validate_mtu (const struct sk_buff *skb,unsigned int mtu); +bool skb_gso_validate_network_len (const struct sk_buff *skb,unsigned int mtu);bool skb_gso_validate_mac_len (const struct sk_buff *skb,unsigned int len);struct sk_buff *skb_segment (struct sk_buff *skb,netdev_features_t features);struct sk_buff *skb_vlan_untag (struct sk_buff *skb);
net/core/skbuff.c +6 -5
@@ -4955,19 +4955,20 @@ static inline bool skb_gso_size_check(const struct sk_buff *skb, }/** -* skb_gso_validate_mtu - Return in case such skb fits a given MTU +* skb_gso_validate_network_len - Will a split GSO skb fit into a given MTU? * * @skb: GSO skb * @mtu: MTU to validate against * -* skb_gso_validate_mtu validates if a given skb will fit a wanted MTU -* once split. +* skb_gso_validate_network_len validates if a given skb will fit a +* wanted MTU once split. It considers L3 headers, L4 headers, and the +* payload. */ -bool skb_gso_validate_mtu (const struct sk_buff *skb,unsigned int mtu) +bool skb_gso_validate_network_len (const struct sk_buff *skb,unsigned int mtu) {return skb_gso_size_check (skb,skb_gso_network_seglen (skb), mtu); } -EXPORT_SYMBOL_GPL (skb_gso_validate_mtu); +EXPORT_SYMBOL_GPL (skb_gso_validate_network_len);/** * skb_gso_validate_mac_len - Will a split GSO skb fit in a given length?
net/ipv4/ip_forward.c +1 -1
@@ -55,7 +55,7 @@ static bool ip_exceeds_mtu(const struct sk_buff *skb, unsigned int mtu)if (skb->ignore_df)return false; -if (skb_is_gso (skb) &&skb_gso_validate_mtu (skb, mtu)) +if (skb_is_gso (skb) &&skb_gso_validate_network_len (skb, mtu))return false;return true;
net/ipv4/ip_output.c +1 -1
@@ -248,7 +248,7 @@ static int ip_finish_output_gso(struct net *net, struct sock *sk,/* common case: seglen is <= mtu */ -if (skb_gso_validate_mtu (skb, mtu)) +if (skb_gso_validate_network_len (skb, mtu))return ip_finish_output2 (net, sk, skb);/* Slowpath - GSO segment length exceeds the egress MTU.
net/ipv4/netfilter/nf_flow_table_ipv4.c +1 -1
@@ -185,7 +185,7 @@ static bool __nf_flow_exceeds_mtu(const struct sk_buff *skb, unsigned int mtu)if ((ip_hdr (skb)->frag_off &htons (IP_DF )) ==0 )return false; -if (skb_is_gso (skb) &&skb_gso_validate_mtu (skb, mtu)) +if (skb_is_gso (skb) &&skb_gso_validate_network_len (skb, mtu))return false;return true;
net/ipv6/ip6_output.c +1 -1
@@ -412,7 +412,7 @@ static bool ip6_pkt_too_big(const struct sk_buff *skb, unsigned int mtu)if (skb->ignore_df)return false; -if (skb_is_gso (skb) &&skb_gso_validate_mtu (skb, mtu)) +if (skb_is_gso (skb) &&skb_gso_validate_network_len (skb, mtu))return false;return true;
net/ipv6/netfilter/nf_flow_table_ipv6.c +1 -1
@@ -178,7 +178,7 @@ static bool __nf_flow_exceeds_mtu(const struct sk_buff *skb, unsigned int mtu)if (skb->len <= mtu)return false; -if (skb_is_gso (skb) &&skb_gso_validate_mtu (skb, mtu)) +if (skb_is_gso (skb) &&skb_gso_validate_network_len (skb, mtu))return false;return true;
net/mpls/af_mpls.c +1 -1
@@ -122,7 +122,7 @@ bool mpls_pkt_too_big(const struct sk_buff *skb, unsigned int mtu)if (skb->len <= mtu)return false; -if (skb_is_gso (skb) &&skb_gso_validate_mtu (skb, mtu)) +if (skb_is_gso (skb) &&skb_gso_validate_network_len (skb, mtu))return false;return true;
net/xfrm/xfrm_device.c +1 -1
@@ -217,7 +217,7 @@ bool xfrm_dev_offload_ok(struct sk_buff *skb, struct xfrm_state *x)if (skb->len <= mtu) goto ok; -if (skb_is_gso (skb) &&skb_gso_validate_mtu (skb, mtu)) +if (skb_is_gso (skb) &&skb_gso_validate_network_len (skb, mtu)) goto ok; }
Signature · 1 line
2.14.1
PATCH v2 2/4 net: sched: tbf: handle GSO_BY_FRAGS case in enqueue
In reply to Daniel Axtenstbf_enqueue() checks the size of a packet before enqueuing it. However, the GSO size check does not consider the GSO_BY_FRAGS case, and so will drop GSO SCTP packets, causing a massive drop in throughput.
Use skb_gso_validate_mac_len() instead, as it does consider that case.
--- net/sched/sch_tbf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/sched/sch_tbf.c +2 -1
@@ -188,7 +188,8 @@ static int tbf_enqueue(struct sk_buff *skb, struct Qdisc *sch,int ret;if (qdisc_pkt_len (skb) > q->max_size) { -if (skb_is_gso (skb) &&skb_gso_mac_seglen (skb) <= q->max_size) +if (skb_is_gso (skb) && +skb_gso_validate_mac_len (skb, q->max_size))return tbf_segment (skb, sch, to_free);return qdisc_drop (skb, sch, to_free); }
Signature · 1 line
2.14.1
PATCH v2 3/4 net: xfrm: use skb_gso_validate_network_len() to check gso sizes
In reply to Daniel AxtensReplace skb_gso_network_seglen() with skb_gso_validate_network_len(), as it considers the GSO_BY_FRAGS case.
--- net/ipv4/xfrm4_output.c | 3 ++- net/ipv6/xfrm6_output.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)
net/ipv4/xfrm4_output.c +2 -1
@@ -30,7 +30,8 @@ static int xfrm4_tunnel_check_size(struct sk_buff *skb) mtu =dst_mtu (skb_dst (skb));if ((!skb_is_gso (skb) && skb->len > mtu) || - (skb_is_gso (skb) &&skb_gso_network_seglen (skb) >ip_skb_dst_mtu (skb->sk, skb))) { + (skb_is_gso (skb) && + !skb_gso_validate_network_len (skb,ip_skb_dst_mtu (skb->sk, skb)))) { skb->protocol =htons (ETH_P_IP );if (skb->sk)
net/ipv6/xfrm6_output.c +1 -1
@@ -82,7 +82,7 @@ static int xfrm6_tunnel_check_size(struct sk_buff *skb)if ((!skb_is_gso (skb) && skb->len > mtu) || (skb_is_gso (skb) && -skb_gso_network_seglen (skb) >ip6_skb_dst_mtu (skb))) { + !skb_gso_validate_network_len (skb,ip6_skb_dst_mtu (skb)))) { skb->dev = dst->dev; skb->protocol =htons (ETH_P_IPV6 );
Signature · 1 line
2.14.1
PATCH v2 4/4 net: make skb_gso_*_seglen functions private
In reply to Daniel AxtensThey're very hard to use properly as they do not consider the GSO_BY_FRAGS case. Code should use skb_gso_validate_network_len and skb_gso_validate_mac_len as they do consider this case.
Make the seglen functions static, which stops people using them outside of skbuff.c
---
v2: drop inline from functions.
--- include/linux/skbuff.h | 33 --------------------------------- net/core/skbuff.c | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 35 deletions(-)
include/linux/skbuff.h +0 -33
@@ -3285,7 +3285,6 @@ int skb_zerocopy(struct sk_buff *to, struct sk_buff *from,void skb_split (struct sk_buff *skb,struct sk_buff *skb1,const u32 len);int skb_shift (struct sk_buff *tgt,struct sk_buff *skb,int shiftlen);void skb_scrub_packet (struct sk_buff *skb,bool xnet); -unsigned int skb_gso_transport_seglen (const struct sk_buff *skb);bool skb_gso_validate_network_len (const struct sk_buff *skb,unsigned int mtu);bool skb_gso_validate_mac_len (const struct sk_buff *skb,unsigned int len);struct sk_buff *skb_segment (struct sk_buff *skb,netdev_features_t features);
@@ -4104,38 +4103,6 @@ static inline bool skb_head_is_locked(const struct sk_buff *skb)return !skb->head_frag ||skb_cloned (skb); } -/** -* skb_gso_network_seglen - Return length of individual segments of a gso packet -* -* @skb: GSO skb -* -* skb_gso_network_seglen is used to determine the real size of the -* individual segments, including Layer3 (IP, IPv6) and L4 headers (TCP/UDP). -* -* The MAC/L2 header is not accounted for. -*/ -static inline unsigned int skb_gso_network_seglen (const struct sk_buff *skb) -{ -unsigned int hdr_len =skb_transport_header (skb) - -skb_network_header (skb); -return hdr_len +skb_gso_transport_seglen (skb); -} - -/** -* skb_gso_mac_seglen - Return length of individual segments of a gso packet -* -* @skb: GSO skb -* -* skb_gso_mac_seglen is used to determine the real size of the -* individual segments, including MAC/L2, Layer3 (IP, IPv6) and L4 -* headers (TCP/UDP). -*/ -static inline unsigned int skb_gso_mac_seglen (const struct sk_buff *skb) -{ -unsigned int hdr_len =skb_transport_header (skb) -skb_mac_header (skb); -return hdr_len +skb_gso_transport_seglen (skb); -} -/* Local Checksum Offload. * Compute outer checksum based on the assumption that the * inner checksum will be offloaded later.
net/core/skbuff.c +35 -2
@@ -4891,7 +4891,7 @@ EXPORT_SYMBOL_GPL(skb_scrub_packet);* * The MAC/L2 or network (IP, IPv6) headers are not accounted for. */ -unsigned int skb_gso_transport_seglen (const struct sk_buff *skb) +static unsigned int skb_gso_transport_seglen (const struct sk_buff *skb) {const struct skb_shared_info *shinfo =skb_shinfo (skb);unsigned int thlen =0 ;
@@ -4913,7 +4913,40 @@ unsigned int skb_gso_transport_seglen(const struct sk_buff *skb)*/ return thlen + shinfo->gso_size; } -EXPORT_SYMBOL_GPL (skb_gso_transport_seglen); + +/** +* skb_gso_network_seglen - Return length of individual segments of a gso packet +* +* @skb: GSO skb +* +* skb_gso_network_seglen is used to determine the real size of the +* individual segments, including Layer3 (IP, IPv6) and L4 headers (TCP/UDP). +* +* The MAC/L2 header is not accounted for. +*/ +static unsigned int skb_gso_network_seglen (const struct sk_buff *skb) +{ +unsigned int hdr_len =skb_transport_header (skb) - +skb_network_header (skb); + +return hdr_len +skb_gso_transport_seglen (skb); +} + +/** +* skb_gso_mac_seglen - Return length of individual segments of a gso packet +* +* @skb: GSO skb +* +* skb_gso_mac_seglen is used to determine the real size of the +* individual segments, including MAC/L2, Layer3 (IP, IPv6) and L4 +* headers (TCP/UDP). +*/ +static unsigned int skb_gso_mac_seglen (const struct sk_buff *skb) +{ +unsigned int hdr_len =skb_transport_header (skb) -skb_mac_header (skb); + +return hdr_len +skb_gso_transport_seglen (skb); +}/** * skb_gso_size_check - check the skb size, considering GSO_BY_FRAGS
Signature · 1 line
2.14.1
Quoted 35 lines
From: Daniel Axtens <[email protected]>
Date: Wed, Feb 28, 2018 at 10:13 PMAs requested [1], I went through and had a look at users of
gso_sizeto see if there were things that need to be fixed to considerGSO_BY_FRAGS, and I have tried to improve our helper functions to deal with this case.I found a few. This fixes bugs relating to the use of skb_gso_*_seglen() where
GSO_BY_FRAGSis not considered.Patch 1 renames
skb_gso_validate_mtutoskb_gso_validate_network_len. This is follow-up to my earlier patch2b16f048729b("net: createskb_gso_validate_mac_len()"), and just makes everything a bit clearer.Patches 2 and 3 replace the final users of
skb_gso_network_seglen()- which doesn't considerGSO_BY_FRAGS- withskb_gso_validate_network_len(), which does. This allows me to make the skb_gso_*_seglen functions private in patch 4 - now future users won't accidentally do the wrong comparison.Two things remain. One is
qdisc_pkt_len_init, which is discussed at
[2] - it's caught up in theGSO_DODGYmess. I don't have any expertise inGSO_DODGY, and it looks like a good clean fix will involve unpicking the whole validation mess, so I have left it for now.Secondly, there are 3 eBPF opcodes that change the
gso_sizeof an SKB and don't considerGSO_BY_FRAGS. This is going through the bpf tree.Regards,
Daniel[1] https://patchwork.ozlabs.org/comment/1852414/
[2] https://www.spinics.net/lists/netdev/msg482397.html
Quoted 7 lines
PS: This is all in the core networking stack. For a driver to be affected by this it would need to support
NETIF_F_GSO_SCTP/NETIF_F_GSO_SOFTWAREand then either usegso_sizeor not be a purely virtual device. (Many drivers look atgso_size, but do not support SCTP segmentation, so the core network will segment an SCTP gso before it hits them.) Based on that, the only driver that may be affected is sunvnet, but I have no way of testing it, so I haven't looked at it.
I took a quick peek into sunvnet to check on this, and it looks like the code in sunvnet_common.c::vnet_handle_offloads() is already mis-handling SCTP gso packets, so I don't think you're adding any more breakage.
I suspect we should change sunvnet's use of NETIF_F_GSO_SOFTWARE to NETIF_F_ALL_TSO...
sln
Quoted 29 lines
v2: split out bpf stuff
fix review comments from Dave MillerDaniel Axtens (4):
net: renameskb_gso_validate_mtu->skb_gso_validate_network_len
net: sched: tbf: handleGSO_BY_FRAGScase in enqueue
net: xfrm: useskb_gso_validate_network_len()to check gso sizes
net: make skb_gso_*_seglen functions privateinclude/linux/skbuff.h | 35 +----------------------- net/core/skbuff.c | 48 ++++++++++++++++++++++++++++----- net/ipv4/ip_forward.c | 2 +- net/ipv4/ip_output.c | 2 +- net/ipv4/netfilter/nf_flow_table_ipv4.c | 2 +- net/ipv4/xfrm4_output.c | 3 ++- net/ipv6/ip6_output.c | 2 +- net/ipv6/netfilter/nf_flow_table_ipv6.c | 2 +- net/ipv6/xfrm6_output.c | 2 +- net/mpls/af_mpls.c | 2 +- net/sched/sch_tbf.c | 3 ++- net/xfrm/xfrm_device.c | 2 +- 12 files changed, 54 insertions(+), 51 deletions(-)--
2.14.1
Re: [PATCH v2 2/4] net: sched: tbf: handle GSO_BY_FRAGS case in enqueue
In reply to Daniel AxtensQuoted 9 lines · Daniel Axtens
tbf_enqueue()checks the size of a packet before enqueuing it. However, the GSO size check does not consider theGSO_BY_FRAGScase, and so will drop GSO SCTP packets, causing a massive drop in throughput.Use
skb_gso_validate_mac_len()instead, as it does consider that case.Signed-off-by Daniel Axtens <[email protected]>
Quoted 21 lines
--- net/sched/sch_tbf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)net/sched/sch_tbf.c +2
-1@@ -188,7 +188,8 @@ static int tbf_enqueue(struct sk_buff *skb, struct Qdisc *sch,int ret;if (qdisc_pkt_len (skb) > q->max_size) { -if (skb_is_gso (skb) &&skb_gso_mac_seglen (skb) <= q->max_size) +if (skb_is_gso (skb) && +skb_gso_validate_mac_len (skb, q->max_size))return tbf_segment (skb, sch, to_free);return qdisc_drop (skb, sch, to_free); }Signature · 1 line
2.14.1
Re: [PATCH v2 1/4] net: rename skb_gso_validate_mtu -> skb_gso_validate_network_len
In reply to Daniel AxtensQuoted 10 lines · Daniel Axtens
If you take a GSO skb, and split it into packets, will the network length (L3 headers + L4 headers + payload) of those packets be small enough to fit within a given MTU?
skb_gso_validate_mtugives you the answer to that question. However, we recently added to add a way to validate the MAC length of a split GSO skb (L2+L3+L4+payload), and the names get confusing, so renameskb_gso_validate_mtutoskb_gso_validate_network_lenSigned-off-by Daniel Axtens <[email protected]>
Quoted 149 lines
--- include/linux/skbuff.h | 2 +- net/core/skbuff.c | 11 ++++++----- net/ipv4/ip_forward.c | 2 +- net/ipv4/ip_output.c | 2 +- net/ipv4/netfilter/nf_flow_table_ipv4.c | 2 +- net/ipv6/ip6_output.c | 2 +- net/ipv6/netfilter/nf_flow_table_ipv6.c | 2 +- net/mpls/af_mpls.c | 2 +- net/xfrm/xfrm_device.c | 2 +- 9 files changed, 14 insertions(+), 13 deletions(-)include/linux/skbuff.h +1
-1@@ -3286,7 +3286,7 @@ void skb_split(struct sk_buff *skb, struct sk_buff *skb1, const u32 len);int skb_shift (struct sk_buff *tgt,struct sk_buff *skb,int shiftlen);void skb_scrub_packet (struct sk_buff *skb,bool xnet);unsigned int skb_gso_transport_seglen (const struct sk_buff *skb); -bool skb_gso_validate_mtu (const struct sk_buff *skb,unsigned int mtu); +bool skb_gso_validate_network_len (const struct sk_buff *skb,unsigned int mtu);bool skb_gso_validate_mac_len (const struct sk_buff *skb,unsigned int len);struct sk_buff *skb_segment (struct sk_buff *skb,netdev_features_t features);struct sk_buff *skb_vlan_untag (struct sk_buff *skb);net/core/skbuff.c +6
-5@@ -4955,19 +4955,20 @@ static inline bool skb_gso_size_check(const struct sk_buff *skb, }/** -* skb_gso_validate_mtu - Return in case such skb fits a given MTU +* skb_gso_validate_network_len - Will a split GSO skb fit into a given MTU? * * @skb: GSO skb * @mtu: MTU to validate against * -* skb_gso_validate_mtu validates if a given skb will fit a wanted MTU -* once split. +* skb_gso_validate_network_len validates if a given skb will fit a +* wanted MTU once split. It considers L3 headers, L4 headers, and the +* payload. */ -bool skb_gso_validate_mtu (const struct sk_buff *skb,unsigned int mtu) +bool skb_gso_validate_network_len (const struct sk_buff *skb,unsigned int mtu) {return skb_gso_size_check (skb,skb_gso_network_seglen (skb), mtu); } -EXPORT_SYMBOL_GPL (skb_gso_validate_mtu); +EXPORT_SYMBOL_GPL (skb_gso_validate_network_len);/** * skb_gso_validate_mac_len - Will a split GSO skb fit in a given length? net/ipv4/ip_forward.c +1
-1@@ -55,7 +55,7 @@ static bool ip_exceeds_mtu(const struct sk_buff *skb, unsigned int mtu)if (skb->ignore_df)return false; -if (skb_is_gso (skb) &&skb_gso_validate_mtu (skb, mtu)) +if (skb_is_gso (skb) &&skb_gso_validate_network_len (skb, mtu))return false;return true;net/ipv4/ip_output.c +1
-1@@ -248,7 +248,7 @@ static int ip_finish_output_gso(struct net *net, struct sock *sk,/* common case: seglen is <= mtu */ -if (skb_gso_validate_mtu (skb, mtu)) +if (skb_gso_validate_network_len (skb, mtu))return ip_finish_output2 (net, sk, skb);/* Slowpath - GSO segment length exceeds the egress MTU. net/ipv4/netfilter/nf_flow_table_ipv4.c +1
-1@@ -185,7 +185,7 @@ static bool __nf_flow_exceeds_mtu(const struct sk_buff *skb, unsigned int mtu)if ((ip_hdr (skb)->frag_off &htons (IP_DF )) ==0 )return false; -if (skb_is_gso (skb) &&skb_gso_validate_mtu (skb, mtu)) +if (skb_is_gso (skb) &&skb_gso_validate_network_len (skb, mtu))return false;return true;net/ipv6/ip6_output.c +1
-1@@ -412,7 +412,7 @@ static bool ip6_pkt_too_big(const struct sk_buff *skb, unsigned int mtu)if (skb->ignore_df)return false; -if (skb_is_gso (skb) &&skb_gso_validate_mtu (skb, mtu)) +if (skb_is_gso (skb) &&skb_gso_validate_network_len (skb, mtu))return false;return true;net/ipv6/netfilter/nf_flow_table_ipv6.c +1
-1@@ -178,7 +178,7 @@ static bool __nf_flow_exceeds_mtu(const struct sk_buff *skb, unsigned int mtu)if (skb->len <= mtu)return false; -if (skb_is_gso (skb) &&skb_gso_validate_mtu (skb, mtu)) +if (skb_is_gso (skb) &&skb_gso_validate_network_len (skb, mtu))return false;return true;net/mpls/af_mpls.c +1
-1@@ -122,7 +122,7 @@ bool mpls_pkt_too_big(const struct sk_buff *skb, unsigned int mtu)if (skb->len <= mtu)return false; -if (skb_is_gso (skb) &&skb_gso_validate_mtu (skb, mtu)) +if (skb_is_gso (skb) &&skb_gso_validate_network_len (skb, mtu))return false;return true;net/xfrm/xfrm_device.c +1
-1@@ -217,7 +217,7 @@ bool xfrm_dev_offload_ok(struct sk_buff *skb, struct xfrm_state *x)if (skb->len <= mtu) goto ok; -if (skb_is_gso (skb) &&skb_gso_validate_mtu (skb, mtu)) +if (skb_is_gso (skb) &&skb_gso_validate_network_len (skb, mtu)) goto ok; }Signature · 1 line
2.14.1
Re: [PATCH v2 3/4] net: xfrm: use skb_gso_validate_network_len() to check gso sizes
In reply to Daniel AxtensQuoted 5 lines · Daniel Axtens
Replace
skb_gso_network_seglen()withskb_gso_validate_network_len(), as it considers theGSO_BY_FRAGScase.Signed-off-by Daniel Axtens <[email protected]>
Quoted 35 lines
--- net/ipv4/xfrm4_output.c | 3 ++- net/ipv6/xfrm6_output.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)net/ipv4/xfrm4_output.c +2
-1@@ -30,7 +30,8 @@ static int xfrm4_tunnel_check_size(struct sk_buff *skb) mtu =dst_mtu (skb_dst (skb));if ((!skb_is_gso (skb) && skb->len > mtu) || - (skb_is_gso (skb) &&skb_gso_network_seglen (skb) >ip_skb_dst_mtu (skb->sk, skb))) { + (skb_is_gso (skb) && + !skb_gso_validate_network_len (skb,ip_skb_dst_mtu (skb->sk, skb)))) { skb->protocol =htons (ETH_P_IP );if (skb->sk)net/ipv6/xfrm6_output.c +1
-1@@ -82,7 +82,7 @@ static int xfrm6_tunnel_check_size(struct sk_buff *skb)if ((!skb_is_gso (skb) && skb->len > mtu) || (skb_is_gso (skb) && -skb_gso_network_seglen (skb) >ip6_skb_dst_mtu (skb))) { + !skb_gso_validate_network_len (skb,ip6_skb_dst_mtu (skb)))) { skb->dev = dst->dev; skb->protocol =htons (ETH_P_IPV6 );Signature · 1 line
2.14.1
Re: [PATCH v2 4/4] net: make skb_gso_*_seglen functions private
In reply to Daniel AxtensQuoted 8 lines · Daniel Axtens
They're very hard to use properly as they do not consider the
GSO_BY_FRAGScase. Code should useskb_gso_validate_network_lenandskb_gso_validate_mac_lenas they do consider this case.Make the seglen functions static, which stops people using them outside of
skbuff.cSigned-off-by Daniel Axtens <[email protected]>
Quoted 118 lines
---
v2: drop inline from functions.
--- include/linux/skbuff.h | 33 --------------------------------- net/core/skbuff.c | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 35 deletions(-)include/linux/skbuff.h +0
-33@@ -3285,7 +3285,6 @@ int skb_zerocopy(struct sk_buff *to, struct sk_buff *from,void skb_split (struct sk_buff *skb,struct sk_buff *skb1,const u32 len);int skb_shift (struct sk_buff *tgt,struct sk_buff *skb,int shiftlen);void skb_scrub_packet (struct sk_buff *skb,bool xnet); -unsigned int skb_gso_transport_seglen (const struct sk_buff *skb);bool skb_gso_validate_network_len (const struct sk_buff *skb,unsigned int mtu);bool skb_gso_validate_mac_len (const struct sk_buff *skb,unsigned int len);struct sk_buff *skb_segment (struct sk_buff *skb,netdev_features_t features);@@ -4104,38 +4103,6 @@ static inline bool skb_head_is_locked(const struct sk_buff *skb)return !skb->head_frag ||skb_cloned (skb); } -/** -* skb_gso_network_seglen - Return length of individual segments of a gso packet -* -* @skb: GSO skb -* -* skb_gso_network_seglen is used to determine the real size of the -* individual segments, including Layer3 (IP, IPv6) and L4 headers (TCP/UDP). -* -* The MAC/L2 header is not accounted for. -*/ -static inline unsigned int skb_gso_network_seglen (const struct sk_buff *skb) -{ -unsigned int hdr_len =skb_transport_header (skb) - -skb_network_header (skb); -return hdr_len +skb_gso_transport_seglen (skb); -} - -/** -* skb_gso_mac_seglen - Return length of individual segments of a gso packet -* -* @skb: GSO skb -* -* skb_gso_mac_seglen is used to determine the real size of the -* individual segments, including MAC/L2, Layer3 (IP, IPv6) and L4 -* headers (TCP/UDP). -*/ -static inline unsigned int skb_gso_mac_seglen (const struct sk_buff *skb) -{ -unsigned int hdr_len =skb_transport_header (skb) -skb_mac_header (skb); -return hdr_len +skb_gso_transport_seglen (skb); -} -/* Local Checksum Offload. * Compute outer checksum based on the assumption that the * inner checksum will be offloaded later. net/core/skbuff.c +35
-2@@ -4891,7 +4891,7 @@ EXPORT_SYMBOL_GPL(skb_scrub_packet);* * The MAC/L2 or network (IP, IPv6) headers are not accounted for. */ -unsigned int skb_gso_transport_seglen (const struct sk_buff *skb) +static unsigned int skb_gso_transport_seglen (const struct sk_buff *skb) {const struct skb_shared_info *shinfo =skb_shinfo (skb);unsigned int thlen =0 ;@@ -4913,7 +4913,40 @@ unsigned int skb_gso_transport_seglen(const struct sk_buff *skb)*/ return thlen + shinfo->gso_size; } -EXPORT_SYMBOL_GPL (skb_gso_transport_seglen); + +/** +* skb_gso_network_seglen - Return length of individual segments of a gso packet +* +* @skb: GSO skb +* +* skb_gso_network_seglen is used to determine the real size of the +* individual segments, including Layer3 (IP, IPv6) and L4 headers (TCP/UDP). +* +* The MAC/L2 header is not accounted for. +*/ +static unsigned int skb_gso_network_seglen (const struct sk_buff *skb) +{ +unsigned int hdr_len =skb_transport_header (skb) - +skb_network_header (skb); + +return hdr_len +skb_gso_transport_seglen (skb); +} + +/** +* skb_gso_mac_seglen - Return length of individual segments of a gso packet +* +* @skb: GSO skb +* +* skb_gso_mac_seglen is used to determine the real size of the +* individual segments, including MAC/L2, Layer3 (IP, IPv6) and L4 +* headers (TCP/UDP). +*/ +static unsigned int skb_gso_mac_seglen (const struct sk_buff *skb) +{ +unsigned int hdr_len =skb_transport_header (skb) -skb_mac_header (skb); + +return hdr_len +skb_gso_transport_seglen (skb); +}/** * skb_gso_size_check - check the skb size, considering GSO_BY_FRAGS Signature · 1 line
2.14.1
David Miller
maintainerFrom: Daniel Axtens <[email protected]>
Date: Thu, 1 Mar 2018 17:13:36 +1100
Quoted 4 lines
As requested [1], I went through and had a look at users of
gso_sizeto see if there were things that need to be fixed to considerGSO_BY_FRAGS, and I have tried to improve our helper functions to deal with this case.
...
Series applied, thanks Daniel.