Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: Find dst with sk's xfrm policy not ctl_sk

If we set XFRM security policy by calling setsockopt with option
IPV6_XFRM_POLICY, the policy will be stored in 'sock_policy' in 'sock'
struct. However tcp_v6_send_response doesn't look up dst_entry with the
actual socket but looks up with tcp control socket. This may cause a
problem that a RST packet is sent without ESP encryption & peer's TCP
socket can't receive it.
This patch will make the function look up dest_entry with actual socket,
if the socket has XFRM policy(sock_policy), so that the TCP response
packet via this function can be encrypted, & aligned on the encrypted
TCP socket.

Tested: We encountered this problem when a TCP socket which is encrypted
in ESP transport mode encryption, receives challenge ACK at SYN_SENT
state. After receiving challenge ACK, TCP needs to send RST to
establish the socket at next SYN try. But the RST was not encrypted &
peer TCP socket still remains on ESTABLISHED state.
So we verified this with test step as below.
[Test step]
1. Making a TCP state mismatch between client(IDLE) & server(ESTABLISHED).
2. Client tries a new connection on the same TCP ports(src & dst).
3. Server will return challenge ACK instead of SYN,ACK.
4. Client will send RST to server to clear the SOCKET.
5. Client will retransmit SYN to server on the same TCP ports.
[Expected result]
The TCP connection should be established.

Cc: Maciej Żenczykowski <maze@google.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Steffen Klassert <steffen.klassert@secunet.com>
Cc: Sehee Lee <seheele@google.com>
Signed-off-by: Sewook Seo <sewookseo@google.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

sewookseo and committed by
David S. Miller
e22aa148 0076cad3

+9 -2
+2
include/net/xfrm.h
··· 1195 1195 1196 1196 static inline int xfrm_sk_clone_policy(struct sock *sk, const struct sock *osk) 1197 1197 { 1198 + if (!sk_fullsock(osk)) 1199 + return 0; 1198 1200 sk->sk_policy[0] = NULL; 1199 1201 sk->sk_policy[1] = NULL; 1200 1202 if (unlikely(osk->sk_policy[0] || osk->sk_policy[1]))
+1 -1
net/ipv4/ip_output.c
··· 1700 1700 tcp_hdr(skb)->source, tcp_hdr(skb)->dest, 1701 1701 arg->uid); 1702 1702 security_skb_classify_flow(skb, flowi4_to_flowi_common(&fl4)); 1703 - rt = ip_route_output_key(net, &fl4); 1703 + rt = ip_route_output_flow(net, &fl4, sk); 1704 1704 if (IS_ERR(rt)) 1705 1705 return; 1706 1706
+2
net/ipv4/tcp_ipv4.c
··· 819 819 ctl_sk->sk_priority = (sk->sk_state == TCP_TIME_WAIT) ? 820 820 inet_twsk(sk)->tw_priority : sk->sk_priority; 821 821 transmit_time = tcp_transmit_time(sk); 822 + xfrm_sk_clone_policy(ctl_sk, sk); 822 823 } 823 824 ip_send_unicast_reply(ctl_sk, 824 825 skb, &TCP_SKB_CB(skb)->header.h4.opt, ··· 828 827 transmit_time); 829 828 830 829 ctl_sk->sk_mark = 0; 830 + xfrm_sk_free_policy(ctl_sk); 831 831 sock_net_set(ctl_sk, &init_net); 832 832 __TCP_INC_STATS(net, TCP_MIB_OUTSEGS); 833 833 __TCP_INC_STATS(net, TCP_MIB_OUTRSTS);
+4 -1
net/ipv6/tcp_ipv6.c
··· 952 952 * Underlying function will use this to retrieve the network 953 953 * namespace 954 954 */ 955 - dst = ip6_dst_lookup_flow(sock_net(ctl_sk), ctl_sk, &fl6, NULL); 955 + if (sk && sk->sk_state != TCP_TIME_WAIT) 956 + dst = ip6_dst_lookup_flow(net, sk, &fl6, NULL); /*sk's xfrm_policy can be referred*/ 957 + else 958 + dst = ip6_dst_lookup_flow(net, ctl_sk, &fl6, NULL); 956 959 if (!IS_ERR(dst)) { 957 960 skb_dst_set(buff, dst); 958 961 ip6_xmit(ctl_sk, buff, &fl6, fl6.flowi6_mark, NULL,