Skip to content

Commit 1de9425

Browse files
qsngregkh
authored andcommitted
xfrm: xfrm_state_mtu should return at least 1280 for ipv6
[ Upstream commit b515d26 ] 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: 91657ea ("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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 10f32b8 commit 1de9425

4 files changed

Lines changed: 15 additions & 4 deletions

File tree

‎include/net/xfrm.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,6 +1546,7 @@ void xfrm_sad_getinfo(struct net *net, struct xfrmk_sadinfo *si);
15461546
void xfrm_spd_getinfo(struct net *net, struct xfrmk_spdinfo *si);
15471547
u32 xfrm_replay_seqhi(struct xfrm_state *x, __be32 net_seq);
15481548
int xfrm_init_replay(struct xfrm_state *x);
1549+
u32 __xfrm_state_mtu(struct xfrm_state *x, int mtu);
15491550
u32 xfrm_state_mtu(struct xfrm_state *x, int mtu);
15501551
int __xfrm_init_state(struct xfrm_state *x, bool init_replay, bool offload);
15511552
int xfrm_init_state(struct xfrm_state *x);

‎net/ipv4/esp4.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ static int esp_output(struct xfrm_state *x, struct sk_buff *skb)
673673
struct xfrm_dst *dst = (struct xfrm_dst *)skb_dst(skb);
674674
u32 padto;
675675

676-
padto = min(x->tfcpad, xfrm_state_mtu(x, dst->child_mtu_cached));
676+
padto = min(x->tfcpad, __xfrm_state_mtu(x, dst->child_mtu_cached));
677677
if (skb->len < padto)
678678
esp.tfclen = padto - skb->len;
679679
}

‎net/ipv6/esp6.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ static int esp6_output(struct xfrm_state *x, struct sk_buff *skb)
708708
struct xfrm_dst *dst = (struct xfrm_dst *)skb_dst(skb);
709709
u32 padto;
710710

711-
padto = min(x->tfcpad, xfrm_state_mtu(x, dst->child_mtu_cached));
711+
padto = min(x->tfcpad, __xfrm_state_mtu(x, dst->child_mtu_cached));
712712
if (skb->len < padto)
713713
esp.tfclen = padto - skb->len;
714714
}

‎net/xfrm/xfrm_state.c‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2516,7 +2516,7 @@ void xfrm_state_delete_tunnel(struct xfrm_state *x)
25162516
}
25172517
EXPORT_SYMBOL(xfrm_state_delete_tunnel);
25182518

2519-
u32 xfrm_state_mtu(struct xfrm_state *x, int mtu)
2519+
u32 __xfrm_state_mtu(struct xfrm_state *x, int mtu)
25202520
{
25212521
const struct xfrm_type *type = READ_ONCE(x->type);
25222522
struct crypto_aead *aead;
@@ -2547,7 +2547,17 @@ u32 xfrm_state_mtu(struct xfrm_state *x, int mtu)
25472547
return ((mtu - x->props.header_len - crypto_aead_authsize(aead) -
25482548
net_adj) & ~(blksize - 1)) + net_adj - 2;
25492549
}
2550-
EXPORT_SYMBOL_GPL(xfrm_state_mtu);
2550+
EXPORT_SYMBOL_GPL(__xfrm_state_mtu);
2551+
2552+
u32 xfrm_state_mtu(struct xfrm_state *x, int mtu)
2553+
{
2554+
mtu = __xfrm_state_mtu(x, mtu);
2555+
2556+
if (x->props.family == AF_INET6 && mtu < IPV6_MIN_MTU)
2557+
return IPV6_MIN_MTU;
2558+
2559+
return mtu;
2560+
}
25512561

25522562
int __xfrm_init_state(struct xfrm_state *x, bool init_replay, bool offload)
25532563
{

0 commit comments

Comments
 (0)