pull request (net): ipsec 2018-03-29
Subsystems (4)
Steffen Klassert
maintainer1) Fix a rcu_read_lock/rcu_read_unlock imbalance
in the error path of xfrm_local_error().
From Taehee Yoo.
2) Some VTI MTU fixes. From Stefano Brivio.
3) Fix a too early overwritten skb control buffer
on xfrm transport mode.
Please not that this pull request has a merge conflict in net/ipv4/ip_tunnel.c.
The conflict is between
commit f6cc9c054e77 ("ip_tunnel: Emit events for post-register MTU changes")
from the net tree and
commit 24fc79798b8d ("ip_tunnel: Clamp MTU to bounds on new link")
from the ipsec tree.
It can be solved as it is currently done in linux-next.
Please pull or let me know if there are problems.
Thanks!
The following changes since commit 51d4740f88affd85d49c04e3c9cd129c0e33bcb9:
net sched actions: return explicit error when tunnel_key mode is not specified (2018-03-15 14:43:41 -0400)
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 9a3fb9fb84cc30577c1b012a6a3efda944684291:
xfrm: Fix transport mode skb control buffer usage. (2018-03-23 07:56:04 +0100)
----------------------------------------------------------------
Stefano Brivio (6):
vti4: Don't count header length twice on tunnel setup
ip_tunnel: Clamp MTU to bounds on new link
vti4: Don't override MTU passed on link creation via IFLA_MTU
vti6: Properly adjust vti6 MTU from MTU of lower device
vti6: Keep set MTU on link creation or change, validate it
vti6: Fix dev->max_mtu setting
Steffen Klassert (1):
xfrm: Fix transport mode skb control buffer usage.
Taehee Yoo (1):
xfrm: fix rcu_read_unlock usage in xfrm_local_error
net/ipv4/ip_tunnel.c | 8 +++++++- net/ipv4/ip_vti.c | 2 -- net/ipv6/ip6_vti.c | 36 +++++++++++++++++++++++------------- net/xfrm/xfrm_input.c | 6 ++++++ net/xfrm/xfrm_output.c | 5 +++-- 5 files changed, 39 insertions(+), 18 deletions(-)
Steffen Klassert
maintainerPATCH 1/8 xfrm: fix rcu_read_unlock usage in xfrm_local_error
From: Taehee Yoo <[email protected]>
In the xfrm_local_error, rcu_read_unlock should be called when afinfo is not NULL. because xfrm_state_get_afinfo calls rcu_read_unlock if afinfo is NULL.
--- net/xfrm/xfrm_output.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
net/xfrm/xfrm_output.c +3 -2
@@ -285,8 +285,9 @@ void xfrm_local_error(struct sk_buff *skb, int mtu)return ; afinfo =xfrm_state_get_afinfo (proto); -if (afinfo) +if (afinfo) { afinfo->local_error (skb, mtu); -rcu_read_unlock (); +rcu_read_unlock (); + } }EXPORT_SYMBOL_GPL (xfrm_local_error);
Signature · 1 line
2.14.1
Steffen Klassert
maintainerPATCH 2/8 vti4: Don't count header length twice on tunnel setup
In reply to Steffen KlassertFrom: Stefano Brivio <[email protected]>
This re-introduces the effect of commit a32452366b72 ("vti4:
Don't count header length twice.") which was accidentally reverted by merge commit f895f0cfbb77 ("Merge branch 'master' ofgit://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec").
The commit message from Steffen Klassert said:
We currently count the size of LL_MAX_HEADER and struct iphdr twice for vti4 devices, this leads to a wrong device mtu. The size of LL_MAX_HEADER and struct iphdr is already counted in ip_tunnel_bind_dev(), so don't do it again in vti_tunnel_init().
And this is still the case now: ip_tunnel_bind_dev() already accounts for the header length of the link layer (not necessarily LL_MAX_HEADER, if the output device is found), plus one IP header.
For example, with a vti device on top of veth, with MTU of 1500, the existing implementation would set the initial vti MTU to 1332, accounting once for LL_MAX_HEADER (128, included in hard_header_len by vti) and twice for the same IP header (once from hard_header_len, once from ip_tunnel_bind_dev()).
It should instead be 1480, because ip_tunnel_bind_dev() is able to figure out that the output device is veth, so no additional link layer header is attached, and will properly count one single IP header.
The existing issue had the side effect of avoiding PMTUD for most xfrm policies, by arbitrarily lowering the initial MTU. However, the only way to get a consistent PMTU value is to let the xfrm PMTU discovery do its course, and commit d6af1a31cc72 ("vti: Add pmtu handling to vti_xmit.") now takes care of local delivery cases where the application ignores local socket notifications.
--- net/ipv4/ip_vti.c | 1 - 1 file changed, 1 deletion(-)
net/ipv4/ip_vti.c +0 -1
@@ -387,7 +387,6 @@ static int vti_tunnel_init(struct net_device *dev)memcpy (dev->dev_addr, &iph->saddr,4 );memcpy (dev->broadcast, &iph->daddr,4 ); - dev->hard_header_len =LL_MAX_HEADER +sizeof (struct iphdr ); dev->mtu =ETH_DATA_LEN ; dev->flags =IFF_NOARP ; dev->addr_len =4 ;
Signature · 1 line
2.14.1
Steffen Klassert
maintainerPATCH 3/8 ip_tunnel: Clamp MTU to bounds on new link
In reply to Steffen KlassertFrom: Stefano Brivio <[email protected]>
Otherwise, it's possible to specify invalid MTU values directly on creation of a link (via 'ip link add'). This is already prevented on subsequent MTU changes by commit b96f9afee4eb ("ipv4/6: use core net MTU range checking").
--- net/ipv4/ip_tunnel.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
net/ipv4/ip_tunnel.c +7 -1
@@ -1108,8 +1108,14 @@ int ip_tunnel_newlink(struct net_device *dev, struct nlattr *tb[],eth_hw_addr_random (dev); mtu =ip_tunnel_bind_dev (dev); -if (!tb[IFLA_MTU ]) +if (tb[IFLA_MTU ]) { +unsigned int max =0xfff8 - dev->hard_header_len - nt->hlen; + + dev->mtu =clamp (dev->mtu, (unsigned int )ETH_MIN_MTU , + (unsigned int )(max -sizeof (struct iphdr ))); + }else { dev->mtu = mtu; + }ip_tunnel_add (itn, nt); out:
Signature · 1 line
2.14.1
Steffen Klassert
maintainerPATCH 4/8 vti4: Don't override MTU passed on link creation via IFLA_MTU
In reply to Steffen KlassertFrom: Stefano Brivio <[email protected]>
Don't hardcode a MTU value on vti tunnel initialization, ip_tunnel_newlink() is able to deal with this already. See also commit ffc2b6ee4174 ("ip_gre: fix IFLA_MTU ignored on NEWLINK").
--- net/ipv4/ip_vti.c | 1 - 1 file changed, 1 deletion(-)
net/ipv4/ip_vti.c +0 -1
@@ -387,7 +387,6 @@ static int vti_tunnel_init(struct net_device *dev)memcpy (dev->dev_addr, &iph->saddr,4 );memcpy (dev->broadcast, &iph->daddr,4 ); - dev->mtu =ETH_DATA_LEN ; dev->flags =IFF_NOARP ; dev->addr_len =4 ; dev->features |=NETIF_F_LLTX ;
Signature · 1 line
2.14.1
Steffen Klassert
maintainerPATCH 5/8 vti6: Properly adjust vti6 MTU from MTU of lower device
In reply to Steffen KlassertFrom: Stefano Brivio <[email protected]>
If a lower device is found, we don't need to subtract LL_MAX_HEADER to calculate our MTU: just use its MTU, the link layer headers are already taken into account by it.
If the lower device is not found, start from ETH_DATA_LEN instead, and only in this case subtract a worst-case LL_MAX_HEADER.
We then need to subtract our additional IPv6 header from the calculation.
While at it, note that vti6 doesn't have a hardware header, so it doesn't need to set dev->hard_header_len. And as vti6_link_config() now always sets the MTU, there's no need to set a default value in vti6_dev_setup().
This makes the behaviour consistent with IPv4 vti, after commit a32452366b72 ("vti4: Don't count header length twice."), which was accidentally reverted by merge commit f895f0cfbb77 ("Merge branch 'master' ofgit://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec").
While commit 53c81e95df17 ("ip6_vti: adjust vti mtu according to mtu of lower device") improved on the original situation, this was still not ideal. As reported in that commit message itself, if we start from an underlying veth MTU of 9000, we end up with an MTU of 8832, that is, 9000 - LL_MAX_HEADER - sizeof(ipv6hdr). This should simply be 8880, or 9000 - sizeof(ipv6hdr) instead:
we found the lower device (veth) and we know we don't have any additional link layer header, so there's no need to subtract an hypothetical worst-case number.
--- net/ipv6/ip6_vti.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
net/ipv6/ip6_vti.c +6 -4
@@ -627,6 +627,7 @@ static void vti6_link_config(struct ip6_tnl *t)struct net_device *dev = t->dev;struct __ip6_tnl_parm *p = &t->parms;struct net_device *tdev =NULL ; +int mtu;memcpy (dev->dev_addr, &p->laddr,sizeof (struct in6_addr ));memcpy (dev->broadcast, &p->raddr,sizeof (struct in6_addr ));
@@ -656,8 +657,11 @@ static void vti6_link_config(struct ip6_tnl *t) tdev =__dev_get_by_index (t->net, p->link);if (tdev) - dev->mtu =max_t (int, tdev->mtu - dev->hard_header_len, -IPV6_MIN_MTU ); + mtu = tdev->mtu -sizeof (struct ipv6hdr ); +else + mtu =ETH_DATA_LEN -LL_MAX_HEADER -sizeof (struct ipv6hdr ); + + dev->mtu =max_t (int, mtu,IPV6_MIN_MTU ); }/**
@@ -866,8 +870,6 @@ static void vti6_dev_setup(struct net_device *dev) dev->priv_destructor = vti6_dev_free; dev->type =ARPHRD_TUNNEL6 ; - dev->hard_header_len =LL_MAX_HEADER +sizeof (struct ipv6hdr ); - dev->mtu =ETH_DATA_LEN ; dev->min_mtu =IPV6_MIN_MTU ; dev->max_mtu =IP_MAX_MTU ; dev->flags |=IFF_NOARP ;
Signature · 1 line
2.14.1
Steffen Klassert
maintainerPATCH 6/8 vti6: Keep set MTU on link creation or change, validate it
In reply to Steffen KlassertFrom: Stefano Brivio <[email protected]>
In vti6_link_config(), if MTU is already given on link creation or change, validate and use it instead of recomputing it. To do that, we need to propagate the knowledge that MTU was set by userspace all the way down to vti6_link_config().
To keep this simple, vti6_dev_init() sets the new 'keep_mtu' argument of vti6_link_config() to true: on initialization, we don't have convenient access to netlink attributes there, but we will anyway check whether dev->mtu is set in vti6_link_config(). If it's non-zero, it was set to the value of the IFLA_MTU attribute during creation. Otherwise, determine a reasonable value.
--- net/ipv6/ip6_vti.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)
net/ipv6/ip6_vti.c +16 -8
@@ -622,7 +622,7 @@ static int vti6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,return 0 ; } -static void vti6_link_config (struct ip6_tnl *t) +static void vti6_link_config (struct ip6_tnl *t,bool keep_mtu) {struct net_device *dev = t->dev;struct __ip6_tnl_parm *p = &t->parms;
@@ -641,6 +641,11 @@ static void vti6_link_config(struct ip6_tnl *t)else dev->flags &= ~IFF_POINTOPOINT ; +if (keep_mtu && dev->mtu) { + dev->mtu =clamp (dev->mtu, dev->min_mtu, dev->max_mtu); +return ; + } +if (p->flags &IP6_TNL_F_CAP_XMIT ) {int strict = (ipv6_addr_type (&p->raddr) & (IPV6_ADDR_MULTICAST |IPV6_ADDR_LINKLOCAL ));
@@ -668,12 +673,14 @@ static void vti6_link_config(struct ip6_tnl *t)* vti6_tnl_change - update the tunnel parameters * @t: tunnel to be changed * @p: tunnel configuration parameters +* @keep_mtu: MTU was set from userspace, don't re-compute it * * Description: * vti6_tnl_change() updates the tunnel parameters **/ static int -vti6_tnl_change (struct ip6_tnl *t,const struct __ip6_tnl_parm *p) +vti6_tnl_change (struct ip6_tnl *t,const struct __ip6_tnl_parm *p, +bool keep_mtu) { t->parms.laddr = p->laddr; t->parms.raddr = p->raddr;
@@ -683,11 +690,12 @@ vti6_tnl_change(struct ip6_tnl *t, const struct __ip6_tnl_parm *p) t->parms.proto = p->proto; t->parms.fwmark = p->fwmark;dst_cache_reset (&t->dst_cache); -vti6_link_config (t); +vti6_link_config (t, keep_mtu);return 0 ; } -static int vti6_update (struct ip6_tnl *t,struct __ip6_tnl_parm *p) +static int vti6_update (struct ip6_tnl *t,struct __ip6_tnl_parm *p, +bool keep_mtu) {struct net *net =dev_net (t->dev);struct vti6_net *ip6n =net_generic (net, vti6_net_id);
@@ -695,7 +703,7 @@ static int vti6_update(struct ip6_tnl *t, struct __ip6_tnl_parm *p)vti6_tnl_unlink (ip6n, t);synchronize_net (); - err =vti6_tnl_change (t, p); + err =vti6_tnl_change (t, p, keep_mtu);vti6_tnl_link (ip6n, t);netdev_state_change (t->dev);return err;
@@ -808,7 +816,7 @@ vti6_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) }else t =netdev_priv (dev); - err =vti6_update (t, &p1); + err =vti6_update (t, &p1, false); }if (t) { err =0 ;
@@ -907,7 +915,7 @@ static int vti6_dev_init(struct net_device *dev)if (err)return err; -vti6_link_config (t); +vti6_link_config (t, true);return 0 ; }
@@ -1012,7 +1020,7 @@ static int vti6_changelink(struct net_device *dev, struct nlattr *tb[], }else t =netdev_priv (dev); -return vti6_update (t, &p); +return vti6_update (t, &p, tb && tb[IFLA_MTU ]); }static size_t vti6_get_size (const struct net_device *dev)
Signature · 1 line
2.14.1
Steffen Klassert
maintainerPATCH 7/8 vti6: Fix dev->max_mtu setting
In reply to Steffen KlassertFrom: Stefano Brivio <[email protected]>
We shouldn't allow a tunnel to have IP_MAX_MTU as MTU, because another IPv6 header is going on top of our packets. Without this patch, we might end up building packets bigger than IP_MAX_MTU.
--- net/ipv6/ip6_vti.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/ip6_vti.c +1 -1
@@ -879,7 +879,7 @@ static void vti6_dev_setup(struct net_device *dev) dev->type =ARPHRD_TUNNEL6 ; dev->min_mtu =IPV6_MIN_MTU ; - dev->max_mtu =IP_MAX_MTU ; + dev->max_mtu =IP_MAX_MTU -sizeof (struct ipv6hdr ); dev->flags |=IFF_NOARP ; dev->addr_len =sizeof (struct in6_addr );netif_keep_dst (dev);
Signature · 1 line
2.14.1
Steffen Klassert
maintainerPATCH 8/8 xfrm: Fix transport mode skb control buffer usage.
In reply to Steffen KlassertA recent commit introduced a new struct xfrm_trans_cb that is used with the sk_buff control buffer. Unfortunately it placed the structure in front of the control buffer and overlooked that the IPv4/IPv6 control buffer is still needed for some layer 4 protocols. As a result the IPv4/IPv6 control buffer is overwritten with this structure. Fix this by setting a apropriate header in front of the structure.
Fixes acf568ee859f ("xfrm: Reinject transport-mode packets ...")
--- net/xfrm/xfrm_input.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/xfrm/xfrm_input.c +6 -0
@@ -26,6 +26,12 @@ struct xfrm_trans_tasklet { };struct xfrm_trans_cb { +union { +struct inet_skb_parm h4; +#if IS_ENABLED (CONFIG_IPV6 ) +struct inet6_skb_parm h6; +#endif + } header;int (*finish)(struct net *net,struct sock *sk,struct sk_buff *skb); };
Signature · 1 line
2.14.1
David Miller
maintainerFrom: Steffen Klassert <[email protected]>
Date: Thu, 29 Mar 2018 09:11:12 +0200
Quoted 11 lines
1) Fix a rcu_read_lock/rcu_read_unlock imbalance
in the error path ofxfrm_local_error().
From Taehee Yoo.2) Some VTI MTU fixes. From Stefano Brivio.
3) Fix a too early overwritten skb control buffer
on xfrm transport mode.Please not that this pull request has a merge conflict in
net/ipv4/ip_tunnel.c.
...
Pulled, and thanks for the conflict info.