Subject: Re: Fw: Nasty Oops in 2.6.0-test6 bind/SO_REUSEADDR

From: Arnaldo Carvalho de Melo <[email-masked]>
Date: Thu, 9 Oct 2003 23:36:44 -0300

Em Wed, Oct 08, 2003 at 01:33:45PM -0700, David S. Miller escreveu:
> Arnaldo, I think this is another piece of fallout
> from the struct sock splitup you did ages ago.
> 
> I think it's dereferencing inet_sk(sk) for a time-wait
> socket, so we probably need a TCP_TIME_WAIT test plus
> some additional logic here?  Better check tcp_ipv6.c too.

Dan, could you please try with this patch?

- Arnaldo

===== net/ipv4/tcp_ipv4.c 1.69 vs edited =====
--- 1.69/net/ipv4/tcp_ipv4.c	Wed Oct  8 12:27:40 2003
+++ edited/net/ipv4/tcp_ipv4.c	Thu Oct  9 23:23:38 2003
@@ -186,7 +186,8 @@
 	int reuse = sk->sk_reuse;
 
 	sk_for_each_bound(sk2, node, &tb->owners) {
-		if (sk != sk2 &&
+		if (likely(sk->sk_state != TCP_TIME_WAIT) &&
+		    sk != sk2 &&
 		    !ipv6_only_sock(sk2) &&
 		    (!sk->sk_bound_dev_if ||
 		     !sk2->sk_bound_dev_if ||
===== net/ipv6/tcp_ipv6.c 1.74 vs edited =====
--- 1.74/net/ipv6/tcp_ipv6.c	Wed Oct  8 12:27:40 2003
+++ edited/net/ipv6/tcp_ipv6.c	Thu Oct  9 23:23:45 2003
@@ -101,7 +101,8 @@
 
 	/* We must walk the whole port owner list in this case. -DaveM */
 	sk_for_each_bound(sk2, node, &tb->owners) {
-		if (sk != sk2 &&
+		if (likely(sk->sk_state != TCP_TIME_WAIT) &&
+		    sk != sk2 &&
 		    (!sk->sk_bound_dev_if ||
 		     !sk2->sk_bound_dev_if ||
 		     sk->sk_bound_dev_if == sk2->sk_bound_dev_if) &&