pull request (net): ipsec 2017-11-01
Subsystems (3)
Steffen Klassert
maintainerPATCH 1/3 xfrm: Fix xfrm_dst_cache memleak
In reply to Steffen KlassertWe have a memleak whenever a flow matches a policy without a matching SA. In this case we generate a dummy bundle and take an additional refcount on the dst_entry. This was needed as long as we had the flowcache. The flowcache removal patches deleted all related refcounts but forgot the one for the dummy bundle case. Fix the memleak by removing this refcount.
--- net/xfrm/xfrm_policy.c | 1 - 1 file changed, 1 deletion(-)
net/xfrm/xfrm_policy.c +0 -1
@@ -2076,7 +2076,6 @@ xfrm_bundle_lookup(struct net *net, const struct flowi *fl, u16 family, u8 dir, xdst->num_xfrms = num_xfrms;memcpy (xdst->pols, pols,sizeof (struct xfrm_policy *) * num_pols); -dst_hold (&xdst->u.dst);return xdst; inc_error:
Signature · 1 line
2.7.4
Steffen Klassert
maintainerPATCH 2/3 xfrm: Clear sk_dst_cache when applying per-socket policy.
In reply to Steffen KlassertFrom: Jonathan Basseri <[email protected]>
If a socket has a valid dst cache, then xfrm_lookup_route will get skipped. However, the cache is not invalidated when applying policy to a socket (i.e. IPV6_XFRM_POLICY). The result is that new policies are sometimes ignored on those sockets. (Note: This was broken for IPv4 and IPv6 at different times.)
This can be demonstrated like so,
1. Create UDP socket.
2. connect() the socket.
3. Apply an outbound XFRM policy to the socket. (setsockopt)
4. send() data on the socket.
Packets will continue to be sent in the clear instead of matching an xfrm or returning a no-match error (EAGAIN). This affects calls to send() and not sendto().
Invalidating the sk_dst_cache is necessary to correctly apply xfrm policies. Since we do this in xfrm_user_policy(), the sk_lock was already acquired in either do_ip_setsockopt() or do_ipv6_setsockopt(), and we may call __sk_dst_reset().
Performance impact should be negligible, since this code is only called when changing xfrm policy, and only affects the socket in question.
Tested: https://android-review.googlesource.com/517555
Tested: https://android-review.googlesource.com/418659
--- net/xfrm/xfrm_state.c | 1 + 1 file changed, 1 insertion(+)
net/xfrm/xfrm_state.c +1 -0
@@ -2069,6 +2069,7 @@ int xfrm_user_policy(struct sock *sk, int optname, u8 __user *optval, int optlenif (err >=0 ) {xfrm_sk_policy_insert (sk, err, pol);xfrm_pol_put (pol); +__sk_dst_reset (sk); err =0 ; }
Signature · 1 line
2.7.4
Steffen Klassert
maintainerPATCH 3/3 xfrm: Fix GSO for IPsec with GRE tunnel.
In reply to Steffen KlassertWe reset the encapsulation field of the skb too early in xfrm_output. As a result, the GRE GSO handler does not segment the packets. This leads to a performance drop down. We fix this by resetting the encapsulation field right before we do the transformation, when the inner headers become invalid.
--- net/xfrm/xfrm_output.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/xfrm/xfrm_output.c +3 -1
@@ -105,6 +105,9 @@ static int xfrm_output_one(struct sk_buff *skb, int err)if (xfrm_offload (skb)) { x->type_offload->encap (x, skb); }else { +/* Inner headers are invalid now. */ + skb->encapsulation =0 ; + err = x->type->output (x, skb);if (err == -EINPROGRESS ) goto out;
@@ -208,7 +211,6 @@ int xfrm_output(struct sock *sk, struct sk_buff *skb)int err;secpath_reset (skb); - skb->encapsulation =0 ;if (xfrm_dev_offload_ok (skb, x)) {struct sec_path *sp;
Signature · 1 line
2.7.4
Steffen Klassert
maintainer1) Fix a memleak when a packet matches a policy
without a matching state.
2) Reset the socket cached dst_entry when inserting a socket policy, otherwise the policy might be ignored. From Jonathan Basseri.
3) Fix GSO for a IPsec, GRE tunnel combination.
We reset the encapsulation field at the skb
too erly, as a result GRE does not segment
GSO packets. Fix this by resetting the the
encapsulation field right before the
transformation where the inner headers get
invalid.
Please pull or let me know if there are problems.
Thanks!
The following changes since commit 864f5af3a3525f588391cd230cb8129ad758708e:
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec (2017-10-24 20:17:47 +0900)
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 73b9fc49b4c0116a04eda3979f64ed9b540b153c:
xfrm: Fix GSO for IPsec with GRE tunnel. (2017-10-31 09:20:35 +0100)
----------------------------------------------------------------
Jonathan Basseri (1):
xfrm: Clear sk_dst_cache when applying per-socket policy.
Steffen Klassert (2):
xfrm: Fix xfrm_dst_cache memleak
xfrm: Fix GSO for IPsec with GRE tunnel.
net/xfrm/xfrm_output.c | 4 +++- net/xfrm/xfrm_policy.c | 1 - net/xfrm/xfrm_state.c | 1 + 3 files changed, 4 insertions(+), 2 deletions(-)
David Miller
maintainerFrom: Steffen Klassert <[email protected]>
Date: Wed, 1 Nov 2017 11:05:00 +0100
Quoted 15 lines
1) Fix a memleak when a packet matches a policy
without a matching state.2) Reset the socket cached
dst_entrywhen inserting a socket policy, otherwise the policy might be ignored. From Jonathan Basseri.3) Fix GSO for a IPsec, GRE tunnel combination.
We reset the encapsulation field at the skb
too erly, as a result GRE does not segment
GSO packets. Fix this by resetting the the
encapsulation field right before the
transformation where the inner headers get
invalid.
Quoted 1 line
Please pull or let me know if there are problems.
Pulled, thanks.