Check size of packets before sending
Subsystems (6)
v2 cover Check size of packets before sending
There are a few ways we can send packets that are too large to a network driver.
When non-GSO packets are forwarded, we validate their size, based on the MTU of the destination device. However, when GSO packets are forwarded, we do not validate their size. We implicitly assume that when they are segmented, the resultant packets will be correctly sized.
This is not always the case.
We observed a case where a packet received on an ibmveth device had a GSO size of around 10kB. This was forwarded by Open vSwitch to a bnx2x device, where it caused a firmware assert. This is described in detail at [0] and was the genesis of this series.
Rather than fixing this in the driver, this series fixes the core path. It does it in 2 steps:
1) make is_skb_forwardable check GSO packets - this catches bridges
2) make validate_xmit_skb check the size of all packets, so as to catch everything else (e.g. macvlan, tc mired, OVS)
I am a bit nervous about how this series will interact with nested VLANs, as the existing code only allows for one VLAN_HLEN. (Previously these packets would sail past unchecked.) But I thought it would be prudent to get more eyes on this sooner rather than later.
Thanks,
Daniel
v1: https://www.spinics.net/lists/netdev/msg478634.html
Changes in v2:
- improve names, thanks Marcelo Ricardo Leitner
- add check to xmit_validate_skb; thanks to everyone who participated in the discussion.
- drop extra check in Open vSwitch. Bad packets will be caught by validate_xmit_skb for now and we can come back and add it later if OVS people would like the extra logging.
[0]: https://patchwork.ozlabs.org/patch/859410/
Daniel Axtens (4):
net: rename skb_gso_validate_mtu -> skb_gso_validate_network_len
net: move skb_gso_mac_seglen to skbuff.h
net: is_skb_forwardable: check the size of GSO segments
net: check the size of a packet in validate_xmit_skb
include/linux/skbuff.h | 18 ++++++++- net/core/dev.c | 24 ++++++++---- net/core/skbuff.c | 66 ++++++++++++++++++++++++++------- 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/sched/sch_tbf.c | 10 ----- net/xfrm/xfrm_device.c | 2 +- 11 files changed, 93 insertions(+), 39 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're about 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 | 9 +++++---- 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, 13 insertions(+), 12 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);struct sk_buff *skb_segment (struct sk_buff *skb,netdev_features_t features);struct sk_buff *skb_vlan_untag (struct sk_buff *skb);int skb_ensure_writable (struct sk_buff *skb,int write_len);
net/core/skbuff.c +5 -4
@@ -4914,15 +4914,16 @@ unsigned int skb_gso_transport_seglen(const struct sk_buff *skb)EXPORT_SYMBOL_GPL (skb_gso_transport_seglen);/** -* 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) {const struct skb_shared_info *shinfo =skb_shinfo (skb);const struct sk_buff *iter;
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
@@ -179,7 +179,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
@@ -121,7 +121,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
@@ -209,7 +209,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: move skb_gso_mac_seglen to skbuff.h
In reply to Daniel AxtensWe're about to use this elsewhere, so move it into the header with the other related functions like skb_gso_network_seglen().
--- include/linux/skbuff.h | 15 +++++++++++++++ net/sched/sch_tbf.c | 10 ---------- 2 files changed, 15 insertions(+), 10 deletions(-)
include/linux/skbuff.h +15 -0
@@ -4120,6 +4120,21 @@ static inline unsigned int skb_gso_network_seglen(const struct sk_buff *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/sched/sch_tbf.c +0 -10
@@ -142,16 +142,6 @@ static u64 psched_ns_t2l(const struct psched_ratecfg *r,return len; } -/* -* Return length of individual segments of a gso packet, -* including all headers (MAC, IP, 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); -} -/* GSO packet is too big, segment it so that tbf can transmit * each segment in time */
Signature · 1 line
2.14.1
PATCH v2 3/4 net: is_skb_forwardable: check the size of GSO segments
In reply to Daniel Axtensis_skb_forwardable attempts to detect if a packet is too large to be sent to the destination device. However, this test does not consider GSO skbs, and it is possible that a GSO skb, when segmented, will be larger than the device can transmit.
Create skb_gso_validate_mac_len, and use that to check.
--- include/linux/skbuff.h | 1 + net/core/dev.c | 7 +++--- net/core/skbuff.c | 67 +++++++++++++++++++++++++++++++++++++++----------- 3 files changed, 57 insertions(+), 18 deletions(-)
include/linux/skbuff.h +1 -0
@@ -3287,6 +3287,7 @@ 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);struct sk_buff *skb_vlan_untag (struct sk_buff *skb);int skb_ensure_writable (struct sk_buff *skb,int write_len);
net/core/dev.c +4 -3
@@ -1841,11 +1841,12 @@ bool is_skb_forwardable(const struct net_device *dev, const struct sk_buff *skb)if (skb->len <= len)return true; -/* if TSO is enabled, we don't care about the length as the packet -* could be forwarded without being segmented before +/* +* if TSO is enabled, we need to check the size of the +* segmented packets */ if (skb_is_gso (skb)) -return true; +return skb_gso_validate_mac_len (skb, len);return false; }
net/core/skbuff.c +52 -15
89 lines not on this page · raw message
Signature · 1 line
2.14.1
PATCH v2 4/4 net: check the size of a packet in validate_xmit_skb
In reply to Daniel AxtensThere are a number of paths where an oversize skb could be sent to a driver. The driver should not be required to check for this - the core layer should do it instead.
Add a check to validate_xmit_skb that checks both GSO and non-GSO packets and drops them if they are too large.
--- net/core/dev.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
net/core/dev.c +13 -4
@@ -1830,13 +1830,11 @@ static inline void net_timestamp_set(struct sk_buff *skb)__net_timestamp (SKB ); \ } \ -bool is_skb_forwardable (const struct net_device *dev,const struct sk_buff *skb) +static inline bool skb_mac_len_fits_dev (const struct net_device *dev, +const struct sk_buff *skb) {unsigned int len; -if (!(dev->flags &IFF_UP )) -return false; - len = dev->mtu + dev->hard_header_len +VLAN_HLEN ;if (skb->len <= len)return true;
@@ -1850,6 +1848,14 @@ bool is_skb_forwardable(const struct net_device *dev, const struct sk_buff *skb)return false; } + +bool is_skb_forwardable (const struct net_device *dev,const struct sk_buff *skb) +{ +if (!(dev->flags &IFF_UP )) +return false; + +return skb_mac_len_fits_dev (dev, skb); +}EXPORT_SYMBOL_GPL (is_skb_forwardable);int __dev_forward_skb (struct net_device *dev,struct sk_buff *skb)
@@ -3081,6 +3087,9 @@ static struct sk_buff *validate_xmit_skb(struct sk_buff *skb, struct net_deviceif (unlikely (!skb)) goto out_null; +if (unlikely (!skb_mac_len_fits_dev (dev, skb))) + goto out_kfree_skb; +if (netif_needs_gso (skb, features)) {struct sk_buff *segs;
Signature · 1 line
2.14.1
Quoted 58 lines · Daniel Axtens
There are a few ways we can send packets that are too large to a network driver.
When non-GSO packets are forwarded, we validate their size, based on the MTU of the destination device. However, when GSO packets are forwarded, we do not validate their size. We implicitly assume that when they are segmented, the resultant packets will be correctly sized.
This is not always the case.
We observed a case where a packet received on an ibmveth device had a GSO size of around 10kB. This was forwarded by Open vSwitch to a bnx2x device, where it caused a firmware assert. This is described in detail at [0] and was the genesis of this series.
Rather than fixing this in the driver, this series fixes the core path. It does it in 2 steps:
1) make
is_skb_forwardablecheck GSO packets - this catches bridges2) make
validate_xmit_skbcheck the size of all packets, so as to catch everything else (e.g. macvlan, tc mired, OVS)I am a bit nervous about how this series will interact with nested VLANs, as the existing code only allows for one
VLAN_HLEN. (Previously these packets would sail past unchecked.) But I thought it would be prudent to get more eyes on this sooner rather than later.Thanks,
Danielv1: https://www.spinics.net/lists/netdev/msg478634.html
Changes in v2:- improve names, thanks Marcelo Ricardo Leitner
- add check to
xmit_validate_skb; thanks to everyone who participated in the discussion.- drop extra check in Open vSwitch. Bad packets will be caught by
validate_xmit_skbfor now and we can come back and add it later if OVS people would like the extra logging.[0]: https://patchwork.ozlabs.org/patch/859410/
Cc Jason Wang <[email protected]>Cc Pravin Shelar <[email protected]>Cc Marcelo Ricardo Leitner <[email protected]>Daniel Axtens (4):
net: renameskb_gso_validate_mtu->skb_gso_validate_network_len
net: moveskb_gso_mac_seglentoskbuff.h
net:is_skb_forwardable: check the size of GSO segments
net: check the size of a packet invalidate_xmit_skb
Quoted 13 lines
include/linux/skbuff.h | 18 ++++++++- net/core/dev.c | 24 ++++++++---- net/core/skbuff.c | 66 ++++++++++++++++++++++++++------- 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/sched/sch_tbf.c | 10 ----- net/xfrm/xfrm_device.c | 2 +- 11 files changed, 93 insertions(+), 39 deletions(-)
May I ask which tree are you targeting ?
( Documentation/networking/netdev-FAQ.txt )
Anything touching GSO is very risky and should target net-next, especially considering 4.15 is released this week end.
Are we really willing to backport this intrusive series in stable trees, or do we have a smaller fix for bnx2x ?
Thanks.
Hi Eric,
Quoted 3 lines
May I ask which tree are you targeting ?
(
Documentation/networking/netdev-FAQ.txt)
I have been targeting net-next, but I haven't pulled for about two weeks. I will rebase and if there are conflicts I will resend early next week.
Quoted 5 lines
Anything touching GSO is very risky and should target net-next, especially considering 4.15 is released this week end.
Are we really willing to backport this intrusive series in stable trees, or do we have a smaller fix for bnx2x ?
I do actually have a smaller fix for bnx2x, although it would need more work:
https://patchwork.ozlabs.org/patch/859410/
It leaves open the possibility of too-large packets causing issues on other drivers. DaveM wasn't a fan: https://patchwork.ozlabs.org/patch/859410/#1839429
Regards,
Daniel
Quoted 2 lines
Thanks.
Quoted 13 lines · Daniel Axtens
Hi Eric,
Quoted 3 lines
May I ask which tree are you targeting ?
(
Documentation/networking/netdev-FAQ.txt)I have been targeting net-next, but I haven't pulled for about two weeks. I will rebase and if there are conflicts I will resend early next week.
Quoted 3 lines
Anything touching GSO is very risky and should target net-next, especially considering 4.15 is released this week end.
Quoted 8 lines
Quoted 2 lines
Are we really willing to backport this intrusive series in stable trees, or do we have a smaller fix for bnx2x ?
I do actually have a smaller fix for bnx2x, although it would need more work:
https://patchwork.ozlabs.org/patch/859410/It leaves open the possibility of too-large packets causing issues on other drivers. DaveM wasn't a fan: https://patchwork.ozlabs.org/patch/859410/#1839429
Yes, I know he prefers a generic solution, but I am pragmatic here. Old kernels are very far from current GSO stack in net-next.
Backporting all the dependencies is going to be very boring/risky.
Quoted 8 lines · Daniel Axtens
There are a few ways we can send packets that are too large to a network driver.
When non-GSO packets are forwarded, we validate their size, based on the MTU of the destination device. However, when GSO packets are forwarded, we do not validate their size. We implicitly assume that when they are segmented, the resultant packets will be correctly sized.
...
Patchset LGTM, but I also think it's risky merging this one in by now.
Marcelo
Quoted 20 lines · Eric Dumazet
Quoted 19 lines · Daniel Axtens
Hi Eric,
Quoted 3 lines
May I ask which tree are you targeting ?
(
Documentation/networking/netdev-FAQ.txt)I have been targeting net-next, but I haven't pulled for about two weeks. I will rebase and if there are conflicts I will resend early next week.
Quoted 5 lines
Anything touching GSO is very risky and should target net-next, especially considering 4.15 is released this week end.
Are we really willing to backport this intrusive series in stable trees, or do we have a smaller fix for bnx2x ?
I do actually have a smaller fix for bnx2x, although it would need more work:
https://patchwork.ozlabs.org/patch/859410/
Quoted 7 lines
Quoted 2 lines
It leaves open the possibility of too-large packets causing issues on other drivers. DaveM wasn't a fan: https://patchwork.ozlabs.org/patch/859410/#1839429
Yes, I know he prefers a generic solution, but I am pragmatic here. Old kernels are very far from current GSO stack in net-next.
Backporting all the dependencies is going to be very boring/risky.
OK, so how about:
- first, a series that introduces skb_gso_validate_mac_len and uses it in bnx2x. This should be backportable without difficulty.
- then, a series that wires skb_gso_validate_mac_len into the core - validate_xmit_skb for instance, and reverts the bnx2x fix. This would not need to be backported.
If that's an approach we can agree on, I am ready to send it when net-next opens again.
Regards,
Daniel
David Miller
maintainerFrom: Daniel Axtens <[email protected]>
Date: Mon, 29 Jan 2018 14:20:58 +1100
Quoted 11 lines
OK, so how about:
- first, a series that introduces
skb_gso_validate_mac_lenand uses it in bnx2x. This should be backportable without difficulty.- then, a series that wires
skb_gso_validate_mac_leninto the core -validate_xmit_skbfor instance, and reverts the bnx2x fix. This would not need to be backported.If that's an approach we can agree on, I am ready to send it when net-next opens again.
Please send the bnx2x specific fix now, thank you.