pull request (net): ipsec 2021-06-23
Subsystems (3)
Steffen Klassert
maintainer1) Don't return a mtu smaller than 1280 on IPv6 pmtu discovery. From Sabrina Dubroca
2) Fix seqcount rcu-read side in xfrm_policy_lookup_bytype for the PREEMPT_RT case. From Varad Gautam.
3) Remove a repeated declaration of xfrm_parse_spi. From Shaokun Zhang.
4) IPv4 beet mode can't handle fragments, but IPv6 does. commit 68dc022d04eb ("xfrm: BEET mode doesn't support fragments for inner packets") handled IPv4 and IPv6 the same way. Relax the check for IPv6 because fragments are possible here. From Xin Long.
5) Memory allocation failures are not reported for XFRMA_ENCAP and XFRMA_COADDR in xfrm_state_construct. Fix this by moving both cases in front of the function.
6) Fix a missing initialization in the xfrm offload fallback fail case for bonding devices. From Ayush Sawal.
Please pull or let me know if there are problems.
Thanks!
The following changes since commit 88a5af943985fb43b4c9472b5abd9c0b9705533d:
Merge tag 'net-5.12-rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net (2021-04-17 09:57:15 -0700)
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 dd72fadf2186fc8a6018f97fe72f4d5ca05df440:
xfrm: Fix xfrm offload fallback fail case (2021-06-22 09:08:15 +0200)
----------------------------------------------------------------
Ayush Sawal (1):
xfrm: Fix xfrm offload fallback fail case
Sabrina Dubroca (1):
xfrm: xfrm_state_mtu should return at least 1280 for ipv6
Shaokun Zhang (1):
xfrm: Remove the repeated declaration
Steffen Klassert (1):
xfrm: Fix error reporting in xfrm_state_construct.
Varad Gautam (1):
xfrm: policy: Read seqcount outside of rcu-read side in xfrm_policy_lookup_bytype
Xin Long (1):
xfrm: remove the fragment check for ipv6 beet mode
include/net/xfrm.h | 2 +- net/ipv4/esp4.c | 2 +- net/ipv6/esp6.c | 2 +- net/xfrm/xfrm_device.c | 1 + net/xfrm/xfrm_output.c | 7 ------- net/xfrm/xfrm_policy.c | 21 ++++++++++++++------- net/xfrm/xfrm_state.c | 14 ++++++++++++-- net/xfrm/xfrm_user.c | 28 ++++++++++++++-------------- 8 files changed, 44 insertions(+), 33 deletions(-)
Steffen Klassert
maintainerPATCH 1/6 xfrm: xfrm_state_mtu should return at least 1280 for ipv6
From: Sabrina Dubroca <[email protected]>
Jianwen reported that IPv6 Interoperability tests are failing in an IPsec case where one of the links between the IPsec peers has an MTU of 1280. The peer generates a packet larger than this MTU, the router replies with a "Packet too big" message indicating an MTU of 1280. When the peer tries to send another large packet, xfrm_state_mtu returns 1280 - ipsec_overhead, which causes ip6_setup_cork to fail with EINVAL.
We can fix this by forcing xfrm_state_mtu to return IPV6_MIN_MTU when IPv6 is used. After going through IPsec, the packet will then be fragmented to obey the actual network's PMTU, just before leaving the host.
Currently, TFC padding is capped to PMTU - overhead to avoid
fragementation: after padding and encapsulation, we still fit within the PMTU. That behavior is preserved in this patch.
--- include/net/xfrm.h | 1 + net/ipv4/esp4.c | 2 +- net/ipv6/esp6.c | 2 +- net/xfrm/xfrm_state.c | 14 ++++++++++++-- 4 files changed, 15 insertions(+), 4 deletions(-)
include/net/xfrm.h +1 -0
@@ -1546,6 +1546,7 @@ void xfrm_sad_getinfo(struct net *net, struct xfrmk_sadinfo *si);void xfrm_spd_getinfo (struct net *net,struct xfrmk_spdinfo *si);u32 xfrm_replay_seqhi (struct xfrm_state *x,__be32 net_seq);int xfrm_init_replay (struct xfrm_state *x); +u32 __xfrm_state_mtu (struct xfrm_state *x,int mtu);u32 xfrm_state_mtu (struct xfrm_state *x,int mtu);int __xfrm_init_state (struct xfrm_state *x,bool init_replay,bool offload);int xfrm_init_state (struct xfrm_state *x);
net/ipv4/esp4.c +1 -1
@@ -673,7 +673,7 @@ static int esp_output(struct xfrm_state *x, struct sk_buff *skb)struct xfrm_dst *dst = (struct xfrm_dst *)skb_dst (skb);u32 padto; - padto =min (x->tfcpad,xfrm_state_mtu (x, dst->child_mtu_cached)); + padto =min (x->tfcpad,__xfrm_state_mtu (x, dst->child_mtu_cached));if (skb->len < padto) esp.tfclen = padto - skb->len; }
net/ipv6/esp6.c +1 -1
@@ -708,7 +708,7 @@ static int esp6_output(struct xfrm_state *x, struct sk_buff *skb)struct xfrm_dst *dst = (struct xfrm_dst *)skb_dst (skb);u32 padto; - padto =min (x->tfcpad,xfrm_state_mtu (x, dst->child_mtu_cached)); + padto =min (x->tfcpad,__xfrm_state_mtu (x, dst->child_mtu_cached));if (skb->len < padto) esp.tfclen = padto - skb->len; }
net/xfrm/xfrm_state.c +12 -2
@@ -2518,7 +2518,7 @@ void xfrm_state_delete_tunnel(struct xfrm_state *x) }EXPORT_SYMBOL (xfrm_state_delete_tunnel); -u32 xfrm_state_mtu (struct xfrm_state *x,int mtu) +u32 __xfrm_state_mtu (struct xfrm_state *x,int mtu) {const struct xfrm_type *type =READ_ONCE (x->type);struct crypto_aead *aead;
@@ -2549,7 +2549,17 @@ u32 xfrm_state_mtu(struct xfrm_state *x, int mtu)return ((mtu - x->props.header_len -crypto_aead_authsize (aead) - net_adj) & ~(blksize -1 )) + net_adj -2 ; } -EXPORT_SYMBOL_GPL (xfrm_state_mtu); +EXPORT_SYMBOL_GPL (__xfrm_state_mtu); + +u32 xfrm_state_mtu (struct xfrm_state *x,int mtu) +{ + mtu =__xfrm_state_mtu (x, mtu); + +if (x->props.family ==AF_INET6 && mtu <IPV6_MIN_MTU ) +return IPV6_MIN_MTU ; + +return mtu; +}int __xfrm_init_state (struct xfrm_state *x,bool init_replay,bool offload) {
Signature · 1 line
2.25.1
Steffen Klassert
maintainerPATCH 2/6 xfrm: policy: Read seqcount outside of rcu-read side in xfrm_policy_lookup_bytype
In reply to Steffen KlassertFrom: Varad Gautam <[email protected]>
xfrm_policy_lookup_bytype loops on seqcount mutex xfrm_policy_hash_generation within an RCU read side critical section. Although ill advised, this is fine if the loop is bounded.
xfrm_policy_hash_generation wraps mutex hash_resize_mutex, which is used to serialize writers (xfrm_hash_resize, xfrm_hash_rebuild). This is fine too.
On PREEMPT_RT=y, the read_seqcount_begin call within xfrm_policy_lookup_bytype emits a mutex lock/unlock for hash_resize_mutex. Mutex locking is fine, since RCU read side critical sections are allowed to sleep with PREEMPT_RT.
xfrm_hash_resize can, however, block on synchronize_rcu while holding hash_resize_mutex.
This leads to the following situation on PREEMPT_RT, where the writer is blocked on RCU grace period expiry, while the reader is blocked on a lock held by the writer:
Thead 1 (xfrm_hash_resize) Thread 2 (xfrm_policy_lookup_bytype)
rcu_read_lock(); mutex_lock(&hash_resize_mutex); read_seqcount_begin(&xfrm_policy_hash_generation); mutex_lock(&hash_resize_mutex); // block
xfrm_bydst_resize();synchronize_rcu(); // block
<RCU stalls in xfrm_policy_lookup_bytype>
Move the read_seqcount_begin call outside of the RCU read side critical section, and do an rcu_read_unlock/retry if we got stale data within the critical section.
On non-PREEMPT_RT, this shortens the time spent within RCU read side critical section in case the seqcount needs a retry, and avoids unbounded looping.
--- net/xfrm/xfrm_policy.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
net/xfrm/xfrm_policy.c +14 -7
@@ -2092,12 +2092,15 @@ static struct xfrm_policy *xfrm_policy_lookup_bytype(struct net *net, u8 type,if (unlikely (!daddr || !saddr))return NULL ; -rcu_read_lock (); retry: -do { - sequence =read_seqcount_begin (&xfrm_policy_hash_generation); - chain =policy_hash_direct (net, daddr, saddr, family, dir); - }while (read_seqcount_retry (&xfrm_policy_hash_generation, sequence)); + sequence =read_seqcount_begin (&xfrm_policy_hash_generation); +rcu_read_lock (); + + chain =policy_hash_direct (net, daddr, saddr, family, dir); +if (read_seqcount_retry (&xfrm_policy_hash_generation, sequence)) { +rcu_read_unlock (); + goto retry; + } ret =NULL ;hlist_for_each_entry_rcu (pol, chain, bydst) {
@@ -2128,11 +2131,15 @@ static struct xfrm_policy *xfrm_policy_lookup_bytype(struct net *net, u8 type, } skip_inexact: -if (read_seqcount_retry (&xfrm_policy_hash_generation, sequence)) +if (read_seqcount_retry (&xfrm_policy_hash_generation, sequence)) { +rcu_read_unlock (); goto retry; + } -if (ret && !xfrm_pol_hold_rcu (ret)) +if (ret && !xfrm_pol_hold_rcu (ret)) { +rcu_read_unlock (); goto retry; + } fail:rcu_read_unlock ();
Signature · 1 line
2.25.1
Steffen Klassert
maintainerPATCH 3/6 xfrm: Remove the repeated declaration
In reply to Steffen KlassertFrom: Shaokun Zhang <[email protected]>
Function 'xfrm_parse_spi' is declared twice, so remove the repeated declaration.
--- include/net/xfrm.h | 1 - 1 file changed, 1 deletion(-)
include/net/xfrm.h +0 -1
@@ -1571,7 +1571,6 @@ int xfrm4_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type);int xfrm4_transport_finish (struct sk_buff *skb,int async);int xfrm4_rcv (struct sk_buff *skb); -int xfrm_parse_spi (struct sk_buff *skb,u8 nexthdr,__be32 *spi,__be32 *seq);static inline int xfrm4_rcv_spi (struct sk_buff *skb,int nexthdr,__be32 spi) {
Signature · 1 line
2.25.1
Steffen Klassert
maintainerPATCH 4/6 xfrm: remove the fragment check for ipv6 beet mode
In reply to Steffen KlassertFrom: Xin Long <[email protected]>
In commit 68dc022d04eb ("xfrm: BEET mode doesn't support fragments for inner packets"), it tried to fix the issue that in TX side the packet is fragmented before the ESP encapping while in the RX side the fragments always get reassembled before decapping with ESP.
This is not true for IPv6. IPv6 is different, and it's using exthdr to save fragment info, as well as the ESP info. Exthdrs are added in TX and processed in RX both in order. So in the above case, the ESP decapping will be done earlier than the fragment reassembling in TX side.
Here just remove the fragment check for the IPv6 inner packets to recover the fragments support for BEET mode.
--- net/xfrm/xfrm_output.c | 7 ------- 1 file changed, 7 deletions(-)
net/xfrm/xfrm_output.c +0 -7
@@ -711,15 +711,8 @@ static int xfrm6_tunnel_check_size(struct sk_buff *skb)static int xfrm6_extract_output (struct xfrm_state *x,struct sk_buff *skb) {#if IS_ENABLED (CONFIG_IPV6 ) -unsigned int ptr =0 ;int err; -if (x->outer_mode.encap ==XFRM_MODE_BEET && -ipv6_find_hdr (skb, &ptr,NEXTHDR_FRAGMENT ,NULL ,NULL ) >=0 ) { -net_warn_ratelimited ("BEET mode doesn't support inner IPv6 fragments\n" ); -return -EAFNOSUPPORT ; - } - err =xfrm6_tunnel_check_size (skb);if (err)return err;
Signature · 1 line
2.25.1
Steffen Klassert
maintainerPATCH 5/6 xfrm: Fix error reporting in xfrm_state_construct.
In reply to Steffen KlassertWhen memory allocation for XFRMA_ENCAP or XFRMA_COADDR fails, the error will not be reported because the -ENOMEM assignment to the err variable is overwritten before. Fix this by moving these two in front of the function so that memory allocation failures will be reported.
--- net/xfrm/xfrm_user.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
net/xfrm/xfrm_user.c +14 -14
@@ -580,6 +580,20 @@ static struct xfrm_state *xfrm_state_construct(struct net *net,copy_from_user_state (x, p); +if (attrs[XFRMA_ENCAP ]) { + x->encap =kmemdup (nla_data (attrs[XFRMA_ENCAP ]), +sizeof (*x->encap),GFP_KERNEL ); +if (x->encap ==NULL ) + goto error; + } + +if (attrs[XFRMA_COADDR ]) { + x->coaddr =kmemdup (nla_data (attrs[XFRMA_COADDR ]), +sizeof (*x->coaddr),GFP_KERNEL ); +if (x->coaddr ==NULL ) + goto error; + } +if (attrs[XFRMA_SA_EXTRA_FLAGS ]) x->props.extra_flags =nla_get_u32 (attrs[XFRMA_SA_EXTRA_FLAGS ]);
@@ -600,23 +614,9 @@ static struct xfrm_state *xfrm_state_construct(struct net *net, attrs[XFRMA_ALG_COMP]))) goto error; -if (attrs[XFRMA_ENCAP ]) { - x->encap =kmemdup (nla_data (attrs[XFRMA_ENCAP ]), -sizeof (*x->encap),GFP_KERNEL ); -if (x->encap ==NULL ) - goto error; - } -if (attrs[XFRMA_TFCPAD ]) x->tfcpad =nla_get_u32 (attrs[XFRMA_TFCPAD ]); -if (attrs[XFRMA_COADDR ]) { - x->coaddr =kmemdup (nla_data (attrs[XFRMA_COADDR ]), -sizeof (*x->coaddr),GFP_KERNEL ); -if (x->coaddr ==NULL ) - goto error; - } -xfrm_mark_get (attrs, &x->mark);xfrm_smark_init (attrs, &x->props.smark);
Signature · 1 line
2.25.1
Steffen Klassert
maintainerPATCH 6/6 xfrm: Fix xfrm offload fallback fail case
In reply to Steffen KlassertFrom: Ayush Sawal <[email protected]>
In case of xfrm offload, if xdo_dev_state_add() of driver returns -EOPNOTSUPP, xfrm offload fallback is failed.
In xfrm state_add() both xso->dev and xso->real_dev are initialized to dev and when err(-EOPNOTSUPP) is returned only xso->dev is set to null.
So in this scenario the condition in func validate_xmit_xfrm(), if ((x->xso.dev != dev) && (x->xso.real_dev == dev))
return skb;
returns true, due to which skb is returned without calling esp_xmit() below which has fallback code. Hence the CRYPTO_FALLBACK is failing.
So fixing this with by keeping x->xso.real_dev as NULL when err is returned in func xfrm_dev_state_add().
--- net/xfrm/xfrm_device.c | 1 + 1 file changed, 1 insertion(+)
net/xfrm/xfrm_device.c +1 -0
@@ -268,6 +268,7 @@ int xfrm_dev_state_add(struct net *net, struct xfrm_state *x, xso->num_exthdrs =0 ; xso->flags =0 ; xso->dev =NULL ; + xso->real_dev =NULL ;dev_put (dev);if (err != -EOPNOTSUPP )
Signature · 1 line
2.25.1
This pull request was applied to netdev/net.git (refs/heads/master):
Hello:
This pull request was applied to netdev/net.git (refs/heads/master):
Quoted 10 lines · On Wed, 23 Jun 2021 08:54:43 +0200 you wrote:
1) Don't return a mtu smaller than 1280 on IPv6 pmtu discovery. From Sabrina Dubroca
2) Fix seqcount rcu-read side in
xfrm_policy_lookup_bytypefor thePREEMPT_RTcase. From Varad Gautam.3) Remove a repeated declaration of
xfrm_parse_spi. From Shaokun Zhang.[...]
Here is the summary with links:
- pull request (net): ipsec 2021-06-23
https://git.kernel.org/netdev/net/c/7c2becf7968b - [2/6] xfrm: policy: Read seqcount outside of rcu-read side in xfrm_policy_lookup_bytype https://git.kernel.org/netdev/net/c/d7b0408934c7 - [3/6] xfrm: Remove the repeated declaration https://git.kernel.org/netdev/net/c/6e1e89418a5c - [4/6] xfrm: remove the fragment check for ipv6 beet mode https://git.kernel.org/netdev/net/c/eebd49a4ffb4 - [5/6] xfrm: Fix error reporting in xfrm_state_construct. https://git.kernel.org/netdev/net/c/6fd06963fa74 - [6/6] xfrm: Fix xfrm offload fallback fail case https://git.kernel.org/netdev/net/c/dd72fadf2186
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html