From: Lorenzo Colitti Date: Fri, 4 Nov 2011 00:05:11 +0000 (-0700) Subject: tcp: Don't nuke connections for the wrong protocol X-Git-Tag: firefly_0821_release~7613^2~238 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=adfa7bc8b41318c20ca571afbd924e3a8cedf2bc;p=firefly-linux-kernel-4.4.55.git tcp: Don't nuke connections for the wrong protocol Currently, calling tcp_nuke_addr to reset IPv6 connections resets IPv4 connections as well, because all Android framework sockets are dual-stack (i.e., IPv6) sockets, and we don't check the source address to see if the connection was in fact an IPv4 connection. Fix this by checking the source address and not resetting the connection if it's a mapped address. Also slightly tweak the IPv4 code path, which doesn't check for mapped addresses either. This was not causing any problems because tcp_is_local normally always returns true for LOOPBACK4_IPV6 (127.0.0.6), because the loopback interface is configured as as 127.0.0.0/8. However, checking explicitly for LOOPBACK4_IPV6 makes the code a bit more robust. Bug: 5535055 Change-Id: I4d6ed3497c5b8643c864783cf681f088cf6b8d2a Signed-off-by: Lorenzo Colitti --- diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 5eb7af23461e..09ced58e6a51 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -273,6 +273,8 @@ #include #include #include +#include +#include #include #include @@ -3374,8 +3376,16 @@ restart: sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[bucket].chain) { struct inet_sock *inet = inet_sk(sk); + if (sysctl_ip_dynaddr && sk->sk_state == TCP_SYN_SENT) + continue; + if (sock_flag(sk, SOCK_DEAD)) + continue; + if (family == AF_INET) { __be32 s4 = inet->inet_rcv_saddr; + if (s4 == LOOPBACK4_IPV6) + continue; + if (in->s_addr != s4 && !(in->s_addr == INADDR_ANY && !tcp_is_local(net, s4))) @@ -3387,7 +3397,11 @@ restart: struct in6_addr *s6; if (!inet->pinet6) continue; + s6 = &inet->pinet6->rcv_saddr; + if (ipv6_addr_type(s6) == IPV6_ADDR_MAPPED) + continue; + if (!ipv6_addr_equal(in6, s6) && !(ipv6_addr_equal(in6, &in6addr_any) && !tcp_is_local6(net, s6))) @@ -3395,11 +3409,6 @@ restart: } #endif - if (sysctl_ip_dynaddr && sk->sk_state == TCP_SYN_SENT) - continue; - if (sock_flag(sk, SOCK_DEAD)) - continue; - sock_hold(sk); spin_unlock_bh(lock);