Fixes for the ipsec tree
Subsystems (3)
Steffen Klassert
maintainercover Fixes for the ipsec tree
I plan to apply the following fixes to the ipsec tree:
1) Fix possible buffer overflow in ESP output transformation.
2) Fix BEET mode for ESP inter address family tunneling on GSO.
3) Fix ESP GSO on inter address family tunnels.
Steffen Klassert
maintainerPATCH 1/3 esp: Fix possible buffer overflow in ESP transformation
The maximum message size that can be send is bigger than the maximum site that skb_page_frag_refill can allocate. So it is possible to write beyond the allocated buffer.
Fix this by doing a fallback to COW in that case.
v2:
Avoid get get_order() costs as suggested by Linus Torvalds.
--- include/net/esp.h | 2 ++ net/ipv4/esp4.c | 5 +++++ net/ipv6/esp6.c | 5 +++++ 3 files changed, 12 insertions(+)
include/net/esp.h +2 -0
@@ -4,6 +4,8 @@#include <linux/skbuff.h> +#define ESP_SKB_FRAG_MAXSIZE (PAGE_SIZE << SKB_FRAG_PAGE_ORDER) +struct ip_esp_hdr ;static inline struct ip_esp_hdr *ip_esp_hdr (const struct sk_buff *skb)
net/ipv4/esp4.c +5 -0
@@ -446,6 +446,7 @@ int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *struct page *page;struct sk_buff *trailer;int tailen = esp->tailen; +unsigned int allocsz;/* this is non-NULL only with TCP/UDP Encapsulation */ if (x->encap) {
@@ -455,6 +456,10 @@ int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *return err; } + allocsz =ALIGN (skb->data_len + tailen,L1_CACHE_BYTES ); +if (allocsz >ESP_SKB_FRAG_MAXSIZE ) + goto cow; +if (!skb_cloned (skb)) {if (tailen <=skb_tailroom (skb)) { nfrags =1 ;
net/ipv6/esp6.c +5 -0
@@ -482,6 +482,7 @@ int esp6_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_infostruct page *page;struct sk_buff *trailer;int tailen = esp->tailen; +unsigned int allocsz;if (x->encap) {int err =esp6_output_encap (x, skb, esp);
@@ -490,6 +491,10 @@ int esp6_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_inforeturn err; } + allocsz =ALIGN (skb->data_len + tailen,L1_CACHE_BYTES ); +if (allocsz >ESP_SKB_FRAG_MAXSIZE ) + goto cow; +if (!skb_cloned (skb)) {if (tailen <=skb_tailroom (skb)) { nfrags =1 ;
Signature · 1 line
2.25.1
Steffen Klassert
maintainerPATCH 2/3 esp: Fix BEET mode inter address family tunneling on GSO
In reply to Steffen KlassertThe xfrm{4,6}_beet_gso_segment() functions did not correctly set the SKB_GSO_IPXIP4 and SKB_GSO_IPXIP6 gso types for the address family tunneling case. Fix this by setting these gso types.
--- net/ipv4/esp4_offload.c | 3 +++ net/ipv6/esp6_offload.c | 3 +++ 2 files changed, 6 insertions(+)
net/ipv4/esp4_offload.c +3 -0
@@ -160,6 +160,9 @@ static struct sk_buff *xfrm4_beet_gso_segment(struct xfrm_state *x,skb_shinfo (skb)->gso_type |=SKB_GSO_TCPV4 ; } +if (proto ==IPPROTO_IPV6 ) +skb_shinfo (skb)->gso_type |=SKB_GSO_IPXIP4 ; +__skb_pull (skb,skb_transport_offset (skb)); ops =rcu_dereference (inet_offloads[proto]);if (likely (ops && ops->callbacks.gso_segment))
net/ipv6/esp6_offload.c +3 -0
@@ -199,6 +199,9 @@ static struct sk_buff *xfrm6_beet_gso_segment(struct xfrm_state *x,ipv6_skip_exthdr (skb,0 , &proto, &frag); } +if (proto ==IPPROTO_IPIP ) +skb_shinfo (skb)->gso_type |=SKB_GSO_IPXIP6 ; +__skb_pull (skb,skb_transport_offset (skb)); ops =rcu_dereference (inet6_offloads[proto]);if (likely (ops && ops->callbacks.gso_segment))
Signature · 1 line
2.25.1
Steffen Klassert
maintainerPATCH 3/3 net: Fix esp GSO on inter address family tunnels.
In reply to Steffen KlassertThe esp tunnel GSO handlers use skb_mac_gso_segment to push the inner packet to the segmentation handlers. However, skb_mac_gso_segment takes the Ethernet Protocol ID from 'skb->protocol' which is wrong for inter address family tunnels. We fix this by introducing a new skb_eth_gso_segment function.
This function can be used if it is necessary to pass the Ethernet Protocol ID directly to the segmentation handler. First users of this function will be the esp4 and esp6 tunnel segmentation handlers.
--- include/linux/netdevice.h | 2 ++ net/core/gro.c | 25 +++++++++++++++++++++++++ net/ipv4/esp4_offload.c | 3 +-- net/ipv6/esp6_offload.c | 3 +-- 4 files changed, 29 insertions(+), 4 deletions(-)
include/linux/netdevice.h +2 -0
@@ -4602,6 +4602,8 @@ int skb_csum_hwoffload_help(struct sk_buff *skb,struct sk_buff *__skb_gso_segment (struct sk_buff *skb,netdev_features_t features,bool tx_path); +struct sk_buff *skb_eth_gso_segment (struct sk_buff *skb, +netdev_features_t features,__be16 type);struct sk_buff *skb_mac_gso_segment (struct sk_buff *skb,netdev_features_t features);
net/core/gro.c +25 -0
@@ -92,6 +92,31 @@ void dev_remove_offload(struct packet_offload *po) }EXPORT_SYMBOL (dev_remove_offload); +/** +* skb_eth_gso_segment - segmentation handler for ethernet protocols. +* @skb: buffer to segment +* @features: features for the output path (see dev->features) +* @type: Ethernet Protocol ID +*/ +struct sk_buff *skb_eth_gso_segment (struct sk_buff *skb, +netdev_features_t features,__be16 type) +{ +struct sk_buff *segs =ERR_PTR (-EPROTONOSUPPORT ); +struct packet_offload *ptype; + +rcu_read_lock (); +list_for_each_entry_rcu (ptype, &offload_base, list) { +if (ptype->type == type && ptype->callbacks.gso_segment) { + segs = ptype->callbacks.gso_segment (skb, features); +break ; + } + } +rcu_read_unlock (); + +return segs; +} +EXPORT_SYMBOL (skb_eth_gso_segment); +/** * skb_mac_gso_segment - mac layer segmentation handler. * @skb: buffer to segment
net/ipv4/esp4_offload.c +1 -2
@@ -110,8 +110,7 @@ static struct sk_buff *xfrm4_tunnel_gso_segment(struct xfrm_state *x,struct sk_buff *skb, netdev_features_t features) { - __skb_push(skb, skb->mac_len); -return skb_mac_gso_segment (skb, features); + return skb_eth_gso_segment(skb, features, htons(ETH_P_IP)); } static struct sk_buff *xfrm4_transport_gso_segment(struct xfrm_state *x,
net/ipv6/esp6_offload.c +1 -2
@@ -145,8 +145,7 @@ static struct sk_buff *xfrm6_tunnel_gso_segment(struct xfrm_state *x,struct sk_buff *skb, netdev_features_t features) { - __skb_push(skb, skb->mac_len); -return skb_mac_gso_segment (skb, features); + return skb_eth_gso_segment(skb, features, htons(ETH_P_IPV6)); } static struct sk_buff *xfrm6_transport_gso_segment(struct xfrm_state *x,
Signature · 1 line
2.25.1
Steffen Klassert
maintainerQuoted 7 lines · Steffen Klassert
I plan to apply the following fixes to the ipsec tree:
1) Fix possible buffer overflow in ESP output transformation.
2) Fix BEET mode for ESP inter address family tunneling on GSO.
3) Fix ESP GSO on inter address family tunnels.
This is now applied to thwe ipsec tree.