Skip to content

Commit 844d487

Browse files
strssndktnklassert
authored andcommitted
xfrm: choose protocol family by skb protocol
We need to choose the protocol family by skb->protocol. Otherwise we call the wrong xfrm{4,6}_local_error handler in case an ipv6 sockets is used in ipv4 mode, in which case we should call down to xfrm4_local_error (ip6 sockets are a superset of ip4 ones). We are called before before ip_output functions, so skb->protocol is not reset. Cc: Steffen Klassert <[email protected]> Acked-by: Eric Dumazet <[email protected]> Signed-off-by: Hannes Frederic Sowa <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent 5d0ff54 commit 844d487

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

include/net/xfrm.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,9 +1728,9 @@ static inline int xfrm_skb_dst_mtu(struct sk_buff *skb)
17281728
{
17291729
struct sock *sk = skb->sk;
17301730

1731-
if (sk && sk->sk_family == AF_INET6)
1731+
if (sk && skb->protocol == htons(ETH_P_IPV6))
17321732
return ip6_skb_dst_mtu(skb);
1733-
else if (sk && sk->sk_family == AF_INET)
1733+
else if (sk && skb->protocol == htons(ETH_P_IP))
17341734
return ip_skb_dst_mtu(skb);
17351735
return dst_mtu(skb_dst(skb));
17361736
}

net/xfrm/xfrm_output.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,17 @@ int xfrm_inner_extract_output(struct xfrm_state *x, struct sk_buff *skb)
216216

217217
void xfrm_local_error(struct sk_buff *skb, int mtu)
218218
{
219+
unsigned int proto;
219220
struct xfrm_state_afinfo *afinfo;
220221

221-
afinfo = xfrm_state_get_afinfo(skb->sk->sk_family);
222+
if (skb->protocol == htons(ETH_P_IP))
223+
proto = AF_INET;
224+
else if (skb->protocol == htons(ETH_P_IPV6))
225+
proto = AF_INET6;
226+
else
227+
return;
228+
229+
afinfo = xfrm_state_get_afinfo(proto);
222230
if (!afinfo)
223231
return;
224232

0 commit comments

Comments
 (0)