Blob Blame History Raw
From: Sabrina Dubroca <sd@queasysnail.net>
Subject: xfrm: xfrm_state_mtu should return at least 1280 for ipv6
Git-commit: b515d2637276a3810d6595e10ab02c13bfd0b63a
Patch-mainline: v5.14
References: bsc#1185377
Acked-by: Jiri Bohac <jbohac@suse.cz>

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.

Fixes: 749439bfac6e ("ipv6: fix udpv6 sendmsg crash caused by too small MTU")
Fixes: 91657eafb64b ("xfrm: take net hdr len into account for esp payload size calculation")
Reported-by: Jianwen Ji <jiji@redhat.com>
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

---
 net/xfrm/xfrm_state.c |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -2161,7 +2161,7 @@ void xfrm_state_delete_tunnel(struct xfr
 }
 EXPORT_SYMBOL(xfrm_state_delete_tunnel);
 
-int xfrm_state_mtu(struct xfrm_state *x, int mtu)
+static int __xfrm_state_mtu(struct xfrm_state *x, int mtu)
 {
 	const struct xfrm_type *type = READ_ONCE(x->type);
 
@@ -2172,6 +2172,16 @@ int xfrm_state_mtu(struct xfrm_state *x,
 	return mtu - x->props.header_len;
 }
 
+int 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)
 {
 	struct xfrm_state_afinfo *afinfo;