pull request (net): ipsec 2022-03-09
Subsystems (3)
Steffen Klassert
maintainer1) Fix IPv6 PMTU discovery for xfrm interfaces.
From Lina Wang.
2) Revert failing for policies and states that are configured with XFRMA_IF_ID 0. It broke a user configuration. From Kai Lueke.
3) Fix a possible buffer overflow in the ESP output path.
4) Fix ESP GSO for tunnel and BEET mode on inter address family tunnels.
Please pull or let me know if there are problems.
Thanks!
The following changes since commit 519ca6fa960587d02904a9f8f79d587ac874fb03:
Merge branch '40GbE' of git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/net-queue (2022-02-26 12:50:20 +0000)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec.git master
for you to fetch changes up to 23c7f8d7989e1646aac82f75761b7648c355cb8a:
net: Fix esp GSO on inter address family tunnels. (2022-03-07 13:14:04 +0100)
----------------------------------------------------------------
Kai Lueke (1):
Revert "xfrm: state and policy should fail if XFRMA_IF_ID 0"
Lina Wang (1):
xfrm: fix tunnel model fragmentation behavior
Steffen Klassert (3):
esp: Fix possible buffer overflow in ESP transformation
esp: Fix BEET mode inter address family tunneling on GSO
net: Fix esp GSO on inter address family tunnels.
include/linux/netdevice.h | 2 ++ include/net/esp.h | 2 ++ net/core/gro.c | 25 +++++++++++++++++++++++++ net/ipv4/esp4.c | 5 +++++ net/ipv4/esp4_offload.c | 6 ++++-- net/ipv6/esp6.c | 5 +++++ net/ipv6/esp6_offload.c | 6 ++++-- net/ipv6/xfrm6_output.c | 16 ++++++++++++++++ net/xfrm/xfrm_interface.c | 5 ++++- net/xfrm/xfrm_user.c | 21 +++------------------ 10 files changed, 70 insertions(+), 23 deletions(-)
Steffen Klassert
maintainerPATCH 1/5 xfrm: fix tunnel model fragmentation behavior
From: Lina Wang <[email protected]>
in tunnel mode, if outer interface(ipv4) is less, it is easily to let inner IPV6 mtu be less than 1280. If so, a Packet Too Big ICMPV6 message is received. When send again, packets are fragmentized with 1280, they are still rejected with ICMPV6(Packet Too Big) by xfrmi_xmit2().
According to RFC4213 Section3.2.2:
if (IPv4 path MTU - 20) is less than 1280
if packet is larger than 1280 bytes
Send ICMPv6 "packet too big" with MTU=1280 Drop packet
else
Encapsulate but do not set the Don't Fragment flag in the IPv4 header. The resulting IPv4 packet might be fragmented by the IPv4 layer on the encapsulator or by some router along the IPv4 path.
endif
else
if packet is larger than (IPv4 path MTU - 20)
Send ICMPv6 "packet too big" with
MTU = (IPv4 path MTU - 20).
Drop packet.
else
Encapsulate and set the Don't Fragment flag in the IPv4 header.
endif
endif
Packets should be fragmentized with ipv4 outer interface, so change it.
After it is fragemtized with ipv4, there will be double fragmenation. No.48 & No.51 are ipv6 fragment packets, No.48 is double fragmentized, then tunneled with IPv4(No.49& No.50), which obey spec. And received peer cannot decrypt it rightly.
48 2002::10 2002::11 1296(length) IPv6 fragment (off=0 more=y ident=0xa20da5bc nxt=50) 49 0x0000 (0) 2002::10 2002::11 1304 IPv6 fragment (off=0 more=y ident=0x7448042c nxt=44) 50 0x0000 (0) 2002::10 2002::11 200 ESP (SPI=0x00035000) 51 2002::10 2002::11 180 Echo (ping) request 52 0x56dc 2002::10 2002::11 248 IPv6 fragment (off=1232 more=n ident=0xa20da5bc nxt=50)
xfrm6_noneed_fragment has fixed above issues. Finally, it acted like below:
1 0x6206 192.168.1.138 192.168.1.1 1316 Fragmented IP protocol (proto=Encap Security Payload 50, off=0, ID=6206) [Reassembled in #2] 2 0x6206 2002::10 2002::11 88 IPv6 fragment (off=0 more=y ident=0x1f440778 nxt=50) 3 0x0000 2002::10 2002::11 248 ICMPv6 Echo (ping) request
--- net/ipv6/xfrm6_output.c | 16 ++++++++++++++++ net/xfrm/xfrm_interface.c | 5 ++++- 2 files changed, 20 insertions(+), 1 deletion(-)
net/ipv6/xfrm6_output.c +16 -0
@@ -45,6 +45,19 @@ static int __xfrm6_output_finish(struct net *net, struct sock *sk, struct sk_bufreturn xfrm_output (sk, skb); } +static int xfrm6_noneed_fragment (struct sk_buff *skb) +{ +struct frag_hdr *fh; +u8 prevhdr =ipv6_hdr (skb)->nexthdr; + +if (prevhdr !=NEXTHDR_FRAGMENT ) +return 0 ; + fh = (struct frag_hdr *)(skb->data +sizeof (struct ipv6hdr )); +if (fh->nexthdr ==NEXTHDR_ESP || fh->nexthdr ==NEXTHDR_AUTH ) +return 1 ; +return 0 ; +} +static int __xfrm6_output (struct net *net,struct sock *sk,struct sk_buff *skb) {struct dst_entry *dst =skb_dst (skb);
@@ -73,6 +86,9 @@ static int __xfrm6_output(struct net *net, struct sock *sk, struct sk_buff *skb)xfrm6_local_rxpmtu (skb, mtu);kfree_skb (skb);return -EMSGSIZE ; + }else if (toobig &&xfrm6_noneed_fragment (skb)) { + skb->ignore_df =1 ; + goto skip_frag; }else if (!skb->ignore_df && toobig && skb->sk) {xfrm_local_error (skb, mtu);kfree_skb (skb);
net/xfrm/xfrm_interface.c +4 -1
@@ -304,7 +304,10 @@ xfrmi_xmit2(struct sk_buff *skb, struct net_device *dev, struct flowi *fl)if (mtu <IPV6_MIN_MTU ) mtu =IPV6_MIN_MTU ; -icmpv6_ndo_send (skb,ICMPV6_PKT_TOOBIG ,0 , mtu); +if (skb->len >1280 ) +icmpv6_ndo_send (skb,ICMPV6_PKT_TOOBIG ,0 , mtu); +else + goto xmit; }else {if (!(ip_hdr (skb)->frag_off &htons (IP_DF ))) goto xmit;
Signature · 1 line
2.25.1
Re: [PATCH 1/5] xfrm: fix tunnel model fragmentation behavior
This patch was applied to netdev/net.git (master) by Steffen Klassert <[email protected]>:
Hello:
This patch was applied to netdev/net.git (master) by Steffen Klassert <[email protected]>:
Quoted 8 lines · On Wed, 9 Mar 2022 14:08:35 +0100 you wrote:
From: Lina Wang <[email protected]>
in tunnel mode, if outer interface(ipv4) is less, it is easily to let inner IPV6 mtu be less than 1280. If so, a Packet Too Big ICMPV6 message is received. When send again, packets are fragmentized with 1280, they are still rejected with ICMPV6(Packet Too Big) by
xfrmi_xmit2().[...]
Here is the summary with links:
- [1/5] xfrm: fix tunnel model fragmentation behavior
https://git.kernel.org/netdev/net/c/4ff2980b6bd2
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Steffen Klassert
maintainerPATCH 2/5 Revert "xfrm: state and policy should fail if XFRMA_IF_ID 0"
In reply to Steffen KlassertFrom: Kai Lueke <[email protected]>
This reverts commit 68ac0f3810e76a853b5f7b90601a05c3048b8b54 because ID 0 was meant to be used for configuring the policy/state without matching for a specific interface (e.g., Cilium is affected, see
https://github.com/cilium/cilium/pull/18789 and
https://github.com/cilium/cilium/pull/19019).
--- net/xfrm/xfrm_user.c | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-)
net/xfrm/xfrm_user.c +3 -18
@@ -630,13 +630,8 @@ static struct xfrm_state *xfrm_state_construct(struct net *net,xfrm_smark_init (attrs, &x->props.smark); -if (attrs[XFRMA_IF_ID ]) { +if (attrs[XFRMA_IF_ID ]) x->if_id =nla_get_u32 (attrs[XFRMA_IF_ID ]); -if (!x->if_id) { - err = -EINVAL ; - goto error; - } - } err =__xfrm_init_state (x, false, attrs[XFRMA_OFFLOAD_DEV ]);if (err)
@@ -1432,13 +1427,8 @@ static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh, mark =xfrm_mark_get (attrs, &m); -if (attrs[XFRMA_IF_ID ]) { +if (attrs[XFRMA_IF_ID ]) if_id =nla_get_u32 (attrs[XFRMA_IF_ID ]); -if (!if_id) { - err = -EINVAL ; - goto out_noput; - } - }if (p->info.seq) { x =xfrm_find_acq_byseq (net, mark, p->info.seq);
@@ -1751,13 +1741,8 @@ static struct xfrm_policy *xfrm_policy_construct(struct net *net, struct xfrm_usxfrm_mark_get (attrs, &xp->mark); -if (attrs[XFRMA_IF_ID ]) { +if (attrs[XFRMA_IF_ID ]) xp->if_id =nla_get_u32 (attrs[XFRMA_IF_ID ]); -if (!xp->if_id) { - err = -EINVAL ; - goto error; - } - }return xp; error:
Signature · 1 line
2.25.1
Steffen Klassert
maintainerPATCH 3/5 esp: Fix possible buffer overflow in ESP transformation
In reply to Steffen KlassertThe 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 4/5 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 5/5 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
This pull request was applied to netdev/net.git (master) by Steffen Klassert <[email protected]>:
Hello:
This pull request was applied to netdev/net.git (master) by Steffen Klassert <[email protected]>:
Quoted 8 lines · On Wed, 9 Mar 2022 14:08:34 +0100 you wrote:
1) Fix IPv6 PMTU discovery for xfrm interfaces.
From Lina Wang.2) Revert failing for policies and states that are configured with
XFRMA_IF_ID0. It broke a user configuration. From Kai Lueke.[...]
Here is the summary with links:
- pull request (net): ipsec 2022-03-09
https://git.kernel.org/netdev/net/c/cc7e2f596e64 - [2/5] Revert "xfrm: state and policy should fail if XFRMA_IF_ID 0" https://git.kernel.org/netdev/net/c/a3d9001b4e28 - [3/5] esp: Fix possible buffer overflow in ESP transformation https://git.kernel.org/netdev/net/c/ebe48d368e97 - [4/5] esp: Fix BEET mode inter address family tunneling on GSO https://git.kernel.org/netdev/net/c/053c8fdf2c93 - [5/5] net: Fix esp GSO on inter address family tunnels. https://git.kernel.org/netdev/net/c/23c7f8d7989e
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html