Skip to contentSkip to conversation

tcp_ipv6_check_established

PATCH Mark Huth 3 participants 3 messages May 11, 2004 – May 20, 2004

Subsystems (3)
lore
Share & tools
lore

Mark Huth

author
#0 lore raw

There appears to be a long-standing bug in tcp_ipv6_check_established that results in the return of EADDRNOTAVAILABLE from connect(). It can be demonstrated in the following scenario:

The following scenario fails in most known ipv6 linuxes

All within a single node.

Host has two IPv6 addresses:
dead:dead:dead:dead::1/128
dead:dead:dead:dead::2/128

Application A creates two listening sockets:
dead:dead:dead:dead::1 49997
dead:dead:dead:dead::2 49997

Application B creates a TCP-connection:
from dead:dead:dead:dead::1 49998 to dead:dead:dead:dead::2 49997

Application C creates a TCP-connection:
from dead:dead:dead:dead::2 49998 to dead:dead:dead:dead::1 49997

However, the latter operation fails, and connect() returns EADDRNOTAVAILABLE. Meaning that the host already has such a connection and
the new one cannot be created. Clearly there is no identical connection
used (different ports), thus connect() misbehaves.

All sockets use SO_REUSEADDR-option, and all sockets bind() their source address and source ports before the attempted connect().

While the above may be somewhat contrived, the code is wrong by inspection. The check for the established connections interates on sk2, while the macro argument for TCP_IPV6_MATCH is sk. Thus the check result is invarient over the loop.

A proposed patch for 2.6.6 is attached. A similar patch is required for 2.4 kernels, and is also attached.

Mark Huth

net/ipv6/tcp_ipv6.c +1 -1
diff -ur linux-2.6.6/net/ipv6/tcp_ipv6.c linux-2.6.6-patch/net/ipv6/tcp_ipv6.c
@@ -479,7 +479,7 @@
 
 	/* And established part... */
 	sk_for_each(sk2, node, &head->chain) {
-		if(TCP_IPV6_MATCH(sk, saddr, daddr, ports, dif))
+		if(TCP_IPV6_MATCH(sk2, saddr, daddr, ports, dif))
 			goto not_unique;
 	}
 
net/ipv6/tcp_ipv6.c +1 -1
diff -ur --exclude CVS linux/net/ipv6/tcp_ipv6.c linux_patch/net/ipv6/tcp_ipv6.c
@@ -454,7 +454,7 @@
 	tw = NULL;
 
 	for(skp = &head->chain; (sk2=*skp)!=NULL; skp = &sk2->next) {
-		if(TCP_IPV6_MATCH(sk, saddr, daddr, ports, dif))
+		if(TCP_IPV6_MATCH(sk2, saddr, daddr, ports, dif))
 			goto not_unique;
 	}
 
#2 lore raw
Quoted 1 line · On Tue, 18 May 2004 16:22:13 +0900 (JST) YOSHIFUJI Hideaki / $B5HF#1QL@(B…

Correct. David, please apply.

Done. Thanks everyone.